Skip to content

Commit 74c8e6b

Browse files
committed
driver core: Add __alloc_size hint to devm allocators
Mark the devm_*alloc()-family of allocations with appropriate __alloc_size()/__realloc_size() hints so the compiler can attempt to reason about buffer lengths from allocations. Cc: Greg Kroah-Hartman <[email protected]> Cc: Rasmus Villemoes <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Jason Gunthorpe <[email protected]> Cc: Nishanth Menon <[email protected]> Cc: Michael Kelley <[email protected]> Cc: Dan Williams <[email protected]> Cc: Won Chung <[email protected]> Signed-off-by: Kees Cook <[email protected]> Reviewed-by: Greg Kroah-Hartman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 8abfff2 commit 74c8e6b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

include/linux/device.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,9 @@ void devres_remove_group(struct device *dev, void *id);
197197
int devres_release_group(struct device *dev, void *id);
198198

199199
/* managed devm_k.alloc/kfree for device drivers */
200-
void *devm_kmalloc(struct device *dev, size_t size, gfp_t gfp) __malloc;
200+
void *devm_kmalloc(struct device *dev, size_t size, gfp_t gfp) __alloc_size(2);
201201
void *devm_krealloc(struct device *dev, void *ptr, size_t size,
202-
gfp_t gfp) __must_check;
202+
gfp_t gfp) __must_check __realloc_size(3);
203203
__printf(3, 0) char *devm_kvasprintf(struct device *dev, gfp_t gfp,
204204
const char *fmt, va_list ap) __malloc;
205205
__printf(3, 4) char *devm_kasprintf(struct device *dev, gfp_t gfp,
@@ -226,7 +226,8 @@ static inline void *devm_kcalloc(struct device *dev,
226226
void devm_kfree(struct device *dev, const void *p);
227227
char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp) __malloc;
228228
const char *devm_kstrdup_const(struct device *dev, const char *s, gfp_t gfp);
229-
void *devm_kmemdup(struct device *dev, const void *src, size_t len, gfp_t gfp);
229+
void *devm_kmemdup(struct device *dev, const void *src, size_t len, gfp_t gfp)
230+
__realloc_size(3);
230231

231232
unsigned long devm_get_free_pages(struct device *dev,
232233
gfp_t gfp_mask, unsigned int order);

0 commit comments

Comments
 (0)