power: supply: wm831x: Use devm_power_supply_register() helper
authorAndrew Davis <afd@ti.com>
Tue, 23 Jan 2024 16:36:45 +0000 (10:36 -0600)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Sat, 27 Jan 2024 00:25:04 +0000 (01:25 +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-14-afd@ti.com
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/supply/wm831x_backup.c

index 1a7265660adeb1d1b43eeeb98540134ad886e1bb..9673fcf7f3afba0019434634174e87f2b187f480 100644 (file)
@@ -171,7 +171,6 @@ static int wm831x_backup_probe(struct platform_device *pdev)
                return -ENOMEM;
 
        devdata->wm831x = wm831x;
-       platform_set_drvdata(pdev, devdata);
 
        /* We ignore configuration failures since we can still read
         * back the status without enabling the charger (which may
@@ -191,22 +190,14 @@ static int wm831x_backup_probe(struct platform_device *pdev)
        devdata->backup_desc.properties = wm831x_backup_props;
        devdata->backup_desc.num_properties = ARRAY_SIZE(wm831x_backup_props);
        devdata->backup_desc.get_property = wm831x_backup_get_prop;
-       devdata->backup = power_supply_register(&pdev->dev,
-                                               &devdata->backup_desc, NULL);
+       devdata->backup = devm_power_supply_register(&pdev->dev,
+                                                    &devdata->backup_desc, NULL);
 
        return PTR_ERR_OR_ZERO(devdata->backup);
 }
 
-static void wm831x_backup_remove(struct platform_device *pdev)
-{
-       struct wm831x_backup *devdata = platform_get_drvdata(pdev);
-
-       power_supply_unregister(devdata->backup);
-}
-
 static struct platform_driver wm831x_backup_driver = {
        .probe = wm831x_backup_probe,
-       .remove_new = wm831x_backup_remove,
        .driver = {
                .name = "wm831x-backup",
        },