Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 5 Sep 2025 23:29:04 GMT
From:      "Bjoern A. Zeeb" <bz@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 39e9290d890b - main - LinuxKPI: cleanup: implement __free() and DEFINE_FREE(); use for kfree()
Message-ID:  <202509052329.585NT42u029365@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by bz:

URL: https://cgit.FreeBSD.org/src/commit/?id=39e9290d890b2aa07b68f2fe956b96e5df9a1da2

commit 39e9290d890b2aa07b68f2fe956b96e5df9a1da2
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2025-09-04 20:24:55 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2025-09-05 23:24:15 +0000

    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
---
 sys/compat/linuxkpi/common/include/linux/cleanup.h | 14 +++++++++++++-
 sys/compat/linuxkpi/common/include/linux/slab.h    |  4 ++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/sys/compat/linuxkpi/common/include/linux/cleanup.h b/sys/compat/linuxkpi/common/include/linux/cleanup.h
index 01f234f0cbe7..45c2a2359ddf 100644
--- a/sys/compat/linuxkpi/common/include/linux/cleanup.h
+++ b/sys/compat/linuxkpi/common/include/linux/cleanup.h
@@ -1,7 +1,7 @@
 /*-
  * SPDX-License-Identifier: BSD-2-Clause
  *
- * Copyright (c) 2024 The FreeBSD Foundation
+ * Copyright (c) 2024-2025 The FreeBSD Foundation
  *
  * This software was developed by Björn Zeeb under sponsorship from
  * the FreeBSD Foundation.
@@ -43,4 +43,16 @@
     guard_ ## _n ## _t guard_ ## _n ## _ ## __COUNTER__			\
 	__cleanup(guard_ ## _n ## _destroy) = guard_ ## _n ## _create
 
+#define	DEFINE_FREE(_n, _t, _f)						\
+    static inline void							\
+    __free_ ## _n(void *p)						\
+    {									\
+	_t _T;								\
+									\
+	_T = *(_t *)p;							\
+	_f;								\
+    }
+
+#define	__free(_n)		__cleanup(__free_##_n)
+
 #endif	/* _LINUXKPI_LINUX_CLEANUP_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/slab.h b/sys/compat/linuxkpi/common/include/linux/slab.h
index 47e3d133eb6c..0e649e1e3c4a 100644
--- a/sys/compat/linuxkpi/common/include/linux/slab.h
+++ b/sys/compat/linuxkpi/common/include/linux/slab.h
@@ -40,8 +40,10 @@
 #include <linux/compat.h>
 #include <linux/types.h>
 #include <linux/gfp.h>
+#include <linux/err.h>
 #include <linux/llist.h>
 #include <linux/overflow.h>
+#include <linux/cleanup.h>
 
 MALLOC_DECLARE(M_KMALLOC);
 
@@ -153,6 +155,8 @@ kfree(const void *ptr)
 	lkpi_kfree(ptr);
 }
 
+DEFINE_FREE(kfree, void *, if (!IS_ERR_OR_NULL(_T)) kfree(_T))
+
 /*
  * Other k*alloc() funtions using the above as underlying allocator.
  */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202509052329.585NT42u029365>