power: supply: fix null pointer dereferencing in power_supply_get_battery_info
authorruanjinjie <ruanjinjie@huawei.com>
Mon, 5 Dec 2022 07:51:53 +0000 (15:51 +0800)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Mon, 5 Dec 2022 21:56:16 +0000 (22:56 +0100)
commit104bb8a663451404a26331263ce5b96c34504049
tree7f585445a18bd8b84a55e373e783085ee3601d1c
parent7e6fb67808ab5ceba73a6f45d0942e1e25ac56a7
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: 3afb50d7125b ("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>
drivers/power/supply/power_supply_core.c