gpt4 book ai didi

linux - 为什么 `%pa` printk 格式说明符不能被 `resource_size_t` 类型识别?

转载 作者:太空狗 更新时间:2023-10-29 12:03:22 27 4
gpt4 key购买 nike

当编译我的模块时,我收到这个警告:

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

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

最佳答案

根据您指向的文档:

For printing a phys_addr_t type (and its derivatives, such as resource_size_t) which can vary based on build options, regardless of the width of the CPU data path. Passed by reference.

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

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

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com