diff options
-rw-r--r-- | drivers/of/platform.c | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/drivers/of/platform.c b/drivers/of/platform.c index ea87a3cf7860..5cc9a8e91be5 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c | |||
@@ -475,10 +475,35 @@ struct of_device *of_device_alloc(struct device_node *np, | |||
475 | struct device *parent) | 475 | struct device *parent) |
476 | { | 476 | { |
477 | struct of_device *dev; | 477 | struct of_device *dev; |
478 | 478 | int rc, i, num_reg = 0, num_irq = 0; | |
479 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); | 479 | struct resource *res, temp_res; |
480 | |||
481 | /* First count how many resources are needed */ | ||
482 | while (of_address_to_resource(np, num_reg, &temp_res) == 0) | ||
483 | num_reg++; | ||
484 | while (of_irq_to_resource(np, num_irq, &temp_res) != NO_IRQ) | ||
485 | num_irq++; | ||
486 | |||
487 | /* Allocate memory for both the struct device and the resource table */ | ||
488 | dev = kzalloc(sizeof(*dev) + (sizeof(*res) * (num_reg + num_irq)), | ||
489 | GFP_KERNEL); | ||
480 | if (!dev) | 490 | if (!dev) |
481 | return NULL; | 491 | return NULL; |
492 | res = (struct resource *) &dev[1]; | ||
493 | |||
494 | /* Populate the resource table */ | ||
495 | if (num_irq || num_reg) { | ||
496 | dev->num_resources = num_reg + num_irq; | ||
497 | dev->resource = res; | ||
498 | for (i = 0; i < num_reg; i++, res++) { | ||
499 | rc = of_address_to_resource(np, i, res); | ||
500 | WARN_ON(rc); | ||
501 | } | ||
502 | for (i = 0; i < num_irq; i++, res++) { | ||
503 | rc = of_irq_to_resource(np, i, res); | ||
504 | WARN_ON(rc == NO_IRQ); | ||
505 | } | ||
506 | } | ||
482 | 507 | ||
483 | dev->dev.of_node = of_node_get(np); | 508 | dev->dev.of_node = of_node_get(np); |
484 | dev->dev.dma_mask = &dev->archdata.dma_mask; | 509 | dev->dev.dma_mask = &dev->archdata.dma_mask; |