Skip to content

Commit d9fa3aa

Browse files
Charles Hansre
authored andcommitted
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: eab4e6d ("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>
1 parent 7cf8821 commit d9fa3aa

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

drivers/power/supply/cpcap-charger.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -689,9 +689,8 @@ static void cpcap_usb_detect(struct work_struct *work)
689689
struct power_supply *battery;
690690

691691
battery = power_supply_get_by_name("battery");
692-
if (IS_ERR_OR_NULL(battery)) {
693-
dev_err(ddata->dev, "battery power_supply not available %li\n",
694-
PTR_ERR(battery));
692+
if (!battery) {
693+
dev_err(ddata->dev, "battery power_supply not available\n");
695694
return;
696695
}
697696

0 commit comments

Comments
 (0)