[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20201102142228.14949-4-brgl@bgdev.pl>
Date: Mon, 2 Nov 2020 15:22:27 +0100
From: Bartosz Golaszewski <brgl@...ev.pl>
To: Jonathan Cameron <jic23@...nel.org>,
Lars-Peter Clausen <lars@...afoo.de>,
Peter Meerwald-Stadler <pmeerw@...erw.net>,
Michal Simek <michal.simek@...inx.com>
Cc: linux-iio@...r.kernel.org, linux-arm-kernel@...ts.infradead.org,
linux-kernel@...r.kernel.org,
Bartosz Golaszewski <bgolaszewski@...libre.com>
Subject: [PATCH v2 3/4] iio: adc: xilinx: use devm_krealloc_array() instead of kfree() + kcalloc()
From: Bartosz Golaszewski <bgolaszewski@...libre.com>
We now have devm_krealloc_array() in the kernel Use it indstead of calling
kfree() and kcalloc() separately.
Signed-off-by: Bartosz Golaszewski <bgolaszewski@...libre.com>
---
drivers/iio/adc/xilinx-xadc-core.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/adc/xilinx-xadc-core.c b/drivers/iio/adc/xilinx-xadc-core.c
index 8494eb424b33..7792aa4cf9cb 100644
--- a/drivers/iio/adc/xilinx-xadc-core.c
+++ b/drivers/iio/adc/xilinx-xadc-core.c
@@ -586,14 +586,18 @@ static int xadc_update_scan_mode(struct iio_dev *indio_dev,
{
struct xadc *xadc = iio_priv(indio_dev);
unsigned int 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)
+ data = devm_krealloc_array(indio_dev->dev.parent, xadc->data, n,
+ sizeof(*xadc->data), GFP_KERNEL);
+ if (!data)
return -ENOMEM;
+ memset(data, 0, n * sizeof(*xadc->data));
+ xadc->data = data;
+
return 0;
}
@@ -1372,7 +1376,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;
}
--
2.29.1
Powered by blists - more mailing lists