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

Configure Feed

Select the types of activity you want to include in your feed.

iio: common: scmi_iio: use kcalloc() instead of kzalloc()

Replace calls of devm_kzalloc() with devm_kcalloc() in scmi_alloc_iiodev()
and scmi_iio_set_sampling_freq_avail() for safer memory allocation with
built-in overflow protection.

Similarly, use array_size() instead of explicit multiplication for
'sensor->sensor_info->intervals.count * 2'.

Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
Reviewed-by: Andy Shevchenko <andy@kernel.org>
Link: https://patch.msgid.link/20250819125017.635182-1-rongqianfeng@vivo.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Qianfeng Rong and committed by
Jonathan Cameron
ccef0530 a4ee7e22

+5 -5
+5 -5
drivers/iio/common/scmi_sensors/scmi_iio.c
··· 521 521 int i; 522 522 523 523 sensor->freq_avail = 524 - devm_kzalloc(&iio_dev->dev, 525 - sizeof(*sensor->freq_avail) * 526 - (sensor->sensor_info->intervals.count * 2), 524 + devm_kcalloc(&iio_dev->dev, 525 + array_size(sensor->sensor_info->intervals.count, 2), 526 + sizeof(*sensor->freq_avail), 527 527 GFP_KERNEL); 528 528 if (!sensor->freq_avail) 529 529 return -ENOMEM; ··· 597 597 iiodev->info = &scmi_iio_info; 598 598 599 599 iio_channels = 600 - devm_kzalloc(dev, 601 - sizeof(*iio_channels) * (iiodev->num_channels), 600 + devm_kcalloc(dev, iiodev->num_channels, 601 + sizeof(*iio_channels), 602 602 GFP_KERNEL); 603 603 if (!iio_channels) 604 604 return ERR_PTR(-ENOMEM);