From d6ed24794e408a51cee2429841cc452323da4af8 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Fri, 27 Jan 2023 15:35:12 -0500 Subject: [PATCH] e2fsck: double cast a pointer to suppress a bogus compiler warning in kfree() The C standard is wrong[1] with respect to the function signature of free(), while the kernel's kfree() is correct. Unfortunately, this leads to compiler warnings. Sayeth Dennis Ritchie: "Noalias must go. This is non-negotiable"[2]. Noalias went. The confusion around const, alas, still remains. [1] https://yarchive.net/comp/const.html [2] https://www.lysator.liu.se/c/dmr-on-noalias.html Signed-off-by: Theodore Ts'o --- e2fsck/jfs_user.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/e2fsck/jfs_user.h b/e2fsck/jfs_user.h index 1167c80..5928a8a 100644 --- a/e2fsck/jfs_user.h +++ b/e2fsck/jfs_user.h @@ -179,7 +179,17 @@ _INLINE_ void *kmalloc(size_t size, gfp_t flags EXT2FS_ATTR((unused))) _INLINE_ void kfree(const void *objp) { +#ifdef HAVE_INTPTR_T + /* + * Work around a botch in the C standard, which triggers + * compiler warnings. For better or for worse, the kernel + * uses const void * for kfree, while the C standard mandates + * the use of void *. See: https://yarchive.net/comp/const.html + */ + free((void *)(intptr_t)objp); +#else free((void *)objp); +#endif } /* generic hashing taken from the Linux kernel */ -- 1.8.3.1