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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 31 Dec 2022 12:32:45 +0000 (13:32 +0100)
commitb8131efb89d9f837c9244f900f0fc2699fd1181d
tree4a0bf8e7e501bfb6f745c0da09d1a4914dd9d2f2
parent301e40552833e21b4c812e49273918caf216279b
power: supply: fix null pointer dereferencing in power_supply_get_battery_info

[ Upstream commit 104bb8a663451404a26331263ce5b96c34504049 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/power/supply/power_supply_core.c