Commit eab64715 authored by Bartosz Golaszewski's avatar Bartosz Golaszewski Committed by Jonathan Cameron

iio: adc: xilinx: use devm_krealloc() instead of kfree() + kcalloc()

We now have devm_krealloc() in the kernel Use it indstead of calling
kfree() and kcalloc() separately.
Signed-off-by: default avatarBartosz Golaszewski <bgolaszewski@baylibre.com>
Tested-by: default avatarAnand Ashok Dumbre <anandash@xilinx.com>
Reviewed-by: default avatarAnand Ashok Dumbre <anandash@xilinx.com>
Link: https://lore.kernel.org/r/20201130142759.28216-3-brgl@bgdev.plSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 9d8fd2a0
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/overflow.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/sysfs.h> #include <linux/sysfs.h>
...@@ -610,15 +611,22 @@ static int xadc_update_scan_mode(struct iio_dev *indio_dev, ...@@ -610,15 +611,22 @@ static int xadc_update_scan_mode(struct iio_dev *indio_dev,
const unsigned long *mask) const unsigned long *mask)
{ {
struct xadc *xadc = iio_priv(indio_dev); struct xadc *xadc = iio_priv(indio_dev);
unsigned int n; size_t new_size, n;
void *data;
n = bitmap_weight(mask, indio_dev->masklength); n = bitmap_weight(mask, indio_dev->masklength);
kfree(xadc->data); if (check_mul_overflow(n, sizeof(*xadc->data), &new_size))
xadc->data = kcalloc(n, sizeof(*xadc->data), GFP_KERNEL); return -ENOMEM;
if (!xadc->data)
data = devm_krealloc(indio_dev->dev.parent, xadc->data,
new_size, GFP_KERNEL);
if (!data)
return -ENOMEM; return -ENOMEM;
memset(data, 0, new_size);
xadc->data = data;
return 0; return 0;
} }
...@@ -1473,7 +1481,6 @@ static int xadc_remove(struct platform_device *pdev) ...@@ -1473,7 +1481,6 @@ static int xadc_remove(struct platform_device *pdev)
free_irq(xadc->irq, indio_dev); free_irq(xadc->irq, indio_dev);
cancel_delayed_work_sync(&xadc->zynq_unmask_work); cancel_delayed_work_sync(&xadc->zynq_unmask_work);
clk_disable_unprepare(xadc->clk); clk_disable_unprepare(xadc->clk);
kfree(xadc->data);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment