编译模块时,出现以下警告:

# make modules
  CC [M]  /jriskhome/repos/module/my_module.o
/jriskhome/repos/module/my_module.c: In function ‘_pci_probe’:
/jriskhome/repos/module/my_module.c:882:3: warning: format ‘%p’ expects argument of type ‘void *’, but argument 7 has type ‘resource_size_t’ [-Wformat=]
   pr_info("Mapped Bar   %d: %p -> %pa (%pa)", bar_number, BAR, pci_resource_start(dev, bar_number), pci_resource_len(dev, bar_number));
   ^
/jriskhome/repos/module/my_module.c:882:3: warning: format ‘%p’ expects argument of type ‘void *’, but argument 8 has type ‘resource_size_t’ [-Wformat=]

我咨询了这个:http://lxr.free-electrons.com/source/Documentation/printk-formats.txt?v=3.10
在我看来,这很对。内核和编译器版本为:
# uname -r
3.10.0-123.8.1.el7.x86_64
#  gcc --version
gcc (GCC) 4.8.2 20140120 (Red Hat 4.8.2-16)
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

我可以进行转换,但是想知道为什么不接受格式说明符。

最佳答案

您从文档中指出:



您需要传递一个指向您的值的指针,而不是值本身。我认为,为了实现上述与当前构建选项的独立性,这种扭曲是完全必要的。

关于linux - 为什么 `%pa`类型无法识别 `resource_size_t` printk格式说明符?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26531316/

10-13 22:38