Doubt regarding platform_get_resource

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have a doubt regarding platform_get_resource function.

I have defined my platform device as:

static struct resource my_resources[] = {

	[0] = {

		.flags	= IORESOURCE_IRQ,

	},

	[1] = {

		.flags	= IORESOURCE_IO,

	},

};



static struct platform_device platform_dev = {

	.id			= -1,

	.dev = {

		.release       = release_platform_dev,

	},

	.resource		= my_resources,

	.num_resources		= ARRAY_SIZE(my_resources),

};



Now, I am trying to access my respurces using platform_get_resource as follows:

resource_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);

resource_ioport = platform_get_resource(pdev, IORESOURCE_IO, 1);

The resource "IORESOURCE_IRQ" stored at index "0" is successfully
retrieved. However, on accessing IORESOURCE_IO stored at index '1',
platform_get_resource function is returing NULL instead of resource
IORESOURCE_IO.

Consider the platform_get_resource definition:

--- snip (drivers/base/platform.c) ----
/**
 * platform_get_resource - get a resource for a device
 * @dev: platform device
 * @type: resource type
 * @num: resource index
 */
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;
}

--- snip ----

As per my understanding. "num" should be the index at which the
resource is stored and thus for reterieving that resource we need to
pass the same index. If this is true, then the platform_get_resource
should return the correct resource on passing index as '1' for
IORESOURCE_IO but it is returning NULL.

On analyzing I observed the following:

Here, within "for" loop, we are matching resource_type(r) with "type"
and 'num' with '0'. We are also post decrementing the num by '1'.
Since we have used "&&" operator the second condition would not be
evaluated if the first condition is false i.e. num wil not be
decremented by '1'.

This is what happing in my case, when I am passing index '1' for
accessing IORESOURCE_IO. In the first iteration of loop, the first
condition evaluates FALSE and hence second condition is not evaluated
i.e. "num" is not decrementing by '1'.

Now, in second iteration of loop, though the first condition evaluates
"TRUE", the second iteration evaluates false since the num was still
'1' instead of '0' and hence returning NULL.

Please verify my understanding and correct me If I am doing anything wrong.

Thanks and Regards,
Meetu
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux