Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

James Clark and committed by
Greg Kroah-Hartman
7c054b2c c5f75484

+10 -16
+3 -6
drivers/iio/adc/xilinx-ams.c
··· 1263 1263 struct device *dev = indio_dev->dev.parent; 1264 1264 struct fwnode_handle *child = NULL; 1265 1265 struct fwnode_handle *fwnode = dev_fwnode(dev); 1266 - size_t ams_size, dev_size; 1266 + size_t ams_size; 1267 1267 int ret, ch_cnt = 0, i, rising_off, falling_off; 1268 1268 unsigned int num_channels = 0; 1269 1269 ··· 1320 1320 } 1321 1321 } 1322 1322 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); 1328 1325 if (!dev_channels) 1329 1326 return -ENOMEM; 1330 1327
+7 -10
drivers/iio/adc/xilinx-xadc-core.c
··· 613 613 const unsigned long *mask) 614 614 { 615 615 struct xadc *xadc = iio_priv(indio_dev); 616 - size_t new_size, n; 616 + size_t n; 617 617 void *data; 618 618 619 619 n = bitmap_weight(mask, indio_dev->masklength); 620 620 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); 626 623 if (!data) 627 624 return -ENOMEM; 628 625 629 - memset(data, 0, new_size); 626 + memset(data, 0, n * sizeof(*xadc->data)); 630 627 xadc->data = data; 631 628 632 629 return 0; ··· 1278 1281 } 1279 1282 1280 1283 indio_dev->num_channels = num_channels; 1281 - indio_dev->channels = devm_krealloc(dev, channels, 1282 - sizeof(*channels) * num_channels, 1283 - GFP_KERNEL); 1284 + indio_dev->channels = devm_krealloc_array(dev, channels, 1285 + num_channels, sizeof(*channels), 1286 + GFP_KERNEL); 1284 1287 /* If we can't resize the channels array, just use the original */ 1285 1288 if (!indio_dev->channels) 1286 1289 indio_dev->channels = channels;