linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] iio: common: scmi_iio: use kcalloc() instead of kzalloc()
@ 2025-08-19 12:50 Qianfeng Rong
  2025-08-19 18:43 ` Andy Shevchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Qianfeng Rong @ 2025-08-19 12:50 UTC (permalink / raw)
  To: Jyoti Bhayana, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, linux-iio, linux-kernel
  Cc: Qianfeng Rong

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>
---
v2:
Changed explicit multiplication 'sensor->sensor_info->intervals.count*2'
to use array_size().
---
 drivers/iio/common/scmi_sensors/scmi_iio.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/common/scmi_sensors/scmi_iio.c b/drivers/iio/common/scmi_sensors/scmi_iio.c
index da516c46e057..39c61c47022a 100644
--- a/drivers/iio/common/scmi_sensors/scmi_iio.c
+++ b/drivers/iio/common/scmi_sensors/scmi_iio.c
@@ -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);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] iio: common: scmi_iio: use kcalloc() instead of kzalloc()
  2025-08-19 12:50 [PATCH v2] iio: common: scmi_iio: use kcalloc() instead of kzalloc() Qianfeng Rong
@ 2025-08-19 18:43 ` Andy Shevchenko
  0 siblings, 0 replies; 2+ messages in thread
From: Andy Shevchenko @ 2025-08-19 18:43 UTC (permalink / raw)
  To: Qianfeng Rong
  Cc: Jyoti Bhayana, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, linux-iio, linux-kernel

On Tue, Aug 19, 2025 at 3:50 PM Qianfeng Rong <rongqianfeng@vivo.com> wrote:
>
> 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

Use --> use
(no need to resend just for this)

> 'sensor->sensor_info->intervals.count * 2'.

Reviewed-by: Andy Shevchenko <andy@kernel.org>

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-08-19 18:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-19 12:50 [PATCH v2] iio: common: scmi_iio: use kcalloc() instead of kzalloc() Qianfeng Rong
2025-08-19 18:43 ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).