[15/21] power: supply: wm8350: Use devm_power_supply_register() helper

Message ID 20240123163653.384385-16-afd@ti.com
State New
Headers
Series Power supply register with devm |

Commit Message

Andrew Davis Jan. 23, 2024, 4:36 p.m. UTC
  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>
---
 drivers/power/supply/wm8350_power.c | 29 +++++++----------------------
 1 file changed, 7 insertions(+), 22 deletions(-)
  

Comments

kernel test robot Jan. 26, 2024, 1 p.m. UTC | #1
Hi Andrew,

kernel test robot noticed the following build warnings:

[auto build test WARNING on sre-power-supply/for-next]
[also build test WARNING on linus/master v6.8-rc1 next-20240125]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Andrew-Davis/power-supply-da9030-Use-devm_power_supply_register-helper/20240124-004253
base:   https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git for-next
patch link:    https://lore.kernel.org/r/20240123163653.384385-16-afd%40ti.com
patch subject: [PATCH 15/21] power: supply: wm8350: Use devm_power_supply_register() helper
config: i386-buildonly-randconfig-004-20240126 (https://download.01.org/0day-ci/archive/20240126/202401262027.yOqHrHcD-lkp@intel.com/config)
compiler: clang version 17.0.6 (https://github.com/llvm/llvm-project 6009708b4367171ccdbf4b5905cb6a803753fe18)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240126/202401262027.yOqHrHcD-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202401262027.yOqHrHcD-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/power/supply/wm8350_power.c:573:23: warning: unused variable 'power' [-Wunused-variable]
     573 |         struct wm8350_power *power = &wm8350->power;
         |                              ^~~~~
   1 warning generated.


vim +/power +573 drivers/power/supply/wm8350_power.c

14431aa0c5a443 drivers/power/wm8350_power.c        Mark Brown       2008-11-16  569  
42720969f394dc drivers/power/supply/wm8350_power.c Uwe Kleine-König 2023-09-18  570  static void wm8350_power_remove(struct platform_device *pdev)
14431aa0c5a443 drivers/power/wm8350_power.c        Mark Brown       2008-11-16  571  {
14431aa0c5a443 drivers/power/wm8350_power.c        Mark Brown       2008-11-16  572  	struct wm8350 *wm8350 = platform_get_drvdata(pdev);
14431aa0c5a443 drivers/power/wm8350_power.c        Mark Brown       2008-11-16 @573  	struct wm8350_power *power = &wm8350->power;
14431aa0c5a443 drivers/power/wm8350_power.c        Mark Brown       2008-11-16  574  
14431aa0c5a443 drivers/power/wm8350_power.c        Mark Brown       2008-11-16  575  	free_charger_irq(wm8350);
14431aa0c5a443 drivers/power/wm8350_power.c        Mark Brown       2008-11-16  576  	device_remove_file(&pdev->dev, &dev_attr_charger_state);
14431aa0c5a443 drivers/power/wm8350_power.c        Mark Brown       2008-11-16  577  }
14431aa0c5a443 drivers/power/wm8350_power.c        Mark Brown       2008-11-16  578
  

Patch

diff --git a/drivers/power/supply/wm8350_power.c b/drivers/power/supply/wm8350_power.c
index f23b4f5343bc1..9b0010b28cafc 100644
--- a/drivers/power/supply/wm8350_power.c
+++ b/drivers/power/supply/wm8350_power.c
@@ -540,22 +540,17 @@  static int wm8350_power_probe(struct platform_device *pdev)
 	struct wm8350_charger_policy *policy = power->policy;
 	int ret;
 
-	power->ac = power_supply_register(&pdev->dev, &wm8350_ac_desc, NULL);
+	power->ac = devm_power_supply_register(&pdev->dev, &wm8350_ac_desc, NULL);
 	if (IS_ERR(power->ac))
 		return PTR_ERR(power->ac);
 
-	power->battery = power_supply_register(&pdev->dev, &wm8350_battery_desc,
-					       NULL);
-	if (IS_ERR(power->battery)) {
-		ret = PTR_ERR(power->battery);
-		goto battery_failed;
-	}
+	power->battery = devm_power_supply_register(&pdev->dev, &wm8350_battery_desc, NULL);
+	if (IS_ERR(power->battery))
+		return PTR_ERR(power->battery);
 
-	power->usb = power_supply_register(&pdev->dev, &wm8350_usb_desc, NULL);
-	if (IS_ERR(power->usb)) {
-		ret = PTR_ERR(power->usb);
-		goto usb_failed;
-	}
+	power->usb = devm_power_supply_register(&pdev->dev, &wm8350_usb_desc, NULL);
+	if (IS_ERR(power->usb))
+		return PTR_ERR(power->usb);
 
 	ret = device_create_file(&pdev->dev, &dev_attr_charger_state);
 	if (ret < 0)
@@ -569,13 +564,6 @@  static int wm8350_power_probe(struct platform_device *pdev)
 		wm8350_reg_lock(wm8350);
 	}
 
-	return ret;
-
-usb_failed:
-	power_supply_unregister(power->battery);
-battery_failed:
-	power_supply_unregister(power->ac);
-
 	return ret;
 }
 
@@ -586,9 +574,6 @@  static void wm8350_power_remove(struct platform_device *pdev)
 
 	free_charger_irq(wm8350);
 	device_remove_file(&pdev->dev, &dev_attr_charger_state);
-	power_supply_unregister(power->battery);
-	power_supply_unregister(power->ac);
-	power_supply_unregister(power->usb);
 }
 
 static struct platform_driver wm8350_power_driver = {