mirror of
https://github.com/torvalds/linux.git
synced 2026-05-24 07:03:03 +02:00
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>
This commit is contained in:
parent
a4ee7e220c
commit
ccef0530e6
|
|
@ -521,9 +521,9 @@ static int scmi_iio_set_sampling_freq_avail(struct iio_dev *iio_dev)
|
|||
int i;
|
||||
|
||||
sensor->freq_avail =
|
||||
devm_kzalloc(&iio_dev->dev,
|
||||
sizeof(*sensor->freq_avail) *
|
||||
(sensor->sensor_info->intervals.count * 2),
|
||||
devm_kcalloc(&iio_dev->dev,
|
||||
array_size(sensor->sensor_info->intervals.count, 2),
|
||||
sizeof(*sensor->freq_avail),
|
||||
GFP_KERNEL);
|
||||
if (!sensor->freq_avail)
|
||||
return -ENOMEM;
|
||||
|
|
@ -597,8 +597,8 @@ scmi_alloc_iiodev(struct scmi_device *sdev,
|
|||
iiodev->info = &scmi_iio_info;
|
||||
|
||||
iio_channels =
|
||||
devm_kzalloc(dev,
|
||||
sizeof(*iio_channels) * (iiodev->num_channels),
|
||||
devm_kcalloc(dev, iiodev->num_channels,
|
||||
sizeof(*iio_channels),
|
||||
GFP_KERNEL);
|
||||
if (!iio_channels)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user