[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <c6379b2fc6a766221664d26d4a29a3960c1c1c1e.1766270196.git.waqar.hameed@axis.com>
Date: Sat, 20 Dec 2025 23:46:25 +0100
From: Waqar Hameed <waqar.hameed@...s.com>
To: Sebastian Reichel <sre@...nel.org>
CC: <kernel@...s.com>, <linux-pm@...r.kernel.org>,
<linux-kernel@...r.kernel.org>
Subject: [PATCH 3/3] power: supply: wm97xx: Use devm_kcalloc()
Instead of handling the memory allocation manually, use the automatic
`devres` variant `devm_kcalloc()`. This is less error prone and
eliminates the `goto`-path.
Signed-off-by: Waqar Hameed <waqar.hameed@...s.com>
---
drivers/power/supply/wm97xx_battery.c | 26 ++++++++------------------
1 file changed, 8 insertions(+), 18 deletions(-)
diff --git a/drivers/power/supply/wm97xx_battery.c b/drivers/power/supply/wm97xx_battery.c
index e91467dcab19c..a6c55b1e02863 100644
--- a/drivers/power/supply/wm97xx_battery.c
+++ b/drivers/power/supply/wm97xx_battery.c
@@ -192,7 +192,7 @@ static int wm97xx_bat_probe(struct platform_device *dev)
if (pdata->min_voltage >= 0)
props++; /* POWER_SUPPLY_PROP_VOLTAGE_MIN */
- prop = kcalloc(props, sizeof(*prop), GFP_KERNEL);
+ prop = devm_kcalloc(&dev->dev, props, sizeof(*prop), GFP_KERNEL);
if (!prop)
return -ENOMEM;
@@ -224,29 +224,20 @@ static int wm97xx_bat_probe(struct platform_device *dev)
bat_psy_desc.num_properties = props;
bat_psy = devm_power_supply_register(&dev->dev, &bat_psy_desc, &cfg);
- if (!IS_ERR(bat_psy)) {
- schedule_work(&bat_work);
- } else {
- ret = PTR_ERR(bat_psy);
- goto free;
- }
+ if (IS_ERR(bat_psy))
+ return PTR_ERR(bat_psy);
+
+ schedule_work(&bat_work);
if (charge_gpiod) {
ret = request_irq(gpiod_to_irq(charge_gpiod), wm97xx_chrg_irq,
0, "AC Detect", dev);
- if (ret) {
- dev_err_probe(&dev->dev, ret,
- "failed to request GPIO irq\n");
- goto free;
- }
+ if (ret)
+ return dev_err_probe(&dev->dev, ret,
+ "failed to request GPIO irq\n");
}
return 0;
-
-free:
- kfree(prop);
-
- return ret;
}
static void wm97xx_bat_remove(struct platform_device *dev)
@@ -254,7 +245,6 @@ static void wm97xx_bat_remove(struct platform_device *dev)
if (charge_gpiod)
free_irq(gpiod_to_irq(charge_gpiod), dev);
cancel_work_sync(&bat_work);
- kfree(prop);
}
static struct platform_driver wm97xx_bat_driver = {
--
2.39.5
Powered by blists - more mailing lists