Skip to content

Commit 6136597

Browse files
andy-shevgregkh
authored andcommitted
driver core: platform: Use temporary variable in platform_device_add()
With the temporary variable for the struct device pointer the code looks better and slightly easier to read and parse by human being. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://lore.kernel.org/r/20231003142122.3072824-3-andriy.shevchenko@linux.intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a549e3a commit 6136597

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

drivers/base/platform.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -655,20 +655,21 @@ EXPORT_SYMBOL_GPL(platform_device_add_data);
655655
*/
656656
int platform_device_add(struct platform_device *pdev)
657657
{
658+
struct device *dev = &pdev->dev;
658659
u32 i;
659660
int ret;
660661

661-
if (!pdev->dev.parent)
662-
pdev->dev.parent = &platform_bus;
662+
if (!dev->parent)
663+
dev->parent = &platform_bus;
663664

664-
pdev->dev.bus = &platform_bus_type;
665+
dev->bus = &platform_bus_type;
665666

666667
switch (pdev->id) {
667668
default:
668-
dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id);
669+
dev_set_name(dev, "%s.%d", pdev->name, pdev->id);
669670
break;
670671
case PLATFORM_DEVID_NONE:
671-
dev_set_name(&pdev->dev, "%s", pdev->name);
672+
dev_set_name(dev, "%s", pdev->name);
672673
break;
673674
case PLATFORM_DEVID_AUTO:
674675
/*
@@ -681,15 +682,15 @@ int platform_device_add(struct platform_device *pdev)
681682
return ret;
682683
pdev->id = ret;
683684
pdev->id_auto = true;
684-
dev_set_name(&pdev->dev, "%s.%d.auto", pdev->name, pdev->id);
685+
dev_set_name(dev, "%s.%d.auto", pdev->name, pdev->id);
685686
break;
686687
}
687688

688689
for (i = 0; i < pdev->num_resources; i++) {
689690
struct resource *p, *r = &pdev->resource[i];
690691

691692
if (r->name == NULL)
692-
r->name = dev_name(&pdev->dev);
693+
r->name = dev_name(dev);
693694

694695
p = r->parent;
695696
if (!p) {
@@ -702,16 +703,16 @@ int platform_device_add(struct platform_device *pdev)
702703
if (p) {
703704
ret = insert_resource(p, r);
704705
if (ret) {
705-
dev_err(&pdev->dev, "failed to claim resource %d: %pR\n", i, r);
706+
dev_err(dev, "failed to claim resource %d: %pR\n", i, r);
706707
goto failed;
707708
}
708709
}
709710
}
710711

711-
pr_debug("Registering platform device '%s'. Parent at %s\n",
712-
dev_name(&pdev->dev), dev_name(pdev->dev.parent));
712+
pr_debug("Registering platform device '%s'. Parent at %s\n", dev_name(dev),
713+
dev_name(dev->parent));
713714

714-
ret = device_add(&pdev->dev);
715+
ret = device_add(dev);
715716
if (ret)
716717
goto failed;
717718

0 commit comments

Comments
 (0)