* [PATCH] iio: adc: ti-ads1298: Add NULL check in ads1298_init
@ 2024-11-18 9:02 Charles Han
2024-11-18 10:08 ` [PATCH] iio: adc: ti-ads1298: Add NULL check in ads1298_init() Markus Elfring
0 siblings, 1 reply; 3+ messages in thread
From: Charles Han @ 2024-11-18 9:02 UTC (permalink / raw)
To: mike.looijmans, jic23, lars, dan.carpenter, nuno.sa,
andriy.shevchenko, viro, yujiaoliang
Cc: linux-iio, linux-kernel, Charles Han
devm_kasprintf() can return a NULL pointer on failure,but this
returned value in ads1298_init() is not checked.
Add NULL check in ads1298_init(), to handle kernel NULL
pointer dereference error.
Fixes: 00ef7708fa60 ("iio: adc: ti-ads1298: Add driver")
Signed-off-by: Charles Han <hanchunchao@inspur.com>
---
drivers/iio/adc/ti-ads1298.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/iio/adc/ti-ads1298.c b/drivers/iio/adc/ti-ads1298.c
index 36d43495f603..03f762415fa5 100644
--- a/drivers/iio/adc/ti-ads1298.c
+++ b/drivers/iio/adc/ti-ads1298.c
@@ -613,6 +613,8 @@ static int ads1298_init(struct iio_dev *indio_dev)
}
indio_dev->name = devm_kasprintf(dev, GFP_KERNEL, "ads129%u%s",
indio_dev->num_channels, suffix);
+ if (!indio_dev->name)
+ return -ENOMEM;
/* Enable internal test signal, double amplitude, double frequency */
ret = regmap_write(priv->regmap, ADS1298_REG_CONFIG2,
--
2.31.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: adc: ti-ads1298: Add NULL check in ads1298_init()
2024-11-18 9:02 [PATCH] iio: adc: ti-ads1298: Add NULL check in ads1298_init Charles Han
@ 2024-11-18 10:08 ` Markus Elfring
2024-11-24 17:54 ` Jonathan Cameron
0 siblings, 1 reply; 3+ messages in thread
From: Markus Elfring @ 2024-11-18 10:08 UTC (permalink / raw)
To: Charles Han, linux-iio, Andy Shevchenko, Dan Carpenter,
Jonathan Cameron, Lars-Peter Clausen, Mike Looijmans,
Nuno Sá, Alexander Viro, Yu Jiaoliang
Cc: LKML
> devm_kasprintf() can return a NULL pointer on failure,but this
> returned value in ads1298_init() is not checked.
> Add NULL check in ads1298_init(), to handle kernel NULL
> pointer dereference error.
Another wording suggestion:
A devm_kasprintf() call can return a null pointer on failure.
But such a return value was not checked in this function implementation.
Thus add a corresponding check so that a null pointer dereference
will be avoided.
Regards,
Markus
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: adc: ti-ads1298: Add NULL check in ads1298_init()
2024-11-18 10:08 ` [PATCH] iio: adc: ti-ads1298: Add NULL check in ads1298_init() Markus Elfring
@ 2024-11-24 17:54 ` Jonathan Cameron
0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2024-11-24 17:54 UTC (permalink / raw)
To: Markus Elfring
Cc: Charles Han, linux-iio, Andy Shevchenko, Dan Carpenter,
Lars-Peter Clausen, Mike Looijmans, Nuno Sá, Alexander Viro,
Yu Jiaoliang, LKML
On Mon, 18 Nov 2024 11:08:47 +0100
Markus Elfring <Markus.Elfring@web.de> wrote:
> > devm_kasprintf() can return a NULL pointer on failure,but this
> > returned value in ads1298_init() is not checked.
> > Add NULL check in ads1298_init(), to handle kernel NULL
> > pointer dereference error.
>
> Another wording suggestion:
> A devm_kasprintf() call can return a null pointer on failure.
> But such a return value was not checked in this function implementation.
> Thus add a corresponding check so that a null pointer dereference
> will be avoided.
>
>
> Regards,
> Markus
I tweaked it to slightly shorter form.
Applied and marked for stable.
Thanks,
Jonathan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-11-24 17:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-18 9:02 [PATCH] iio: adc: ti-ads1298: Add NULL check in ads1298_init Charles Han
2024-11-18 10:08 ` [PATCH] iio: adc: ti-ads1298: Add NULL check in ads1298_init() Markus Elfring
2024-11-24 17:54 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox