linux-3.4.10 _pci_assign_resource函数bug

linux-3.4.10 _pci_assign_resource函数bug
<linux-3.4.10/drivers/pci/setup-res.c>
int pci_reassign_resource(struct pci_dev *dev, int resno, resource_size_t addsize,resource_size_t min_align)
{
        //omitted
        /* already aligned with min_align */
        new_size = resource_size(res) + addsize;
        ret = _pci_assign_resource(dev, resno, new_size, min_align);
        if (!ret) {
                res->flags &= ~IORESOURCE_STARTALIGN;
                dev_info(&dev->dev, "BAR %d: reassigned %pR\n", resno, res);
                if (resno < PCI_BRIDGE_RESOURCES)
                        pci_update_resource(dev, resno);
        }
        return ret;
}
 
static int _pci_assign_resource(struct pci_dev *dev, int resno, int size, resource_size_t min_align)
{
    //………
    bus = dev->bus;
    while ((ret = __pci_assign_resource(bus, dev, resno, size, min_align))) {
           if (!bus->parent || !bus->self->transparent)
                    break;
           bus = bus->parent;
    }
    // ……...
}
 
static int __pci_assign_resource(struct pci_bus *bus, struct pci_dev *dev,int resno, resource_size_t size, resource_size_t align)
从以上的函数调用关系可知
pci_reassign_resource()-->_pci_assign_resource()-->__pci_assign_resource()
函数的定义里size定义的类型不一致,这样在64位操作系统里,会引起符号扩展的错误,因为当resource_size_t为64位无符号数时,而int定义为32位的有符号数,如果int定义的数最高位为1,这样再把int值赋值回u64的值就会引起符号扩展导致size错误。
<linux-3.4.10/include/linux/types.h>
 
#ifdef CONFIG_PHYS_ADDR_T_64BIT
typedef u64 phys_addr_t;
#else  
typedef u32 phys_addr_t;
#endif
typedef phys_addr_t resource_size_t;
 
例如:在X86_64机器内核版本Linux ubuntu 2.6.32-30-server #59-Ubuntu SMP
测试程序<test.c>
#include <stdio.h>
int main()
{
        unsigned long a=0xe0000000;
        int b=a;
        unsigned long c=b;
        printf("a=%#lx, b=%#x, c=%#lx\n", a, b, c);
        return 0;
}
swq@ubuntu:~$ gcc test.c
swq@ubuntu:~$ ./a.out
a=0xe0000000, b=0xe0000000, c=0xffffffffe0000000
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值