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:
Charles Han 2025-05-19 10:47:41 +08:00 committed by Sebastian Reichel
parent 7cf88213b9
commit d9fa3aae08
1 changed files with 2 additions and 3 deletions

View File

@ -689,9 +689,8 @@ static void cpcap_usb_detect(struct work_struct *work)
struct power_supply *battery; struct power_supply *battery;
battery = power_supply_get_by_name("battery"); battery = power_supply_get_by_name("battery");
if (IS_ERR_OR_NULL(battery)) { if (!battery) {
dev_err(ddata->dev, "battery power_supply not available %li\n", dev_err(ddata->dev, "battery power_supply not available\n");
PTR_ERR(battery));
return; return;
} }