mirror of https://github.com/torvalds/linux.git
power: supply: cpcap-charger: Fix null check for power_supply_get_by_name
In the cpcap_usb_detect() function, the power_supply_get_by_name()
function may return `NULL` instead of an error pointer.
To prevent potential null pointer dereferences, Added a null check.
Fixes: eab4e6d953 ("power: supply: cpcap-charger: get the battery inserted infomation from cpcap-battery")
Signed-off-by: Charles Han <hanchunchao@inspur.com>
Link: https://lore.kernel.org/r/20250519024741.5846-1-hanchunchao@inspur.com
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
This commit is contained in:
parent
7cf88213b9
commit
d9fa3aae08
|
|
@ -689,9 +689,8 @@ static void cpcap_usb_detect(struct work_struct *work)
|
|||
struct power_supply *battery;
|
||||
|
||||
battery = power_supply_get_by_name("battery");
|
||||
if (IS_ERR_OR_NULL(battery)) {
|
||||
dev_err(ddata->dev, "battery power_supply not available %li\n",
|
||||
PTR_ERR(battery));
|
||||
if (!battery) {
|
||||
dev_err(ddata->dev, "battery power_supply not available\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue