繁体   English   中英

printk的Linux内核模块错误:格式参数过多

[英]Linux kernel module error for printk: too many arguments for format

我已经在/home/coder/workspace/test_module目录中创建了hello.cMakefile 我正在使用Arch Linux。 我已经安装了linux-headers

你好ç

#include <linux/init.h>
#include <linux/module.h>


static int hello_init(void){
    printk(KERN_ALERT, "hello, this is hello module");

    return 0;
}

static void hello_exit(void){
    printk(KERN_ALERT, "exiting the hello module");
}

module_init(hello_init);
module_exit(hello_exit);

生成文件

obj-m=hello.o

KDIR = /usr/lib/modules/$(shell uname -r)/build

all :
        make -C $(KDIR) M=$(PWD) modules


clean :
        rm -rf *.o *.ko *.mod.* *.symvers *.order

错误

[coder@coder test_module]$ make
make -C /usr/lib/modules/4.10.13-1-ARCH/build M=/home/coder/workspace/test_module modules
make[1]: Entering directory '/usr/lib/modules/4.10.13-1-ARCH/build'
  CC [M]  /home/coder/workspace/test_module/hello.o
In file included from ./include/linux/printk.h:6:0,
                 from ./include/linux/kernel.h:13,
                 from ./include/linux/list.h:8,
                 from ./include/linux/module.h:9,
                 from /home/coder/workspace/test_module/hello.c:2:
/home/coder/workspace/test_module/hello.c: In function 'hello_init':
./include/linux/kern_levels.h:4:18: warning: too many arguments for format [-Wformat-extra-args]
 #define KERN_SOH "\001"  /* ASCII Start Of Header */
                  ^
./include/linux/kern_levels.h:8:20: note: in expansion of macro 'KERN_SOH'
 #define KERN_ALERT KERN_SOH "1" /* action must be taken immediately */
                    ^~~~~~~~
/home/coder/workspace/test_module/hello.c:6:9: note: in expansion of macro 'KERN_ALERT'
  printk(KERN_ALERT, "hello, this is hello module");
         ^~~~~~~~~~
/home/coder/workspace/test_module/hello.c: In function 'hello_exit':
./include/linux/kern_levels.h:4:18: warning: too many arguments for format [-Wformat-extra-args]
 #define KERN_SOH "\001"  /* ASCII Start Of Header */
                  ^
./include/linux/kern_levels.h:8:20: note: in expansion of macro 'KERN_SOH'
 #define KERN_ALERT KERN_SOH "1" /* action must be taken immediately */
                    ^~~~~~~~
/home/coder/workspace/test_module/hello.c:12:9: note: in expansion of macro 'KERN_ALERT'
  printk(KERN_ALERT, "exiting the hello module");
         ^~~~~~~~~~
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /home/coder/workspace/test_module/hello.mod.o
  LD [M]  /home/coder/workspace/test_module/hello.ko
make[1]: Leaving directory '/usr/lib/modules/4.10.13-1-ARCH/build'

更多细节

$ uname -r
4.10.13-1-ARCH

$ ls -l /usr/lib/modules/$(uname -r)/build
drwxr-xr-x   4 root root     4096 Apr 27 15:47 Documentation
-rw-r--r--   1 root root      252 Apr 27 15:47 Kconfig
-rw-r--r--   1 root root    59062 Apr 27 15:47 Makefile
-rw-r--r--   1 root root  1321690 Apr 27 15:47 Module.symvers
drwxr-xr-x   4 root root     4096 Apr 27 15:47 arch
drwxr-xr-x   3 root root     4096 Apr 27 15:47 block
drwxr-xr-x   2 root root     4096 Apr 27 15:47 certs
drwxr-xr-x   4 root root     4096 Apr 27 15:47 crypto
drwxr-xr-x 123 root root     4096 Apr 27 15:47 drivers
drwxr-xr-x  64 root root     4096 Apr 27 15:47 fs
drwxr-xr-x  21 root root     4096 Apr 27 15:47 include
drwxr-xr-x   2 root root     4096 Apr 27 15:47 init
drwxr-xr-x   8 root root     4096 Apr 27 15:47 kernel
drwxr-xr-x   4 root root     4096 Apr 27 15:47 lib
drwxr-xr-x   2 root root     4096 Apr 27 15:47 mm
drwxr-xr-x  58 root root     4096 Apr 27 15:47 net
drwxr-xr-x   2 root root     4096 Apr 27 15:47 samples
drwxr-xr-x  14 root root     4096 Apr 27 15:47 scripts
drwxr-xr-x  10 root root     4096 Apr 27 15:47 security
drwxr-xr-x  21 root root     4096 Apr 27 15:47 sound
drwxr-xr-x   3 root root     4096 Apr 27 15:47 tools
drwxr-xr-x   2 root root     4096 Apr 27 15:47 usr
drwxr-xr-x   4 root root     4096 Apr 27 15:47 virt
-rw-r--r--   1 root root 20557744 Apr 27 15:46 vmlinux

我在这里做错了什么?

Loglevel不是printk()的单独参数,它是消息的前缀。 在您的情况下:

printk(KERN_ALERT "hello, this is hello module");

更多信息: https//en.wikipedia.org/wiki/Printk

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM