[SRU][P][PATCH 1/2] devres: Introduce devm_kmemdup_array()

Juerg Haefliger juerg.haefliger at canonical.com
Wed Jul 2 14:17:29 UTC 2025


From: Raag Jadav <raag.jadav at intel.com>

Introduce '_array' variant of devm_kmemdup() which is more robust and
consistent with alloc family of helpers.

Suggested-by: Andy Shevchenko <andriy.shevchenko at linux.intel.com>
Signed-off-by: Raag Jadav <raag.jadav at intel.com>
Reviewed-by: Dmitry Torokhov <dmitry.torokhov at gmail.com>
Reviewed-by: Linus Walleij <linus.walleij at linaro.org>
Signed-off-by: Andy Shevchenko <andriy.shevchenko at linux.intel.com>
(backported from commit a103b833ac3806b816bc993cba77d0b17cf801f1)
[juergh: Add function definition to include/linux/device.h]
CVE-2025-38056
Signed-off-by: Juerg Haefliger <juerg.haefliger at canonical.com>
---
 include/linux/device.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/include/linux/device.h b/include/linux/device.h
index 80a5b3268986..2b8dcb662c24 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -358,6 +358,11 @@ 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);
 void *devm_kmemdup(struct device *dev, const void *src, size_t len, gfp_t gfp)
 	__realloc_size(3);
+static inline void *devm_kmemdup_array(struct device *dev, const void *src,
+				       size_t n, size_t size, gfp_t flags)
+{
+	return devm_kmemdup(dev, src, size_mul(size, n), flags);
+}
 
 unsigned long devm_get_free_pages(struct device *dev,
 				  gfp_t gfp_mask, unsigned int order);
-- 
2.48.1




More information about the kernel-team mailing list