diff options
Diffstat (limited to 'drivers/of/platform.c')
-rw-r--r-- | drivers/of/platform.c | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/drivers/of/platform.c b/drivers/of/platform.c index bb72223c22ae..5b4a07f1220e 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c | |||
@@ -584,34 +584,33 @@ struct platform_device *of_device_alloc(struct device_node *np, | |||
584 | struct device *parent) | 584 | struct device *parent) |
585 | { | 585 | { |
586 | struct platform_device *dev; | 586 | struct platform_device *dev; |
587 | int rc, i, num_reg = 0, num_irq = 0; | 587 | int rc, i, num_reg = 0, num_irq; |
588 | struct resource *res, temp_res; | 588 | struct resource *res, temp_res; |
589 | 589 | ||
590 | /* First count how many resources are needed */ | 590 | dev = platform_device_alloc("", -1); |
591 | while (of_address_to_resource(np, num_reg, &temp_res) == 0) | ||
592 | num_reg++; | ||
593 | while (of_irq_to_resource(np, num_irq, &temp_res) != NO_IRQ) | ||
594 | num_irq++; | ||
595 | |||
596 | /* Allocate memory for both the struct device and the resource table */ | ||
597 | dev = kzalloc(sizeof(*dev) + (sizeof(*res) * (num_reg + num_irq)), | ||
598 | GFP_KERNEL); | ||
599 | if (!dev) | 591 | if (!dev) |
600 | return NULL; | 592 | return NULL; |
601 | res = (struct resource *) &dev[1]; | 593 | |
594 | /* count the io and irq resources */ | ||
595 | while (of_address_to_resource(np, num_reg, &temp_res) == 0) | ||
596 | num_reg++; | ||
597 | num_irq = of_irq_count(np); | ||
602 | 598 | ||
603 | /* Populate the resource table */ | 599 | /* Populate the resource table */ |
604 | if (num_irq || num_reg) { | 600 | if (num_irq || num_reg) { |
601 | res = kzalloc(sizeof(*res) * (num_irq + num_reg), GFP_KERNEL); | ||
602 | if (!res) { | ||
603 | platform_device_put(dev); | ||
604 | return NULL; | ||
605 | } | ||
606 | |||
605 | dev->num_resources = num_reg + num_irq; | 607 | dev->num_resources = num_reg + num_irq; |
606 | dev->resource = res; | 608 | dev->resource = res; |
607 | for (i = 0; i < num_reg; i++, res++) { | 609 | for (i = 0; i < num_reg; i++, res++) { |
608 | rc = of_address_to_resource(np, i, res); | 610 | rc = of_address_to_resource(np, i, res); |
609 | WARN_ON(rc); | 611 | WARN_ON(rc); |
610 | } | 612 | } |
611 | for (i = 0; i < num_irq; i++, res++) { | 613 | WARN_ON(of_irq_to_resource_table(np, res, num_irq) != num_irq); |
612 | rc = of_irq_to_resource(np, i, res); | ||
613 | WARN_ON(rc == NO_IRQ); | ||
614 | } | ||
615 | } | 614 | } |
616 | 615 | ||
617 | dev->dev.of_node = of_node_get(np); | 616 | dev->dev.of_node = of_node_get(np); |
@@ -619,7 +618,6 @@ struct platform_device *of_device_alloc(struct device_node *np, | |||
619 | dev->dev.dma_mask = &dev->archdata.dma_mask; | 618 | dev->dev.dma_mask = &dev->archdata.dma_mask; |
620 | #endif | 619 | #endif |
621 | dev->dev.parent = parent; | 620 | dev->dev.parent = parent; |
622 | dev->dev.release = of_release_dev; | ||
623 | 621 | ||
624 | if (bus_id) | 622 | if (bus_id) |
625 | dev_set_name(&dev->dev, "%s", bus_id); | 623 | dev_set_name(&dev->dev, "%s", bus_id); |
@@ -657,8 +655,8 @@ struct platform_device *of_platform_device_create(struct device_node *np, | |||
657 | * to do such, possibly using a device notifier | 655 | * to do such, possibly using a device notifier |
658 | */ | 656 | */ |
659 | 657 | ||
660 | if (of_device_register(dev) != 0) { | 658 | if (of_device_add(dev) != 0) { |
661 | of_device_free(dev); | 659 | platform_device_put(dev); |
662 | return NULL; | 660 | return NULL; |
663 | } | 661 | } |
664 | 662 | ||