Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1779272ybb; Thu, 2 Apr 2020 07:14:43 -0700 (PDT) X-Google-Smtp-Source: APiQypJLTa3U21iV7530wmCKBOfwoeilX8pNZ38HJUWavxVOCqTlMOnD4uTU7pdbzDbBYiClT9ZY X-Received: by 2002:a9d:30c7:: with SMTP id r7mr2487798otg.289.1585836883784; Thu, 02 Apr 2020 07:14:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585836883; cv=none; d=google.com; s=arc-20160816; b=AuQ88gFOmuEKE6PFuwnXQ27Njt7ynxuLgy/wuatHxqU5BVPNT8uJAOZtYI6DtWuJPP CgJyRfA4nFn7epchB4rLMgPDu2asora31ZgaPx8qlG6+Sl3HggLDvyPcNjJICbZ8hHPd Rq4emR3bu8z7HHVVY5fPnT516L8swsBz6C415RVyDOGU1DUhT70uVFPhcim+jn6/Wzp3 1V+V5fGgA3A3yvCUeACwhSILnXbbjXC6IiGk+IXXBeFUnKGCNztLD2dQCKXvOR81P+CW poq72KnaQKpWZWGQt0Ulc/Rtzupo9ibiarHOJIIY6jOr6tJb6FE0cbDSwUJMYmT8K36I TFpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=nyXUDDja7A2EweBger7ZAD8AF1/sMU0Tv0KkAoOGIG8=; b=dGLYM4942wOYODob0L6wwDNfpSog2eUnCV8o6O7qgSc+ZlIlvsbrqeAE7uOYrwrgKt biB5yBw+vuED/7KCpy5Emcv/RVVAhA+wjv8da953yn7javfACi1lFtDt9pGbewVXfC2U /0IYaRwJmE0MGMyARn6lym0uWGyZFEnd9TgK9hvRXJ8ryL7azMk4xAd4H9wLk8GaLeoQ ydjryTXbqni3J/TI9uMfcnXS6BtVO94ENmwQOPI9FrA11wZxzaFNCVXo0L4rANMugMBa KR2ZdXAoFxeijybTxIkF7VG44F0kru5kZiuknj5fHZ6N7WiW6Ut3A7OAUUt2+7gVCv8x GAYQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m5si2378384otp.41.2020.04.02.07.14.28; Thu, 02 Apr 2020 07:14:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387543AbgDBNw2 (ORCPT + 99 others); Thu, 2 Apr 2020 09:52:28 -0400 Received: from relay7-d.mail.gandi.net ([217.70.183.200]:38823 "EHLO relay7-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733252AbgDBNw2 (ORCPT ); Thu, 2 Apr 2020 09:52:28 -0400 X-Originating-IP: 86.202.105.35 Received: from localhost (lfbn-lyo-1-9-35.w86-202.abo.wanadoo.fr [86.202.105.35]) (Authenticated sender: alexandre.belloni@bootlin.com) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 25DE720006; Thu, 2 Apr 2020 13:52:24 +0000 (UTC) Date: Thu, 2 Apr 2020 15:52:23 +0200 From: Alexandre Belloni To: Colin King Cc: Alessandro Zummo , Guenter Roeck , Chris Packham , linux-rtc@vger.kernel.org, kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH][next] rtc: ds1307: check for failed memory allocation on wdt Message-ID: <20200402135223.GI3683@piout.net> References: <20200402131441.539088-1-colin.king@canonical.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200402131441.539088-1-colin.king@canonical.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02/04/2020 14:14:41+0100, Colin King wrote: > From: Colin Ian King > > Currently a failed memory allocation will lead to a null pointer > dereference on point wdt. Fix this by checking for a failed allocation > and adding error return handling to function ds1307_wdt_register. > > Addresses-Coverity: ("Dereference null return") > Fixes: fd90d48db037 ("rtc: ds1307: add support for watchdog timer on ds1388") > Signed-off-by: Colin Ian King > --- > drivers/rtc/rtc-ds1307.c | 15 ++++++++++----- > 1 file changed, 10 insertions(+), 5 deletions(-) > > diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c > index fad042118862..95c5b6facc59 100644 > --- a/drivers/rtc/rtc-ds1307.c > +++ b/drivers/rtc/rtc-ds1307.c > @@ -1665,14 +1665,16 @@ static const struct watchdog_ops ds1388_wdt_ops = { > > }; > > -static void ds1307_wdt_register(struct ds1307 *ds1307) > +static int ds1307_wdt_register(struct ds1307 *ds1307) > { > struct watchdog_device *wdt; > > if (ds1307->type != ds_1388) > - return; > + return 0; > > wdt = devm_kzalloc(ds1307->dev, sizeof(*wdt), GFP_KERNEL); > + if (!wdt) > + return -ENOMEM; > > wdt->info = &ds1388_wdt_info; > wdt->ops = &ds1388_wdt_ops; > @@ -1683,10 +1685,13 @@ static void ds1307_wdt_register(struct ds1307 *ds1307) > watchdog_init_timeout(wdt, 0, ds1307->dev); > watchdog_set_drvdata(wdt, ds1307); > devm_watchdog_register_device(ds1307->dev, wdt); > + > + return 0; > } > #else > -static void ds1307_wdt_register(struct ds1307 *ds1307) > +static int ds1307_wdt_register(struct ds1307 *ds1307) > { > + return 0; > } > #endif /* CONFIG_WATCHDOG_CORE */ > > @@ -1979,9 +1984,9 @@ static int ds1307_probe(struct i2c_client *client, > > ds1307_hwmon_register(ds1307); > ds1307_clks_register(ds1307); > - ds1307_wdt_register(ds1307); > + err = ds1307_wdt_register(ds1307); > > - return 0; > + return err; As the watchdog is optional and the RTC can work properly without the watchdog driver being compiled, my opinion is that the error should not be returned. -- Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com