From: Raag Jadav Date: Wed, 12 Feb 2025 06:25:05 +0000 (+0530) Subject: devres: Introduce devm_kmemdup_array() X-Git-Tag: v6.15-rc1~183^2~8^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a103b833ac3806b816bc993cba77d0b17cf801f1;p=thirdparty%2Fkernel%2Flinux.git devres: Introduce devm_kmemdup_array() Introduce '_array' variant of devm_kmemdup() which is more robust and consistent with alloc family of helpers. Suggested-by: Andy Shevchenko Signed-off-by: Raag Jadav Reviewed-by: Dmitry Torokhov Reviewed-by: Linus Walleij Signed-off-by: Andy Shevchenko --- diff --git a/include/linux/device/devres.h b/include/linux/device/devres.h index 6b0b265058bcc..9b49f99158508 100644 --- a/include/linux/device/devres.h +++ b/include/linux/device/devres.h @@ -79,6 +79,11 @@ void devm_kfree(struct device *dev, const void *p); void * __realloc_size(3) devm_kmemdup(struct device *dev, const void *src, size_t len, gfp_t gfp); +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); +} char * __malloc devm_kstrdup(struct device *dev, const char *s, gfp_t gfp);