Skip to content

Commit a549e3a

Browse files
andy-shevgregkh
authored andcommitted
driver core: platform: Refactor error path in a couple places
The usual pattern is to bail out on the error case. Besides that one of the labels is redundant as we may return directly. Refactor platform_device_add() and platform_dma_configure() accordingly. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://lore.kernel.org/r/20231003142122.3072824-2-andriy.shevchenko@linux.intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent aab8aa0 commit a549e3a

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

drivers/base/platform.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ int platform_device_add(struct platform_device *pdev)
678678
*/
679679
ret = ida_alloc(&platform_devid_ida, GFP_KERNEL);
680680
if (ret < 0)
681-
goto err_out;
681+
return ret;
682682
pdev->id = ret;
683683
pdev->id_auto = true;
684684
dev_set_name(&pdev->dev, "%s.%d.auto", pdev->name, pdev->id);
@@ -712,8 +712,10 @@ int platform_device_add(struct platform_device *pdev)
712712
dev_name(&pdev->dev), dev_name(pdev->dev.parent));
713713

714714
ret = device_add(&pdev->dev);
715-
if (ret == 0)
716-
return ret;
715+
if (ret)
716+
goto failed;
717+
718+
return 0;
717719

718720
failed:
719721
if (pdev->id_auto) {
@@ -727,7 +729,6 @@ int platform_device_add(struct platform_device *pdev)
727729
release_resource(r);
728730
}
729731

730-
err_out:
731732
return ret;
732733
}
733734
EXPORT_SYMBOL_GPL(platform_device_add);
@@ -1453,12 +1454,12 @@ static int platform_dma_configure(struct device *dev)
14531454
attr = acpi_get_dma_attr(to_acpi_device_node(dev->fwnode));
14541455
ret = acpi_dma_configure(dev, attr);
14551456
}
1457+
if (ret || drv->driver_managed_dma)
1458+
return ret;
14561459

1457-
if (!ret && !drv->driver_managed_dma) {
1458-
ret = iommu_device_use_default_domain(dev);
1459-
if (ret)
1460-
arch_teardown_dma_ops(dev);
1461-
}
1460+
ret = iommu_device_use_default_domain(dev);
1461+
if (ret)
1462+
arch_teardown_dma_ops(dev);
14621463

14631464
return ret;
14641465
}

0 commit comments

Comments
 (0)