]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
power: supply: wm97xx: Use devm_kcalloc()
authorWaqar Hameed <waqar.hameed@axis.com>
Fri, 23 Jan 2026 08:55:43 +0000 (09:55 +0100)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Fri, 30 Jan 2026 19:57:32 +0000 (20:57 +0100)
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>
drivers/power/supply/wm97xx_battery.c

index f00722c88c6fea7d6204c0504ecf810f1668c344..c30c347b48f9975e4bd6ddc8c91e4cbd893a2387 100644 (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 = {