From: Greg KH <gregkh@linuxfoundation.org>
To: James Clark <james.clark@arm.com>
Cc: linux-kernel@vger.kernel.org, linux@roeck-us.net,
michal.simek@amd.com, Jonathan.Cameron@huawei.com,
Jonathan Corbet <corbet@lwn.net>,
Jean Delvare <jdelvare@suse.com>,
Anand Ashok Dumbre <anand.ashok.dumbre@xilinx.com>,
Jonathan Cameron <jic23@kernel.org>,
Lars-Peter Clausen <lars@metafoo.de>,
Andy Gross <agross@kernel.org>,
Bjorn Andersson <andersson@kernel.org>,
Konrad Dybcio <konrad.dybcio@linaro.org>,
Jiri Slaby <jirislaby@kernel.org>,
linux-doc@vger.kernel.org, linux-hwmon@vger.kernel.org,
linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-arm-msm@vger.kernel.org, linux-serial@vger.kernel.org
Subject: Re: [PATCH v4 1/4] devres: Provide krealloc_array
Date: Sat, 13 May 2023 20:04:40 +0900 [thread overview]
Message-ID: <2023051340-sinuous-darkroom-2497@gregkh> (raw)
In-Reply-To: <20230509094942.396150-2-james.clark@arm.com>
On Tue, May 09, 2023 at 10:49:38AM +0100, James Clark wrote:
> There is no krealloc_array equivalent in devres. Users would have to
> do their own multiplication overflow check so provide one.
>
> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Signed-off-by: James Clark <james.clark@arm.com>
> ---
> Documentation/driver-api/driver-model/devres.rst | 1 +
> include/linux/device.h | 11 +++++++++++
> 2 files changed, 12 insertions(+)
>
> diff --git a/Documentation/driver-api/driver-model/devres.rst b/Documentation/driver-api/driver-model/devres.rst
> index 4249eb4239e0..8be086b3f829 100644
> --- a/Documentation/driver-api/driver-model/devres.rst
> +++ b/Documentation/driver-api/driver-model/devres.rst
> @@ -364,6 +364,7 @@ MEM
> devm_kmalloc_array()
> devm_kmemdup()
> devm_krealloc()
> + devm_krealloc_array()
> devm_kstrdup()
> devm_kstrdup_const()
> devm_kvasprintf()
> diff --git a/include/linux/device.h b/include/linux/device.h
> index 472dd24d4823..58f4f5948edb 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -223,6 +223,17 @@ static inline void *devm_kcalloc(struct device *dev,
> {
> return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO);
> }
> +static inline __realloc_size(3, 4) void * __must_check
Shouldn't you have a blank line before this one?
> +devm_krealloc_array(struct device *dev, void *p, size_t new_n, size_t new_size, gfp_t flags)
> +{
> + size_t bytes;
> +
> + if (unlikely(check_mul_overflow(new_n, new_size, &bytes)))
> + return NULL;
> +
> + return devm_krealloc(dev, p, bytes, flags);
> +}
I dislike how we have to keep copying the "real" functions (i.e.
krealloc_array) into something like this, but I can't think of a better
way to do it.
thanks,
greg k-h
next prev parent reply other threads:[~2023-05-13 11:09 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-09 9:49 [PATCH v4 0/4] devres: Provide krealloc_array James Clark
2023-05-09 9:49 ` [PATCH v4 1/4] " James Clark
2023-05-13 11:04 ` Greg KH [this message]
2023-05-15 7:55 ` James Clark
2023-05-15 11:55 ` Greg KH
2023-05-09 9:49 ` [PATCH v4 2/4] hwmon: pmbus: Use devm_krealloc_array James Clark
2023-05-09 9:49 ` [PATCH v4 3/4] iio: adc: " James Clark
2023-05-09 9:49 ` [PATCH v4 4/4] serial: qcom_geni: Comment use of devm_krealloc rather than devm_krealloc_array James Clark
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2023051340-sinuous-darkroom-2497@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=Jonathan.Cameron@huawei.com \
--cc=agross@kernel.org \
--cc=anand.ashok.dumbre@xilinx.com \
--cc=andersson@kernel.org \
--cc=corbet@lwn.net \
--cc=james.clark@arm.com \
--cc=jdelvare@suse.com \
--cc=jic23@kernel.org \
--cc=jirislaby@kernel.org \
--cc=konrad.dybcio@linaro.org \
--cc=lars@metafoo.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=michal.simek@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).