Skip to content

Commit a67d74a

Browse files
committed
mm/slab: Add __free() support for kvfree
Allow for the declaration of variables that trigger kvfree() when they go out of scope. The check for NULL and call to kvfree() can be elided by the compiler in most cases, otherwise without the NULL check an unnecessary call to kvfree() may be emitted. Peter proposed a comment for this detail [1]. Link: http://lore.kernel.org/r/20230816103102.GF980931@hirez.programming.kicks-ass.net [1] Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Acked-by: Pankaj Gupta <pankaj.gupta@amd.com> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com> Tested-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com> Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 2df2135 commit a67d74a

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

include/linux/slab.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,8 @@ static inline __alloc_size(1, 2) void *kvcalloc(size_t n, size_t size, gfp_t fla
763763
extern void *kvrealloc(const void *p, size_t oldsize, size_t newsize, gfp_t flags)
764764
__realloc_size(3);
765765
extern void kvfree(const void *addr);
766+
DEFINE_FREE(kvfree, void *, if (_T) kvfree(_T))
767+
766768
extern void kvfree_sensitive(const void *addr, size_t len);
767769

768770
unsigned int kmem_cache_size(struct kmem_cache *s);

0 commit comments

Comments
 (0)