drivers/iio/adc/pac1934.c | 3 +++ 1 file changed, 3 insertions(+)
Add check for the return value of devm_kmemdup()
to prevent potential null pointer dereference.
Fixes: 0fb528c8255b ("iio: adc: adding support for PAC193x")
Signed-off-by: Charles Han <hanchunchao@inspur.com>
---
drivers/iio/adc/pac1934.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/iio/adc/pac1934.c b/drivers/iio/adc/pac1934.c
index 2e442e46f679..95c9d14b5529 100644
--- a/drivers/iio/adc/pac1934.c
+++ b/drivers/iio/adc/pac1934.c
@@ -1108,6 +1108,9 @@ static int pac1934_acpi_parse_channel_config(struct i2c_client *client,
devm_kmemdup(dev, rez->package.elements[i].string.pointer,
(size_t)rez->package.elements[i].string.length + 1,
GFP_KERNEL);
+ if (!info->labels[idx])
+ return -ENOMEM;
+
info->labels[idx][rez->package.elements[i].string.length] = '\0';
info->shunts[idx] = rez->package.elements[i + 1].integer.value * 1000;
info->active_channels[idx] = (info->shunts[idx] != 0);
--
2.43.0
On 9/1/25 1:45 AM, Charles Han wrote: > Add check for the return value of devm_kmemdup() > to prevent potential null pointer dereference. > > Fixes: 0fb528c8255b ("iio: adc: adding support for PAC193x") > Signed-off-by: Charles Han <hanchunchao@inspur.com> > --- Reviewed-by: David Lechner <dlechner@baylibre.com>
On Mon, 1 Sep 2025 14:45:11 +0800 Charles Han <hanchunchao@inspur.com> wrote: > Add check for the return value of devm_kmemdup() > to prevent potential null pointer dereference. > > Fixes: 0fb528c8255b ("iio: adc: adding support for PAC193x") > Signed-off-by: Charles Han <hanchunchao@inspur.com> Good catch, but not that simple. This just leaked an ACPI resource that was held over the loop this is in. See the ACPI_FREE() that follows it. Jonathan > --- > drivers/iio/adc/pac1934.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/iio/adc/pac1934.c b/drivers/iio/adc/pac1934.c > index 2e442e46f679..95c9d14b5529 100644 > --- a/drivers/iio/adc/pac1934.c > +++ b/drivers/iio/adc/pac1934.c > @@ -1108,6 +1108,9 @@ static int pac1934_acpi_parse_channel_config(struct i2c_client *client, > devm_kmemdup(dev, rez->package.elements[i].string.pointer, > (size_t)rez->package.elements[i].string.length + 1, > GFP_KERNEL); > + if (!info->labels[idx]) > + return -ENOMEM; > + > info->labels[idx][rez->package.elements[i].string.length] = '\0'; > info->shunts[idx] = rez->package.elements[i + 1].integer.value * 1000; > info->active_channels[idx] = (info->shunts[idx] != 0);
© 2016 - 2025 Red Hat, Inc.