git: 1b4e08b4832d - main - linuxkpi: Support non-NULL zero-size pointers
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 20 Mar 2023 20:47:50 UTC
The branch main has been updated by dumbbell: URL: https://cgit.FreeBSD.org/src/commit/?id=1b4e08b4832deeea4b9121cdaed4f6700bdab03f commit 1b4e08b4832deeea4b9121cdaed4f6700bdab03f Author: Jean-Sébastien Pédron <dumbbell@FreeBSD.org> AuthorDate: 2023-02-20 20:50:29 +0000 Commit: Jean-Sébastien Pédron <dumbbell@FreeBSD.org> CommitDate: 2023-03-20 20:47:36 +0000 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 --- sys/compat/linuxkpi/common/include/linux/slab.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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); }