Skip to content

Commit 39e9290

Browse files
Bjoern A. ZeebBjoern A. Zeeb
authored andcommitted
LinuxKPI: cleanup: implement __free() and DEFINE_FREE(); use for kfree()
A wifi driver update needs this. Sponsored by: The FreeBSD Foundation (initially) MFC after: 3 days Reviewed by: dumbbell Differential Revision: https://reviews.freebsd.org/D52075
1 parent 5cb64a1 commit 39e9290

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

sys/compat/linuxkpi/common/include/linux/cleanup.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*-
22
* SPDX-License-Identifier: BSD-2-Clause
33
*
4-
* Copyright (c) 2024 The FreeBSD Foundation
4+
* Copyright (c) 2024-2025 The FreeBSD Foundation
55
*
66
* This software was developed by Björn Zeeb under sponsorship from
77
* the FreeBSD Foundation.
@@ -43,4 +43,16 @@
4343
guard_ ## _n ## _t guard_ ## _n ## _ ## __COUNTER__ \
4444
__cleanup(guard_ ## _n ## _destroy) = guard_ ## _n ## _create
4545

46+
#define DEFINE_FREE(_n, _t, _f) \
47+
static inline void \
48+
__free_ ## _n(void *p) \
49+
{ \
50+
_t _T; \
51+
\
52+
_T = *(_t *)p; \
53+
_f; \
54+
}
55+
56+
#define __free(_n) __cleanup(__free_##_n)
57+
4658
#endif /* _LINUXKPI_LINUX_CLEANUP_H */

sys/compat/linuxkpi/common/include/linux/slab.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@
4040
#include <linux/compat.h>
4141
#include <linux/types.h>
4242
#include <linux/gfp.h>
43+
#include <linux/err.h>
4344
#include <linux/llist.h>
4445
#include <linux/overflow.h>
46+
#include <linux/cleanup.h>
4547

4648
MALLOC_DECLARE(M_KMALLOC);
4749

@@ -153,6 +155,8 @@ kfree(const void *ptr)
153155
lkpi_kfree(ptr);
154156
}
155157

158+
DEFINE_FREE(kfree, void *, if (!IS_ERR_OR_NULL(_T)) kfree(_T))
159+
156160
/*
157161
* Other k*alloc() funtions using the above as underlying allocator.
158162
*/

0 commit comments

Comments
 (0)