Skip to content

Commit 7c054b2

Browse files
James-A-Clarkgregkh
authored andcommitted
iio: adc: Use devm_krealloc_array
Now that it exists, use it instead of doing the multiplication and checking for overflow manually. Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: James Clark <james.clark@arm.com> Link: https://lore.kernel.org/r/20230509094942.396150-4-james.clark@arm.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c5f7548 commit 7c054b2

2 files changed

Lines changed: 10 additions & 16 deletions

File tree

drivers/iio/adc/xilinx-ams.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,7 @@ static int ams_parse_firmware(struct iio_dev *indio_dev)
12631263
struct device *dev = indio_dev->dev.parent;
12641264
struct fwnode_handle *child = NULL;
12651265
struct fwnode_handle *fwnode = dev_fwnode(dev);
1266-
size_t ams_size, dev_size;
1266+
size_t ams_size;
12671267
int ret, ch_cnt = 0, i, rising_off, falling_off;
12681268
unsigned int num_channels = 0;
12691269

@@ -1320,11 +1320,8 @@ static int ams_parse_firmware(struct iio_dev *indio_dev)
13201320
}
13211321
}
13221322

1323-
dev_size = array_size(sizeof(*dev_channels), num_channels);
1324-
if (dev_size == SIZE_MAX)
1325-
return -ENOMEM;
1326-
1327-
dev_channels = devm_krealloc(dev, ams_channels, dev_size, GFP_KERNEL);
1323+
dev_channels = devm_krealloc_array(dev, ams_channels, num_channels,
1324+
sizeof(*dev_channels), GFP_KERNEL);
13281325
if (!dev_channels)
13291326
return -ENOMEM;
13301327

drivers/iio/adc/xilinx-xadc-core.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -613,20 +613,17 @@ static int xadc_update_scan_mode(struct iio_dev *indio_dev,
613613
const unsigned long *mask)
614614
{
615615
struct xadc *xadc = iio_priv(indio_dev);
616-
size_t new_size, n;
616+
size_t n;
617617
void *data;
618618

619619
n = bitmap_weight(mask, indio_dev->masklength);
620620

621-
if (check_mul_overflow(n, sizeof(*xadc->data), &new_size))
622-
return -ENOMEM;
623-
624-
data = devm_krealloc(indio_dev->dev.parent, xadc->data,
625-
new_size, GFP_KERNEL);
621+
data = devm_krealloc_array(indio_dev->dev.parent, xadc->data,
622+
n, sizeof(*xadc->data), GFP_KERNEL);
626623
if (!data)
627624
return -ENOMEM;
628625

629-
memset(data, 0, new_size);
626+
memset(data, 0, n * sizeof(*xadc->data));
630627
xadc->data = data;
631628

632629
return 0;
@@ -1281,9 +1278,9 @@ static int xadc_parse_dt(struct iio_dev *indio_dev, unsigned int *conf, int irq)
12811278
}
12821279

12831280
indio_dev->num_channels = num_channels;
1284-
indio_dev->channels = devm_krealloc(dev, channels,
1285-
sizeof(*channels) * num_channels,
1286-
GFP_KERNEL);
1281+
indio_dev->channels = devm_krealloc_array(dev, channels,
1282+
num_channels, sizeof(*channels),
1283+
GFP_KERNEL);
12871284
/* If we can't resize the channels array, just use the original */
12881285
if (!indio_dev->channels)
12891286
indio_dev->channels = channels;

0 commit comments

Comments
 (0)