Linux: Implicit function declaration error even though function is present

Viewed 42

I am trying to call a custom function from the linux/fs/ext2/file.c file as follows:

printk(KERN_ALERT "Count: %i\n", getValue());

I have added the declaration and definition of the getValue() function at the top of file.c

static int getValue(void);

static int getValue(void) {
        return 123;
}

However, my printk call is giving the following when compiling:

fs/ext2/file.c: In function ‘ext2_fsync’:
fs/ext2/file.c:162:52: error: implicit declaration of function ‘getValue’ [-Werror=implicit-function-declaration]
  162 |         printk(KERN_ALERT "Count: %i\n", getValue());
      |                                          ^~~~~~~~~~~~~~~
./include/linux/printk.h:436:33: note: in definition of macro ‘printk_index_wrap’
  436 |                 _p_func(_fmt, ##__VA_ARGS__);                           \
      |                                 ^~~~~~~~~~~
fs/ext2/file.c:162:9: note: in expansion of macro ‘printk’
  162 |         printk(KERN_ALERT "Count: %i\n", getValue());
      |         ^~~~~~
cc1: some warnings being treated as errors
make[2]: *** [scripts/Makefile.build:249: fs/ext2/file.o] Error 1
make[1]: *** [scripts/Makefile.build:466: fs/ext2] Error 2
make: *** [Makefile:1846: fs] Error 2

I am able to run this code separately but when building the kernel, I get the error mentioned above. How would I fix this?

0 Answers
Related