* [PATCH] iio: proximity: sx9310: fix NULL pointer dereference in sx9310_check_whoami
@ 2026-08-25 9:18 Yang Zi
2026-08-25 9:28 ` Joshua Crofts
2026-08-26 14:00 ` Andy Shevchenko
0 siblings, 2 replies; 3+ messages in thread
From: Yang Zi @ 2026-08-25 9:18 UTC (permalink / raw)
To: jic23, linux-iio
Cc: dlechner, nuno.sa, andy, u.kleine-koenig, dakr, o-takashi, email,
linux-kernel
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.
Signed-off-by: Yang Zi <2959243019@qq.com>
---
diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c
index 79ba46d8a0aa..305b41f2847d 100644
--- a/drivers/iio/proximity/sx9310.c
+++ b/drivers/iio/proximity/sx9310.c
@@ -892,6 +892,8 @@ static int sx9310_check_whoami(struct device *dev,
return ret;
ddata = device_get_match_data(dev);
+ if (!ddata)
+ return -ENODEV;
if (ddata->whoami != whoami)
return -ENODEV;
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: proximity: sx9310: fix NULL pointer dereference in sx9310_check_whoami
2026-08-25 9:18 [PATCH] iio: proximity: sx9310: fix NULL pointer dereference in sx9310_check_whoami Yang Zi
@ 2026-08-25 9:28 ` Joshua Crofts
2026-08-26 14:00 ` Andy Shevchenko
1 sibling, 0 replies; 3+ messages in thread
From: Joshua Crofts @ 2026-08-25 9:28 UTC (permalink / raw)
To: Yang Zi
Cc: jic23, linux-iio, dlechner, nuno.sa, andy, u.kleine-koenig, dakr,
o-takashi, email, linux-kernel
On Tue, 25 Aug 2026 17:18:01 +0800
Yang Zi <2959243019@qq.com> 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.
>
> Signed-off-by: Yang Zi <2959243019@qq.com>
> ---
> diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c
> index 79ba46d8a0aa..305b41f2847d 100644
> --- a/drivers/iio/proximity/sx9310.c
> +++ b/drivers/iio/proximity/sx9310.c
> @@ -892,6 +892,8 @@ static int sx9310_check_whoami(struct device *dev,
> return ret;
>
> ddata = device_get_match_data(dev);
> + if (!ddata)
> + return -ENODEV;
-ENODATA is preferred in IIO.
Also looking at the cc list, no need to add addresses that have "commit_signer"
next to them when running get_maintainer.pl, just maintainers, reviewers and
mailing lists.
--
Kind regards,
Joshua Crofts
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: proximity: sx9310: fix NULL pointer dereference in sx9310_check_whoami
2026-08-25 9:18 [PATCH] iio: proximity: sx9310: fix NULL pointer dereference in sx9310_check_whoami Yang Zi
2026-08-25 9:28 ` Joshua Crofts
@ 2026-08-26 14:00 ` Andy Shevchenko
1 sibling, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2026-08-26 14:00 UTC (permalink / raw)
To: Yang Zi
Cc: jic23, linux-iio, dlechner, nuno.sa, andy, u.kleine-koenig, dakr,
o-takashi, email, linux-kernel
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-08-26 14:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-25 9:18 [PATCH] iio: proximity: sx9310: fix NULL pointer dereference in sx9310_check_whoami Yang Zi
2026-08-25 9:28 ` Joshua Crofts
2026-08-26 14:00 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox