From: James Clark <james.clark@arm.com> To: linux-kernel@vger.kernel.org Cc: James Clark <james.clark@arm.com>, Jonathan Corbet <corbet@lwn.net>, Guenter Roeck <linux@roeck-us.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>, Michal Simek <michal.simek@xilinx.com>, Andy Gross <agross@kernel.org>, Bjorn Andersson <andersson@kernel.org>, Konrad Dybcio <konrad.dybcio@linaro.org>, Greg Kroah-Hartman <gregkh@linuxfoundation.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: [PATCH 1/4] devres: Provide krealloc_array Date: Mon, 6 Mar 2023 15:27:20 +0000 [thread overview] Message-ID: <20230306152723.3090195-2-james.clark@arm.com> (raw) In-Reply-To: <20230306152723.3090195-1-james.clark@arm.com> There is no krealloc_array equivalent in devres. Users would have to do their own multiplication overflow check so provide one. Signed-off-by: James Clark <james.clark@arm.com> --- Documentation/driver-api/driver-model/devres.rst | 1 + include/linux/device.h | 10 ++++++++++ 2 files changed, 11 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 1508e637bb26..0dd5956c8516 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -223,6 +223,16 @@ 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 +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); +} + void devm_kfree(struct device *dev, const void *p); char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp) __malloc; const char *devm_kstrdup_const(struct device *dev, const char *s, gfp_t gfp); -- 2.34.1
WARNING: multiple messages have this Message-ID (diff)
From: James Clark <james.clark@arm.com> To: linux-kernel@vger.kernel.org Cc: James Clark <james.clark@arm.com>, Jonathan Corbet <corbet@lwn.net>, Guenter Roeck <linux@roeck-us.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>, Michal Simek <michal.simek@xilinx.com>, Andy Gross <agross@kernel.org>, Bjorn Andersson <andersson@kernel.org>, Konrad Dybcio <konrad.dybcio@linaro.org>, Greg Kroah-Hartman <gregkh@linuxfoundation.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: [PATCH 1/4] devres: Provide krealloc_array Date: Mon, 6 Mar 2023 15:27:20 +0000 [thread overview] Message-ID: <20230306152723.3090195-2-james.clark@arm.com> (raw) In-Reply-To: <20230306152723.3090195-1-james.clark@arm.com> There is no krealloc_array equivalent in devres. Users would have to do their own multiplication overflow check so provide one. Signed-off-by: James Clark <james.clark@arm.com> --- Documentation/driver-api/driver-model/devres.rst | 1 + include/linux/device.h | 10 ++++++++++ 2 files changed, 11 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 1508e637bb26..0dd5956c8516 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -223,6 +223,16 @@ 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 +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); +} + void devm_kfree(struct device *dev, const void *p); char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp) __malloc; const char *devm_kstrdup_const(struct device *dev, const char *s, gfp_t gfp); -- 2.34.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2023-03-06 15:27 UTC|newest] Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-03-06 15:27 [PATCH 0/4] devres: Provide krealloc_array James Clark 2023-03-06 15:27 ` James Clark 2023-03-06 15:27 ` James Clark [this message] 2023-03-06 15:27 ` [PATCH 1/4] " James Clark 2023-03-06 15:27 ` [PATCH 2/4] hwmon: pmbus: Use devm_krealloc_array James Clark 2023-03-06 15:27 ` James Clark 2023-03-06 15:30 ` Guenter Roeck 2023-03-06 15:30 ` Guenter Roeck 2023-03-06 15:27 ` [PATCH 3/4] iio: adc: " James Clark 2023-03-06 15:27 ` James Clark 2023-03-08 11:58 ` Michal Simek 2023-03-08 11:58 ` Michal Simek 2023-03-09 15:04 ` James Clark 2023-03-09 15:04 ` James Clark 2023-03-06 15:27 ` [PATCH 4/4] serial: qcom_geni: " James Clark 2023-03-06 15:27 ` 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=20230306152723.3090195-2-james.clark@arm.com \ --to=james.clark@arm.com \ --cc=agross@kernel.org \ --cc=anand.ashok.dumbre@xilinx.com \ --cc=andersson@kernel.org \ --cc=corbet@lwn.net \ --cc=gregkh@linuxfoundation.org \ --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@xilinx.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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.