Skip to content

Commit a9125e8

Browse files
krzksre
authored andcommitted
power: supply: core: simplify with cleanup.h
Allocate the memory with scoped/cleanup.h to reduce error handling and make the code a bit simpler. Signed-off-by: Krzysztof Kozlowski <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sebastian Reichel <[email protected]>
1 parent 17656d2 commit a9125e8

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

drivers/power/supply/power_supply_core.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* Modified: 2004, Oct Szabolcs Gyurko
1010
*/
1111

12+
#include <linux/cleanup.h>
1213
#include <linux/module.h>
1314
#include <linux/types.h>
1415
#include <linux/init.h>
@@ -756,10 +757,10 @@ int power_supply_get_battery_info(struct power_supply *psy,
756757

757758
for (index = 0; index < len; index++) {
758759
struct power_supply_battery_ocv_table *table;
759-
char *propname;
760760
int i, tab_len, size;
761761

762-
propname = kasprintf(GFP_KERNEL, "ocv-capacity-table-%d", index);
762+
char *propname __free(kfree) = kasprintf(GFP_KERNEL, "ocv-capacity-table-%d",
763+
index);
763764
if (!propname) {
764765
power_supply_put_battery_info(psy, info);
765766
err = -ENOMEM;
@@ -768,13 +769,11 @@ int power_supply_get_battery_info(struct power_supply *psy,
768769
list = of_get_property(battery_np, propname, &size);
769770
if (!list || !size) {
770771
dev_err(&psy->dev, "failed to get %s\n", propname);
771-
kfree(propname);
772772
power_supply_put_battery_info(psy, info);
773773
err = -EINVAL;
774774
goto out_put_node;
775775
}
776776

777-
kfree(propname);
778777
tab_len = size / (2 * sizeof(__be32));
779778
info->ocv_table_size[index] = tab_len;
780779

0 commit comments

Comments
 (0)