]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
power: supply: cpcap-charger: Fix null check for power_supply_get_by_name
authorCharles Han <hanchunchao@inspur.com>
Mon, 19 May 2025 02:47:41 +0000 (10:47 +0800)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Sun, 22 Jun 2025 17:23:04 +0000 (19:23 +0200)
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: eab4e6d953c1 ("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>
drivers/power/supply/cpcap-charger.c

index 13300dc60baf9b8ba143c784fc2a1d1badf64fc6..d0c3008db53490c6305eba48e14f9fab02f69975 100644 (file)
@@ -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;
                }