Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Convert regulator drivers to use

Merge series from Raag Jadav <raag.jadav@intel.com>:

This series converts regulator drivers to use the newly introduced[1]
devm_kmemdup_array() helper.

[1] https://lore.kernel.org/r/20250212062513.2254767-1-raag.jadav@intel.com

+139 -127
+1 -1
drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c
··· 7 7 * Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com> 8 8 */ 9 9 10 - #include <linux/device.h> 10 + #include <linux/device/devres.h> 11 11 #include <linux/err.h> 12 12 #include <linux/gfp_types.h> 13 13 #include <linux/i2c.h>
+1 -1
drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_spi.c
··· 7 7 * Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com> 8 8 */ 9 9 10 - #include <linux/device.h> 10 + #include <linux/device/devres.h> 11 11 #include <linux/err.h> 12 12 #include <linux/gfp_types.h> 13 13 #include <linux/module.h>
+2 -2
drivers/regulator/cros-ec-regulator.c
··· 138 138 data->num_voltages = 139 139 min_t(u16, ARRAY_SIZE(resp.voltages_mv), resp.num_voltages); 140 140 data->voltages_mV = 141 - devm_kmemdup(dev, resp.voltages_mv, 142 - sizeof(u16) * data->num_voltages, GFP_KERNEL); 141 + devm_kmemdup_array(dev, resp.voltages_mv, data->num_voltages, 142 + sizeof(resp.voltages_mv[0]), GFP_KERNEL); 143 143 if (!data->voltages_mV) 144 144 return -ENOMEM; 145 145
+2 -3
drivers/regulator/devres.c
··· 332 332 const struct regulator_bulk_data *in_consumers, 333 333 struct regulator_bulk_data **out_consumers) 334 334 { 335 - *out_consumers = devm_kmemdup(dev, in_consumers, 336 - num_consumers * sizeof(*in_consumers), 337 - GFP_KERNEL); 335 + *out_consumers = devm_kmemdup_array(dev, in_consumers, num_consumers, 336 + sizeof(*in_consumers), GFP_KERNEL); 338 337 if (*out_consumers == NULL) 339 338 return -ENOMEM; 340 339
+1 -118
include/linux/device.h
··· 26 26 #include <linux/atomic.h> 27 27 #include <linux/uidgid.h> 28 28 #include <linux/gfp.h> 29 - #include <linux/overflow.h> 30 29 #include <linux/device/bus.h> 31 30 #include <linux/device/class.h> 31 + #include <linux/device/devres.h> 32 32 #include <linux/device/driver.h> 33 33 #include <linux/cleanup.h> 34 34 #include <asm/device.h> ··· 280 280 const struct bin_attribute *attr); 281 281 void device_remove_bin_file(struct device *dev, 282 282 const struct bin_attribute *attr); 283 - 284 - /* device resource management */ 285 - typedef void (*dr_release_t)(struct device *dev, void *res); 286 - typedef int (*dr_match_t)(struct device *dev, void *res, void *match_data); 287 - 288 - void *__devres_alloc_node(dr_release_t release, size_t size, gfp_t gfp, 289 - int nid, const char *name) __malloc; 290 - #define devres_alloc(release, size, gfp) \ 291 - __devres_alloc_node(release, size, gfp, NUMA_NO_NODE, #release) 292 - #define devres_alloc_node(release, size, gfp, nid) \ 293 - __devres_alloc_node(release, size, gfp, nid, #release) 294 - 295 - void devres_for_each_res(struct device *dev, dr_release_t release, 296 - dr_match_t match, void *match_data, 297 - void (*fn)(struct device *, void *, void *), 298 - void *data); 299 - void devres_free(void *res); 300 - void devres_add(struct device *dev, void *res); 301 - void *devres_find(struct device *dev, dr_release_t release, 302 - dr_match_t match, void *match_data); 303 - void *devres_get(struct device *dev, void *new_res, 304 - dr_match_t match, void *match_data); 305 - void *devres_remove(struct device *dev, dr_release_t release, 306 - dr_match_t match, void *match_data); 307 - int devres_destroy(struct device *dev, dr_release_t release, 308 - dr_match_t match, void *match_data); 309 - int devres_release(struct device *dev, dr_release_t release, 310 - dr_match_t match, void *match_data); 311 - 312 - /* devres group */ 313 - void * __must_check devres_open_group(struct device *dev, void *id, gfp_t gfp); 314 - void devres_close_group(struct device *dev, void *id); 315 - void devres_remove_group(struct device *dev, void *id); 316 - int devres_release_group(struct device *dev, void *id); 317 - 318 - /* managed devm_k.alloc/kfree for device drivers */ 319 - void *devm_kmalloc(struct device *dev, size_t size, gfp_t gfp) __alloc_size(2); 320 - void *devm_krealloc(struct device *dev, void *ptr, size_t size, 321 - gfp_t gfp) __must_check __realloc_size(3); 322 - __printf(3, 0) char *devm_kvasprintf(struct device *dev, gfp_t gfp, 323 - const char *fmt, va_list ap) __malloc; 324 - __printf(3, 4) char *devm_kasprintf(struct device *dev, gfp_t gfp, 325 - const char *fmt, ...) __malloc; 326 - static inline void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp) 327 - { 328 - return devm_kmalloc(dev, size, gfp | __GFP_ZERO); 329 - } 330 - static inline void *devm_kmalloc_array(struct device *dev, 331 - size_t n, size_t size, gfp_t flags) 332 - { 333 - size_t bytes; 334 - 335 - if (unlikely(check_mul_overflow(n, size, &bytes))) 336 - return NULL; 337 - 338 - return devm_kmalloc(dev, bytes, flags); 339 - } 340 - static inline void *devm_kcalloc(struct device *dev, 341 - size_t n, size_t size, gfp_t flags) 342 - { 343 - return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO); 344 - } 345 - static inline __realloc_size(3, 4) void * __must_check 346 - devm_krealloc_array(struct device *dev, void *p, size_t new_n, size_t new_size, gfp_t flags) 347 - { 348 - size_t bytes; 349 - 350 - if (unlikely(check_mul_overflow(new_n, new_size, &bytes))) 351 - return NULL; 352 - 353 - return devm_krealloc(dev, p, bytes, flags); 354 - } 355 - 356 - void devm_kfree(struct device *dev, const void *p); 357 - char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp) __malloc; 358 - const char *devm_kstrdup_const(struct device *dev, const char *s, gfp_t gfp); 359 - void *devm_kmemdup(struct device *dev, const void *src, size_t len, gfp_t gfp) 360 - __realloc_size(3); 361 - 362 - unsigned long devm_get_free_pages(struct device *dev, 363 - gfp_t gfp_mask, unsigned int order); 364 - void devm_free_pages(struct device *dev, unsigned long addr); 365 - 366 - #ifdef CONFIG_HAS_IOMEM 367 - void __iomem *devm_ioremap_resource(struct device *dev, 368 - const struct resource *res); 369 - void __iomem *devm_ioremap_resource_wc(struct device *dev, 370 - const struct resource *res); 371 - 372 - void __iomem *devm_of_iomap(struct device *dev, 373 - struct device_node *node, int index, 374 - resource_size_t *size); 375 - #else 376 - 377 - static inline 378 - void __iomem *devm_ioremap_resource(struct device *dev, 379 - const struct resource *res) 380 - { 381 - return ERR_PTR(-EINVAL); 382 - } 383 - 384 - static inline 385 - void __iomem *devm_ioremap_resource_wc(struct device *dev, 386 - const struct resource *res) 387 - { 388 - return ERR_PTR(-EINVAL); 389 - } 390 - 391 - static inline 392 - void __iomem *devm_of_iomap(struct device *dev, 393 - struct device_node *node, int index, 394 - resource_size_t *size) 395 - { 396 - return ERR_PTR(-EINVAL); 397 - } 398 - 399 - #endif 400 283 401 284 /* allows to add/remove a custom action to devres stack */ 402 285 int devm_remove_action_nowarn(struct device *dev, void (*action)(void *), void *data);
+129
include/linux/device/devres.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef _DEVICE_DEVRES_H_ 3 + #define _DEVICE_DEVRES_H_ 4 + 5 + #include <linux/err.h> 6 + #include <linux/gfp_types.h> 7 + #include <linux/numa.h> 8 + #include <linux/overflow.h> 9 + #include <linux/stdarg.h> 10 + #include <linux/types.h> 11 + 12 + struct device; 13 + struct device_node; 14 + struct resource; 15 + 16 + /* device resource management */ 17 + typedef void (*dr_release_t)(struct device *dev, void *res); 18 + typedef int (*dr_match_t)(struct device *dev, void *res, void *match_data); 19 + 20 + void * __malloc 21 + __devres_alloc_node(dr_release_t release, size_t size, gfp_t gfp, int nid, const char *name); 22 + #define devres_alloc(release, size, gfp) \ 23 + __devres_alloc_node(release, size, gfp, NUMA_NO_NODE, #release) 24 + #define devres_alloc_node(release, size, gfp, nid) \ 25 + __devres_alloc_node(release, size, gfp, nid, #release) 26 + 27 + void devres_for_each_res(struct device *dev, dr_release_t release, 28 + dr_match_t match, void *match_data, 29 + void (*fn)(struct device *, void *, void *), 30 + void *data); 31 + void devres_free(void *res); 32 + void devres_add(struct device *dev, void *res); 33 + void *devres_find(struct device *dev, dr_release_t release, dr_match_t match, void *match_data); 34 + void *devres_get(struct device *dev, void *new_res, dr_match_t match, void *match_data); 35 + void *devres_remove(struct device *dev, dr_release_t release, dr_match_t match, void *match_data); 36 + int devres_destroy(struct device *dev, dr_release_t release, dr_match_t match, void *match_data); 37 + int devres_release(struct device *dev, dr_release_t release, dr_match_t match, void *match_data); 38 + 39 + /* devres group */ 40 + void * __must_check devres_open_group(struct device *dev, void *id, gfp_t gfp); 41 + void devres_close_group(struct device *dev, void *id); 42 + void devres_remove_group(struct device *dev, void *id); 43 + int devres_release_group(struct device *dev, void *id); 44 + 45 + /* managed devm_k.alloc/kfree for device drivers */ 46 + void * __alloc_size(2) 47 + devm_kmalloc(struct device *dev, size_t size, gfp_t gfp); 48 + void * __must_check __realloc_size(3) 49 + devm_krealloc(struct device *dev, void *ptr, size_t size, gfp_t gfp); 50 + static inline void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp) 51 + { 52 + return devm_kmalloc(dev, size, gfp | __GFP_ZERO); 53 + } 54 + static inline void *devm_kmalloc_array(struct device *dev, size_t n, size_t size, gfp_t flags) 55 + { 56 + size_t bytes; 57 + 58 + if (unlikely(check_mul_overflow(n, size, &bytes))) 59 + return NULL; 60 + 61 + return devm_kmalloc(dev, bytes, flags); 62 + } 63 + static inline void *devm_kcalloc(struct device *dev, size_t n, size_t size, gfp_t flags) 64 + { 65 + return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO); 66 + } 67 + static inline __realloc_size(3, 4) void * __must_check 68 + devm_krealloc_array(struct device *dev, void *p, size_t new_n, size_t new_size, gfp_t flags) 69 + { 70 + size_t bytes; 71 + 72 + if (unlikely(check_mul_overflow(new_n, new_size, &bytes))) 73 + return NULL; 74 + 75 + return devm_krealloc(dev, p, bytes, flags); 76 + } 77 + 78 + void devm_kfree(struct device *dev, const void *p); 79 + 80 + void * __realloc_size(3) 81 + devm_kmemdup(struct device *dev, const void *src, size_t len, gfp_t gfp); 82 + static inline void *devm_kmemdup_array(struct device *dev, const void *src, 83 + size_t n, size_t size, gfp_t flags) 84 + { 85 + return devm_kmemdup(dev, src, size_mul(size, n), flags); 86 + } 87 + 88 + char * __malloc 89 + devm_kstrdup(struct device *dev, const char *s, gfp_t gfp); 90 + const char *devm_kstrdup_const(struct device *dev, const char *s, gfp_t gfp); 91 + char * __printf(3, 0) __malloc 92 + devm_kvasprintf(struct device *dev, gfp_t gfp, const char *fmt, va_list ap); 93 + char * __printf(3, 4) __malloc 94 + devm_kasprintf(struct device *dev, gfp_t gfp, const char *fmt, ...); 95 + 96 + unsigned long devm_get_free_pages(struct device *dev, gfp_t gfp_mask, unsigned int order); 97 + void devm_free_pages(struct device *dev, unsigned long addr); 98 + 99 + #ifdef CONFIG_HAS_IOMEM 100 + 101 + void __iomem *devm_ioremap_resource(struct device *dev, const struct resource *res); 102 + void __iomem *devm_ioremap_resource_wc(struct device *dev, const struct resource *res); 103 + 104 + void __iomem *devm_of_iomap(struct device *dev, struct device_node *node, int index, 105 + resource_size_t *size); 106 + #else 107 + 108 + static inline 109 + void __iomem *devm_ioremap_resource(struct device *dev, const struct resource *res) 110 + { 111 + return IOMEM_ERR_PTR(-EINVAL); 112 + } 113 + 114 + static inline 115 + void __iomem *devm_ioremap_resource_wc(struct device *dev, const struct resource *res) 116 + { 117 + return IOMEM_ERR_PTR(-EINVAL); 118 + } 119 + 120 + static inline 121 + void __iomem *devm_of_iomap(struct device *dev, struct device_node *node, int index, 122 + resource_size_t *size) 123 + { 124 + return IOMEM_ERR_PTR(-EINVAL); 125 + } 126 + 127 + #endif 128 + 129 + #endif /* _DEVICE_DEVRES_H_ */
+3
include/linux/err.h
··· 44 44 /* Return the pointer in the percpu address space. */ 45 45 #define ERR_PTR_PCPU(error) ((void __percpu *)(unsigned long)ERR_PTR(error)) 46 46 47 + /* Cast an error pointer to __iomem. */ 48 + #define IOMEM_ERR_PTR(error) (__force void __iomem *)ERR_PTR(error) 49 + 47 50 /** 48 51 * PTR_ERR - Extract the error code from an error pointer. 49 52 * @ptr: An error pointer.
-2
include/linux/io.h
··· 65 65 } 66 66 #endif 67 67 68 - #define IOMEM_ERR_PTR(err) (__force void __iomem *)ERR_PTR(err) 69 - 70 68 void __iomem *devm_ioremap(struct device *dev, resource_size_t offset, 71 69 resource_size_t size); 72 70 void __iomem *devm_ioremap_uc(struct device *dev, resource_size_t offset,