aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorJean-Sébastien Pédron <dumbbell@FreeBSD.org>2023-02-20 20:50:29 +0000
committerJean-Sébastien Pédron <dumbbell@FreeBSD.org>2023-03-20 20:47:36 +0000
commit1b4e08b4832deeea4b9121cdaed4f6700bdab03f (patch)
tree23f3d80c1d5fc8907ba4eab6aac83252bbedaaf0 /sys
parenteef905a85907102bc00b76b5b135c24cabe0456a (diff)
downloadsrc-1b4e08b4832deeea4b9121cdaed4f6700bdab03f.tar.gz
src-1b4e08b4832deeea4b9121cdaed4f6700bdab03f.zip
linuxkpi: Support non-NULL zero-size pointers
DRM drivers set some pointers to `ZERO_SIZE_PTR` directly (without allocating anything), to treat pointers which were "initialized" (set to `ZERO_SIZE_PTR`) with no memory allocation like really allocated pointers. NULL isn't used because it represents a third state. Reviewed by: emaste, manu Approved by: emaste, manu Differential Revision: https://reviews.freebsd.org/D39055
Diffstat (limited to 'sys')
-rw-r--r--sys/compat/linuxkpi/common/include/linux/slab.h9
1 files changed, 8 insertions, 1 deletions
diff --git a/sys/compat/linuxkpi/common/include/linux/slab.h b/sys/compat/linuxkpi/common/include/linux/slab.h
index 915f33acf67e..a2cce4cfe75a 100644
--- a/sys/compat/linuxkpi/common/include/linux/slab.h
+++ b/sys/compat/linuxkpi/common/include/linux/slab.h
@@ -90,7 +90,8 @@ struct linux_kmem_cache;
/* drm-kmod 5.4 compat */
#define kfree_async(ptr) kfree(ptr);
-#define ZERO_OR_NULL_PTR(x) ((x) == NULL)
+#define ZERO_SIZE_PTR ((void *)16)
+#define ZERO_OR_NULL_PTR(x) ((x) == NULL || (x) == ZERO_SIZE_PTR)
static inline gfp_t
linux_check_m_flags(gfp_t flags)
@@ -195,6 +196,9 @@ extern void linux_kfree_async(void *);
static inline void
kfree(const void *ptr)
{
+ if (ZERO_OR_NULL_PTR(ptr))
+ return;
+
if (curthread->td_critnest != 0)
linux_kfree_async(__DECONST(void *, ptr));
else
@@ -204,6 +208,9 @@ kfree(const void *ptr)
static __inline void
kfree_sensitive(const void *ptr)
{
+ if (ZERO_OR_NULL_PTR(ptr))
+ return;
+
zfree(__DECONST(void *, ptr), M_KMALLOC);
}