mm/vmalloc: add DEFINE_FREE() for vfree()

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

Link: https://lore.kernel.org/20260903-execmem-rox-cache-pmd-v1-v1-4-11beb2a3d249@kernel.org
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Benjamin Tissoires <bentiss@kernel.org>
Cc: Jiri Kosina <jikos@kernel.org>
Cc: Luis Chamberalin <mcgrof@kernel.org>
Cc: "Uladzislau Rezki (Sony)" <urezki@gmail.com>
This commit is contained in:
Mike Rapoport (Microsoft) 2026-09-03 18:50:01 +03:00 committed by Andrew Morton
parent 569db54d8b
commit 254e7a129e
2 changed files with 5 additions and 2 deletions

View File

@ -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;

View File

@ -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);