[PATCH 4/5] mm/vmalloc: add DEFINE_FREE() for vfree()

From: Mike Rapoport (Microsoft)

Date: Thu Sep 03 2026 - 13:19:35 EST


... and use it in hid-core, the only place with a cleanup for a
vmalloc() allocation.

Signed-off-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>
---
drivers/hid/hid-core.c | 4 ++--
include/linux/vmalloc.h | 3 +++
2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index a3ff0514f9cdf..ec7c2860c93ef 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -944,7 +944,7 @@ static int hid_scan_report(struct hid_device *hid)
hid_parser_reserved
};

- struct hid_parser *parser __free(kvfree) = vzalloc(sizeof(*parser));
+ struct hid_parser *parser __free(vfree) = vzalloc(sizeof(*parser));
if (!parser)
return -ENOMEM;

@@ -1265,7 +1265,7 @@ static int hid_parse_collections(struct hid_device *device)
hid_parser_reserved
};

- struct hid_parser *parser __free(kvfree) = vzalloc(sizeof(*parser));
+ struct hid_parser *parser __free(vfree) = vzalloc(sizeof(*parser));
if (!parser)
return -ENOMEM;

diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
index 6e555e31e6225..034a693777ca0 100644
--- a/include/linux/vmalloc.h
+++ b/include/linux/vmalloc.h
@@ -3,6 +3,7 @@
#define _LINUX_VMALLOC_H

#include <linux/alloc_tag.h>
+#include <linux/cleanup.h>
#include <linux/sched.h>
#include <linux/spinlock.h>
#include <linux/init.h>
@@ -215,6 +216,8 @@ void *__must_check vrealloc_node_align_noprof(const void *p, size_t size,
extern void vfree(const void *addr);
extern void vfree_atomic(const void *addr);

+DEFINE_FREE(vfree, void *, if (!IS_ERR_OR_NULL(_T)) vfree(_T))
+
extern void *vmap(struct page **pages, unsigned int count,
unsigned long flags, pgprot_t prot);
void *vmap_pfn(unsigned long *pfns, unsigned int count, pgprot_t prot);

--
2.53.0