mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-07 19:30:30 +09:00
power: supply: fix null pointer dereferencing in power_supply_get_battery_info
[ Upstream commit104bb8a663] 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:3afb50d712("power: supply: core: Add some helpers to use the battery OCV capacity table") Signed-off-by: ruanjinjie <ruanjinjie@huawei.com> Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
72283ecfdc
commit
5beadb55f4
@@ -677,6 +677,11 @@ int power_supply_get_battery_info(struct power_supply *psy,
|
|||||||
int i, tab_len, size;
|
int i, tab_len, size;
|
||||||
|
|
||||||
propname = kasprintf(GFP_KERNEL, "ocv-capacity-table-%d", index);
|
propname = kasprintf(GFP_KERNEL, "ocv-capacity-table-%d", index);
|
||||||
|
if (!propname) {
|
||||||
|
power_supply_put_battery_info(psy, info);
|
||||||
|
err = -ENOMEM;
|
||||||
|
goto out_put_node;
|
||||||
|
}
|
||||||
list = of_get_property(battery_np, propname, &size);
|
list = of_get_property(battery_np, propname, &size);
|
||||||
if (!list || !size) {
|
if (!list || !size) {
|
||||||
dev_err(&psy->dev, "failed to get %s\n", propname);
|
dev_err(&psy->dev, "failed to get %s\n", propname);
|
||||||
|
|||||||
Reference in New Issue
Block a user