[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20180607073543.GP13775@localhost>
Date: Thu, 7 Jun 2018 09:35:43 +0200
From: Johan Hovold <johan@...nel.org>
To: Andy Shevchenko <andy.shevchenko@...il.com>
Cc: Colin King <colin.king@...onical.com>,
Tony Lindgren <tony@...mide.com>,
Linus Walleij <linus.walleij@...aro.org>,
kernel-janitors@...r.kernel.org,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
"open list:GPIO SUBSYSTEM" <linux-gpio@...r.kernel.org>,
Haojian Zhuang <haojian.zhuang@...aro.org>,
Linux OMAP Mailing List <linux-omap@...r.kernel.org>,
linux-arm Mailing List <linux-arm-kernel@...ts.infradead.org>
Subject: Re: [PATCH][next] pinctrl: pinctrl-single: add allocation failure
checking of saved_vals
On Wed, Jun 06, 2018 at 07:02:03PM +0300, Andy Shevchenko wrote:
> On Wed, Jun 6, 2018 at 4:43 PM, Colin King <colin.king@...onical.com> wrote:
> > From: Colin Ian King <colin.king@...onical.com>
> >
> > Currently saved_vals is being allocated and there is no check for
> > failed allocation (which is more likely than normal when using
> > GFP_ATOMIC). Fix this by checking for a failed allocation and
> > propagating this error return down the the caller chain.
> >
> > Detected by CoverityScan, CID#1469841 ("Dereference null return value")
> >
> > Fixes: 88a1dbdec682 ("pinctrl: pinctrl-single: Add functions to save and restore pinctrl context")
> > Signed-off-by: Colin Ian King <colin.king@...onical.com>
> > ---
> > drivers/pinctrl/pinctrl-single.c | 14 +++++++++++---
> > 1 file changed, 11 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
> > index 9c3c00515aa0..0905ee002041 100644
> > --- a/drivers/pinctrl/pinctrl-single.c
> > +++ b/drivers/pinctrl/pinctrl-single.c
> > @@ -1588,8 +1588,11 @@ static int pcs_save_context(struct pcs_device *pcs)
> >
> > mux_bytes = pcs->width / BITS_PER_BYTE;
> >
> > - if (!pcs->saved_vals)
> > + if (!pcs->saved_vals) {
> > pcs->saved_vals = devm_kzalloc(pcs->dev, pcs->size, GFP_ATOMIC);
>
> > + if (!pcs->saved_vals)
> > + return -ENOMEM;
>
> Wouldn't make sense to move it out of the first condition?
>
> Something like
>
> if (!foo)
> foo = ...malloc(...);
> if (!foo)
> return ...
No, checking for NULL immediately after the allocation is more obvious
and easier to parse.
Johan
Powered by blists - more mailing lists