为什么`resource_size_t`类型无法识别`%pa` printk格式说明符?

时间:2014-10-23 15:11:22

标签: linux linux-device-driver

编译模块时,我收到此警告:

# 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.

我可以投了它,但想知道为什么格式说明符不被接受。

1 个答案:

答案 0 :(得分:3)

从您指出的文档中:

  

用于打印phys_addr_t类型(及其派生类,例如resource_size_t),它可以根据构建选项而变化,而不管CPU数据路径的宽度如何。 通过引用传递。

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