]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
e2fsck: double cast a pointer to suppress a bogus compiler warning in kfree()
authorTheodore Ts'o <tytso@mit.edu>
Fri, 27 Jan 2023 20:35:12 +0000 (15:35 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 27 Jan 2023 20:46:45 +0000 (15:46 -0500)
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 <tytso@mit.edu>
e2fsck/jfs_user.h

index 1167c80d3df917351b0cf6e0eeadb124ea9b3820..5928a8a8eda3659274d0fc7d0a9c52110533df7f 100644 (file)
@@ -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 */