Skip to content

Commit 104bb8a

Browse files
ruanjinjiesre
authored andcommitted
power: supply: fix null pointer dereferencing in power_supply_get_battery_info
when kmalloc() fail to allocate memory in kasprintf(), propname will be NULL, strcmp() called by of_get_property() will cause null pointer dereference. So return ENOMEM if kasprintf() return NULL pointer. Fixes: 3afb50d ("power: supply: core: Add some helpers to use the battery OCV capacity table") Signed-off-by: ruanjinjie <[email protected]> Reviewed-by: Baolin Wang <[email protected]> Signed-off-by: Sebastian Reichel <[email protected]>
1 parent 7e6fb67 commit 104bb8a

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

drivers/power/supply/power_supply_core.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,11 @@ int power_supply_get_battery_info(struct power_supply *psy,
750750
int i, tab_len, size;
751751

752752
propname = kasprintf(GFP_KERNEL, "ocv-capacity-table-%d", index);
753+
if (!propname) {
754+
power_supply_put_battery_info(psy, info);
755+
err = -ENOMEM;
756+
goto out_put_node;
757+
}
753758
list = of_get_property(battery_np, propname, &size);
754759
if (!list || !size) {
755760
dev_err(&psy->dev, "failed to get %s\n", propname);

0 commit comments

Comments
 (0)