Skip to content

Commit

Permalink
linux/modules/mmap_file: define the backward compatibility macro even…
Browse files Browse the repository at this point in the history
… when !CONFIG_DEBUG_FS

Building on Alpine 3.4 fails:

    make -C /lib/modules/4.4.68-0-grsec/build M=/shared/linux/modules modules
      CC [M]  /shared/linux/modules/mmap_file.o
    /shared/linux/modules/mmap_file.c: In function 'mmap_file_init':
    /shared/linux/modules/mmap_file.c:196:17: error: implicit declaration
    of function 'debugfs_create_file_unsafe' [-Werror=implicit-function-declaration]
      debugfs_file = debugfs_create_file_unsafe(debugname, 0644, NULL, NULL, &mmap_file_fops);
                     ^
    /shared/linux/modules/mmap_file.c:196:15: error: assignment makes
    pointer from integer without a cast [-Werror=int-conversion]
      debugfs_file = debugfs_create_file_unsafe(debugname, 0644, NULL, NULL, &mmap_file_fops);
                   ^
    cc1: all warnings being treated as errors
    scripts/Makefile.build:264: recipe for target '/shared/linux/modules/mmap_file.o' failed

Fix this by mapping map debugfs_create_file_unsafe to
debugfs_create_file on Linux<4.14 when CONFIG_DEBUG_FS is unset.
Unfortunately the versions mismatch because there was a bug fixed by
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c2a737eb2ea5682ffe63bc08003965496d6dc088

Fixes: 4c3ea5c ("linux/modules/mmap_file: invert the macro defining
debugfs_create_file for Linux 6.13 compatibility")
  • Loading branch information
fishilico committed Feb 9, 2025
1 parent 66f942f commit b1c15d6
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion linux/modules/mmap_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ static const struct file_operations mmap_file_fops = {

static int __init mmap_file_init(void)
{
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 7, 0) && defined(CONFIG_DEBUG_FS)
#if LINUX_VERSION_CODE < (IS_ENABLED(CONFIG_DEBUG_FS) ? KERNEL_VERSION(4, 7, 0) : KERNEL_VERSION(4, 14, 0))
/* Commit 149d200deaa68 ("debugfs: prevent access to removed files'
* private data") introduced a file operation proxy which does not
* support mmap(). Using an "unsafe" debugfs file is needed to make
Expand All @@ -186,6 +186,9 @@ static int __init mmap_file_init(void)
* just define debugfs_create_file to debugfs_create_file_unsafe, since
* Linux 6.13. Instead, define a macro the other way round, to ensure
* maximum compatibility.
* Unfortunately, the dummy implementation of debugfs_create_file_unsafe
* when CONFIG_DEBUG_FS is unset was introduced later, in Linux 4.14, by
* commit c2a737eb2ea5 ("debugfs: Add dummy implementation of few helpers").
*/
#define debugfs_create_file_unsafe debugfs_create_file
#endif
Expand Down

0 comments on commit b1c15d6

Please sign in to comment.