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
This commit is contained in:
Jean-Sébastien Pédron 2023-02-20 21:50:29 +01:00
parent eef905a859
commit 1b4e08b483
No known key found for this signature in database
GPG Key ID: 39E99761A5FD94CC

View File

@ -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);
}