power: supply: da9052: Use devm_power_supply_register() helper
authorAndrew Davis <afd@ti.com>
Tue, 23 Jan 2024 16:36:34 +0000 (10:36 -0600)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Sat, 27 Jan 2024 00:23:40 +0000 (01:23 +0100)
Use the device lifecycle managed register function. This helps prevent
mistakes like unregistering out of order in cleanup functions and
forgetting to unregister on error paths.

Signed-off-by: Andrew Davis <afd@ti.com>
Link: https://lore.kernel.org/r/20240123163653.384385-3-afd@ti.com
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/supply/da9052-battery.c

index 6f7c58a41e91850e9fc90f0ca522917c49f42f29..0d84c42c624e080595b715b3d4459629c7bb9dd5 100644 (file)
@@ -622,7 +622,7 @@ static s32 da9052_bat_probe(struct platform_device *pdev)
                }
        }
 
-       bat->psy = power_supply_register(&pdev->dev, &psy_desc, &psy_cfg);
+       bat->psy = devm_power_supply_register(&pdev->dev, &psy_desc, &psy_cfg);
        if (IS_ERR(bat->psy)) {
                ret = PTR_ERR(bat->psy);
                goto err;
@@ -644,8 +644,6 @@ static void da9052_bat_remove(struct platform_device *pdev)
 
        for (i = 0; i < ARRAY_SIZE(da9052_bat_irqs); i++)
                da9052_free_irq(bat->da9052, da9052_bat_irq_bits[i], bat);
-
-       power_supply_unregister(bat->psy);
 }
 
 static struct platform_driver da9052_bat_driver = {