[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHp75VecWJXd-kP8mhFtFZpiU-qcW3_nQz=w1Addq7SHTv=SSQ@mail.gmail.com>
Date: Tue, 19 Aug 2025 13:13:04 +0300
From: Andy Shevchenko <andy.shevchenko@...il.com>
To: Qianfeng Rong <rongqianfeng@...o.com>
Cc: Jyoti Bhayana <jbhayana@...gle.com>, Jonathan Cameron <jic23@...nel.org>,
David Lechner <dlechner@...libre.com>, Nuno Sá <nuno.sa@...log.com>,
Andy Shevchenko <andy@...nel.org>, linux-iio@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] iio: common: scmi_iio: use kcalloc() instead of kzalloc()
On Tue, Aug 19, 2025 at 1:08 PM Qianfeng Rong <rongqianfeng@...o.com> wrote:
> 在 2025/8/19 17:46, Andy Shevchenko 写道:
> > On Tue, Aug 19, 2025 at 11:56 AM Qianfeng Rong <rongqianfeng@...o.com> wrote:
...
> > While this change is correct...
> >> sensor->freq_avail =
> >> - devm_kzalloc(&iio_dev->dev,
> >> - sizeof(*sensor->freq_avail) *
> >> - (sensor->sensor_info->intervals.count * 2),
> >> + devm_kcalloc(&iio_dev->dev,
> >> + sensor->sensor_info->intervals.count * 2,
> > ...I would also switch this to use array_size() instead of explicit
> > multiplication as it will check for boundaries that are not static in
> > this case.
>
> I don't understand what "will check for boundaries that are not static in
> this case" means. Could you explain it to me?
intervals.count may be anything and of any type. Compiler may or may
not proof that it holds the value less than size_t / 2 (which may be
== int / 2 on 32-bit platforms). That's why it's better to use
array_size(intervals.count, 2),
> I've experimented with the following command and found that kmalloc_array()
> generates fewer instructions than kmalloc(array_size()):
> objdump -dSl --prefix-addresses <changed module>.o
It's about the second parameter in devm_kcalloc(), and of course it
may generate less instructions but it's irrelevant to my comment.
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists