summaryrefslogtreecommitdiff
path: root/drivers/iio/adc
diff options
context:
space:
mode:
authorAlexandru Ardelean <alexandru.ardelean@analog.com>2020-04-28 14:14:28 +0300
committerJonathan Cameron <Jonathan.Cameron@huawei.com>2020-07-07 20:24:11 +0100
commit6ff0199a1df2f65d708a36aed944c3c11ba198f6 (patch)
tree936bff4fa20418a648fa0c0b3fc85a4bbcae153f /drivers/iio/adc
parenta07a4fe5ff460e99293c0d682421920d54e31d7f (diff)
iio: adc: ti_am335x_adc: alloc channels via devm_kcalloc()
This change attaches the life-cycle of the channels array to the parent device object that is attached to the IIO device. This way we can remove from the cleanup code, the explicit tiadc_channels_remove() which simply does a kfree() on the channels array. Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'drivers/iio/adc')
-rw-r--r--drivers/iio/adc/ti_am335x_adc.c15
1 files changed, 5 insertions, 10 deletions
diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c
index 55c583bf1664..68b863ec559c 100644
--- a/drivers/iio/adc/ti_am335x_adc.c
+++ b/drivers/iio/adc/ti_am335x_adc.c
@@ -428,7 +428,8 @@ static const char * const chan_name_ain[] = {
"AIN7",
};
-static int tiadc_channel_init(struct iio_dev *indio_dev, int channels)
+static int tiadc_channel_init(struct device *dev, struct iio_dev *indio_dev,
+ int channels)
{
struct tiadc_device *adc_dev = iio_priv(indio_dev);
struct iio_chan_spec *chan_array;
@@ -436,7 +437,8 @@ static int tiadc_channel_init(struct iio_dev *indio_dev, int channels)
int i;
indio_dev->num_channels = channels;
- chan_array = kcalloc(channels, sizeof(*chan_array), GFP_KERNEL);
+ chan_array = devm_kcalloc(dev, channels, sizeof(*chan_array),
+ GFP_KERNEL);
if (chan_array == NULL)
return -ENOMEM;
@@ -459,11 +461,6 @@ static int tiadc_channel_init(struct iio_dev *indio_dev, int channels)
return 0;
}
-static void tiadc_channels_remove(struct iio_dev *indio_dev)
-{
- kfree(indio_dev->channels);
-}
-
static int tiadc_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val, int *val2, long mask)
@@ -634,7 +631,7 @@ static int tiadc_probe(struct platform_device *pdev)
tiadc_writel(adc_dev, REG_FIFO1THR, FIFO1_THRESHOLD);
mutex_init(&adc_dev->fifo1_lock);
- err = tiadc_channel_init(indio_dev, adc_dev->channels);
+ err = tiadc_channel_init(&pdev->dev, indio_dev, adc_dev->channels);
if (err < 0)
return err;
@@ -665,7 +662,6 @@ err_dma:
err_buffer_unregister:
tiadc_iio_buffered_hardware_remove(indio_dev);
err_free_channels:
- tiadc_channels_remove(indio_dev);
return err;
}
@@ -683,7 +679,6 @@ static int tiadc_remove(struct platform_device *pdev)
}
iio_device_unregister(indio_dev);
tiadc_iio_buffered_hardware_remove(indio_dev);
- tiadc_channels_remove(indio_dev);
step_en = get_adc_step_mask(adc_dev);
am335x_tsc_se_clr(adc_dev->mfd_tscadc, step_en);