From: Waqar Hameed Date: Fri, 23 Jan 2026 08:55:43 +0000 (+0100) Subject: power: supply: wm97xx: Use devm_kcalloc() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=72db889394d89ffde61e7438f0cdfc0135c9da48;p=thirdparty%2Flinux.git 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 Link: https://patch.msgid.link/5ac93f5b0fa417bb5d9e93b9302a18f2c04d4077.1769158280.git.waqar.hameed@axis.com Signed-off-by: Sebastian Reichel --- diff --git a/drivers/power/supply/wm97xx_battery.c b/drivers/power/supply/wm97xx_battery.c index f00722c88c6fe..c30c347b48f99 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,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 = {