linux-rtc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next][V3] rtc: ds1307: check for failed memory allocation on wdt
@ 2020-04-03 11:04 Colin King
  2020-04-03 11:40 ` Alexandre Belloni
  0 siblings, 1 reply; 2+ messages in thread
From: Colin King @ 2020-04-03 11:04 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni, Guenter Roeck,
	Chris Packham, linux-rtc
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Currently a failed memory allocation will lead to a null pointer
dereference on point wdt.  Fix this by checking for a failed
allocation and just returning.

Addresses-Coverity: ("Dereference null return")
Fixes: fd90d48db037 ("rtc: ds1307: add support for watchdog timer on ds1388")

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---

V2: move error exit label and remove a return statement, thanks to 
    Walter Harms for spotting this clean up.
V3: simplify, just bail out and return on detecting the out of memory
    condition

---

 drivers/rtc/rtc-ds1307.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index fad042118862..49702942bb08 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -1673,6 +1673,8 @@ static void ds1307_wdt_register(struct ds1307 *ds1307)
 		return;
 
 	wdt = devm_kzalloc(ds1307->dev, sizeof(*wdt), GFP_KERNEL);
+	if (!wdt)
+		return;
 
 	wdt->info = &ds1388_wdt_info;
 	wdt->ops = &ds1388_wdt_ops;
-- 
2.25.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-04-03 11:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-03 11:04 [PATCH][next][V3] rtc: ds1307: check for failed memory allocation on wdt Colin King
2020-04-03 11:40 ` Alexandre Belloni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).