[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <2023051340-sinuous-darkroom-2497@gregkh>
Date: Sat, 13 May 2023 20:04:40 +0900
From: Greg KH <gregkh@...uxfoundation.org>
To: James Clark <james.clark@....com>
Cc: linux-kernel@...r.kernel.org, linux@...ck-us.net,
michal.simek@....com, Jonathan.Cameron@...wei.com,
Jonathan Corbet <corbet@....net>,
Jean Delvare <jdelvare@...e.com>,
Anand Ashok Dumbre <anand.ashok.dumbre@...inx.com>,
Jonathan Cameron <jic23@...nel.org>,
Lars-Peter Clausen <lars@...afoo.de>,
Andy Gross <agross@...nel.org>,
Bjorn Andersson <andersson@...nel.org>,
Konrad Dybcio <konrad.dybcio@...aro.org>,
Jiri Slaby <jirislaby@...nel.org>, linux-doc@...r.kernel.org,
linux-hwmon@...r.kernel.org, linux-iio@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org,
linux-arm-msm@...r.kernel.org, linux-serial@...r.kernel.org
Subject: Re: [PATCH v4 1/4] devres: Provide krealloc_array
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@...wei.com>
> Signed-off-by: James Clark <james.clark@....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
Powered by blists - more mailing lists