]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
power: supply: core: simplify with cleanup.h
authorKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Fri, 5 Jul 2024 11:31:12 +0000 (13:31 +0200)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Tue, 27 Aug 2024 09:47:48 +0000 (11:47 +0200)
Allocate the memory with scoped/cleanup.h to reduce error handling and
make the code a bit simpler.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://lore.kernel.org/r/20240705113113.42851-1-krzysztof.kozlowski@linaro.org
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/supply/power_supply_core.c

index 8f6025acd10a08a3e4e6c80549c41658653bf1f9..2b845ac5115773585488f9ab4d5921bcec1d909a 100644 (file)
@@ -9,6 +9,7 @@
  *  Modified: 2004, Oct     Szabolcs Gyurko
  */
 
+#include <linux/cleanup.h>
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/init.h>
@@ -756,10 +757,10 @@ int power_supply_get_battery_info(struct power_supply *psy,
 
        for (index = 0; index < len; index++) {
                struct power_supply_battery_ocv_table *table;
-               char *propname;
                int i, tab_len, size;
 
-               propname = kasprintf(GFP_KERNEL, "ocv-capacity-table-%d", index);
+               char *propname __free(kfree) = kasprintf(GFP_KERNEL, "ocv-capacity-table-%d",
+                                                        index);
                if (!propname) {
                        power_supply_put_battery_info(psy, info);
                        err = -ENOMEM;
@@ -768,13 +769,11 @@ int power_supply_get_battery_info(struct power_supply *psy,
                list = of_get_property(battery_np, propname, &size);
                if (!list || !size) {
                        dev_err(&psy->dev, "failed to get %s\n", propname);
-                       kfree(propname);
                        power_supply_put_battery_info(psy, info);
                        err = -EINVAL;
                        goto out_put_node;
                }
 
-               kfree(propname);
                tab_len = size / (2 * sizeof(__be32));
                info->ocv_table_size[index] = tab_len;