iio: core: Switch to krealloc_array()
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Mon, 24 Jul 2023 11:02:03 +0000 (14:02 +0300)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sat, 29 Jul 2023 11:47:28 +0000 (12:47 +0100)
Let the krealloc_array() copy the original data and
check for a multiplication overflow.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Nuno Sa <nuno.sa@analog.com>
Link: https://lore.kernel.org/r/20230724110204.46285-4-andriy.shevchenko@linux.intel.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/industrialio-core.c

index 895b89a..75e4f31 100644 (file)
@@ -1474,7 +1474,7 @@ int iio_device_register_sysfs_group(struct iio_dev *indio_dev,
        const struct attribute_group **new, **old = iio_dev_opaque->groups;
        unsigned int cnt = iio_dev_opaque->groupcounter;
 
-       new = krealloc(old, sizeof(*new) * (cnt + 2), GFP_KERNEL);
+       new = krealloc_array(old, cnt + 2, sizeof(*new), GFP_KERNEL);
        if (!new)
                return -ENOMEM;