git: 0b1244bd79c2 - main - LinuxKPI: Move kfree_async() functionality in to kfree()

From: Vladimir Kondratyev <wulf_at_FreeBSD.org>
Date: Mon, 10 Jan 2022 19:50:43 UTC
The branch main has been updated by wulf:

URL: https://cgit.FreeBSD.org/src/commit/?id=0b1244bd79c2c4da25278a2e25a2471d9edd9408

commit 0b1244bd79c2c4da25278a2e25a2471d9edd9408
Author:     Vladimir Kondratyev <wulf@FreeBSD.org>
AuthorDate: 2021-11-15 13:53:02 +0000
Commit:     Vladimir Kondratyev <wulf@FreeBSD.org>
CommitDate: 2022-01-10 19:49:37 +0000

    LinuxKPI: Move kfree_async() functionality in to kfree()
    
    Obsolete it usage but keep for a while for drm-kmod 5.4 compatibility
    
    MFC after:      1 week
    Reviewed by:    hselasky, manu
    Differential Revision:  https://reviews.freebsd.org/D33298
---
 sys/compat/linuxkpi/common/include/linux/slab.h | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/sys/compat/linuxkpi/common/include/linux/slab.h b/sys/compat/linuxkpi/common/include/linux/slab.h
index 56bb08c185e2..b8fe3a48bd3c 100644
--- a/sys/compat/linuxkpi/common/include/linux/slab.h
+++ b/sys/compat/linuxkpi/common/include/linux/slab.h
@@ -86,18 +86,8 @@ struct linux_kmem_cache;
 #define	ARCH_KMALLOC_MINALIGN \
 	__alignof(unsigned long long)
 
-/*
- * Critical section-friendly version of kfree().
- * Requires knowledge of the allocation size at build time.
- */
-#define kfree_async(ptr)	do {					\
-	_Static_assert(sizeof(*(ptr)) >= sizeof(struct llist_node),	\
-	    "Size of object to free is unknown or too small");		\
-	if (curthread->td_critnest != 0)				\
-		linux_kfree_async(ptr);					\
-	else								\
-		kfree(ptr);						\
-} while (0)
+/* drm-kmod 5.4 compat */
+#define kfree_async(ptr)	kfree(ptr);
 
 static inline gfp_t
 linux_check_m_flags(gfp_t flags)
@@ -117,7 +107,8 @@ linux_check_m_flags(gfp_t flags)
 static inline void *
 kmalloc(size_t size, gfp_t flags)
 {
-	return (malloc(size, M_KMALLOC, linux_check_m_flags(flags)));
+	return (malloc(MAX(size, sizeof(struct llist_node)), M_KMALLOC,
+	    linux_check_m_flags(flags)));
 }
 
 static inline void *
@@ -186,10 +177,15 @@ krealloc(void *ptr, size_t size, gfp_t flags)
 	return (realloc(ptr, size, M_KMALLOC, linux_check_m_flags(flags)));
 }
 
+extern void linux_kfree_async(void *);
+
 static inline void
 kfree(const void *ptr)
 {
-	free(__DECONST(void *, ptr), M_KMALLOC);
+	if (curthread->td_critnest != 0)
+		linux_kfree_async(__DECONST(void *, ptr));
+	else
+		free(__DECONST(void *, ptr), M_KMALLOC);
 }
 
 static __inline void
@@ -210,6 +206,5 @@ extern void *lkpi_kmem_cache_alloc(struct linux_kmem_cache *, gfp_t);
 extern void *lkpi_kmem_cache_zalloc(struct linux_kmem_cache *, gfp_t);
 extern void lkpi_kmem_cache_free(struct linux_kmem_cache *, void *);
 extern void linux_kmem_cache_destroy(struct linux_kmem_cache *);
-void linux_kfree_async(void *);
 
 #endif					/* _LINUX_SLAB_H_ */