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@axis.com>
Link: https://patch.msgid.link/5ac93f5b0fa417bb5d9e93b9302a18f2c04d4077.1769158280.git.waqar.hameed@axis.com
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
This commit is contained in:
Waqar Hameed
2026-01-23 09:55:43 +01:00
committed by Sebastian Reichel
parent 2306725991
commit 72db889394

View File

@@ -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,12 +224,10 @@ static int wm97xx_bat_probe(struct platform_device *dev)
bat_psy_desc.num_properties = props;
bat_psy = 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,
@@ -246,9 +244,6 @@ static int wm97xx_bat_probe(struct platform_device *dev)
unregister:
power_supply_unregister(bat_psy);
free:
kfree(prop);
return ret;
}
@@ -258,7 +253,6 @@ static void wm97xx_bat_remove(struct platform_device *dev)
free_irq(gpiod_to_irq(charge_gpiod), dev);
cancel_work_sync(&bat_work);
power_supply_unregister(bat_psy);
kfree(prop);
}
static struct platform_driver wm97xx_bat_driver = {