Re: [PATCH] iio: proximity: sx9310: fix NULL pointer dereference in sx9310_check_whoami
From: Andy Shevchenko
Date: Wed Aug 26 2026 - 10:02:58 EST
On Tue, Aug 25, 2026 at 05:18:01PM +0800, Yang Zi wrote:
> device_get_match_data() can return NULL, e.g. when the device is matched
> through the I2C device ID table rather than the OF/ACPI match tables. In
> that case sx9310_check_whoami() dereferences a NULL pointer when reading
> ddata->whoami.
>
> Return -ENODEV if no match data is found to avoid the NULL pointer
> dereference.
-ENODATA, please.
...
> ddata = device_get_match_data(dev);
> + if (!ddata)
> + return -ENODEV;
+ blank line.
> if (ddata->whoami != whoami)
> return -ENODEV;
>
--
With Best Regards,
Andy Shevchenko