Re: [PATCH v6 10/12] watchdog: add gpio watchdog driver

Wolfgang Denk
2021-08-19T12:32:17Z

Dear Rasmus,

In message <62540f7b-0e07-8759-8e12-125527c2edec@prevas.dk> you wrote:
>
> >> +static int gpio_wdt_reset(struct udevice *dev)
> >> +{
> >> + struct gpio_wdt_priv *priv = dev_get_priv(dev);
> >> +
> >> + priv->state = !priv->state;
> >
> > Potential NULL pointer dereference.
>
> No, no and no. If allocation of the (driver or uclass) private data
> fails, the device probe would have failed, so this code can never get
> called with such a struct udevice.

Famous last words...

> Perhaps try doing a
>
> git grep -10 -E 'dev_get(_uclass)?_priv'
>
> and see how many cases you can find where that is followed by a NULL check?

The existence of bad code is not a justification to add more of it.

Best regards,

Wolfgang Denk

--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de
No, I'm not going to explain it. If you can't figure it out, you
didn't want to know anyway... :-)
- Larry Wall in <1991Aug7.180856.2854@netlabs.com>