This is a note to let you know that I've just added the patch titled iio: adc: xilinx: use devm_krealloc() instead of kfree() + kcalloc() to the 5.10-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: iio-adc-xilinx-use-devm_krealloc-instead-of-kfree-kc.patch and it can be found in the queue-5.10 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. commit 49dbe0191303691b44cd796ff0855a4833f6c79d Author: Bartosz Golaszewski <brgl@xxxxxxxx> Date: Mon Nov 30 15:27:58 2020 +0100 iio: adc: xilinx: use devm_krealloc() instead of kfree() + kcalloc() [ Upstream commit eab64715709ed440d54cac42f239e2d49df26c1f ] We now have devm_krealloc() in the kernel Use it indstead of calling kfree() and kcalloc() separately. Signed-off-by: Bartosz Golaszewski <bgolaszewski@xxxxxxxxxxxx> Tested-by: Anand Ashok Dumbre <anandash@xxxxxxxxxx> Reviewed-by: Anand Ashok Dumbre <anandash@xxxxxxxxxx> Link: https://lore.kernel.org/r/20201130142759.28216-3-brgl@xxxxxxxx Signed-off-by: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx> Stable-dep-of: 8d6b3ea4d9ea ("iio: adc: xilinx-xadc: Don't clobber preset voltage/temperature thresholds") Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx> diff --git a/drivers/iio/adc/xilinx-xadc-core.c b/drivers/iio/adc/xilinx-xadc-core.c index 8494eb424b331..6f89a97bb127b 100644 --- a/drivers/iio/adc/xilinx-xadc-core.c +++ b/drivers/iio/adc/xilinx-xadc-core.c @@ -19,6 +19,7 @@ #include <linux/kernel.h> #include <linux/module.h> #include <linux/of.h> +#include <linux/overflow.h> #include <linux/platform_device.h> #include <linux/slab.h> #include <linux/sysfs.h> @@ -585,15 +586,22 @@ static int xadc_update_scan_mode(struct iio_dev *indio_dev, const unsigned long *mask) { struct xadc *xadc = iio_priv(indio_dev); - unsigned int n; + size_t new_size, n; + void *data; n = bitmap_weight(mask, indio_dev->masklength); - kfree(xadc->data); - xadc->data = kcalloc(n, sizeof(*xadc->data), GFP_KERNEL); - if (!xadc->data) + if (check_mul_overflow(n, sizeof(*xadc->data), &new_size)) + return -ENOMEM; + + data = devm_krealloc(indio_dev->dev.parent, xadc->data, + new_size, GFP_KERNEL); + if (!data) return -ENOMEM; + memset(data, 0, new_size); + xadc->data = data; + return 0; } @@ -1372,7 +1380,6 @@ static int xadc_remove(struct platform_device *pdev) free_irq(xadc->irq, indio_dev); cancel_delayed_work_sync(&xadc->zynq_unmask_work); clk_disable_unprepare(xadc->clk); - kfree(xadc->data); return 0; }