内核 platform_get_resource() 函数解析

struct resource *platform_get_resource(struct platform_device *dev,            unsigned int type, unsigned int num)

{  int i;

    for (i = 0; i < dev->num_resources; i++)

    {   struct resource *r = &dev->resource[i];

         if (type == resource_type(r) && num-- == 0)   

         return r;  

    }

    return NULL;

}

summary point: 1. 从该函数的定义可以看出 num 参数是同一种类型资源下的资源索引,因为 if (type == resource_type(r) && num-- == 0) 这条判断语句的执行是先执行 && 前面的类型判断,然后才执行索引判断。

原文地址:https://www.cnblogs.com/youngvoice/p/5434357.html