]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
HID: apple: avoid setting up battery timer for devices without battery
authorAditya Garg <gargaditya08@live.com>
Mon, 30 Jun 2025 12:37:13 +0000 (12:37 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 28 Aug 2025 14:26:05 +0000 (16:26 +0200)
commit c061046fe9ce3ff31fb9a807144a2630ad349c17 upstream.

Currently, the battery timer is set up for all devices using hid-apple,
irrespective of whether they actually have a battery or not.

APPLE_RDESC_BATTERY is a quirk that indicates the device has a battery
and needs the battery timer. This patch checks for this quirk before
setting up the timer, ensuring that only devices with a battery will
have the timer set up.

Fixes: 6e143293e17a ("HID: apple: Report Magic Keyboard battery over USB")
Cc: stable@vger.kernel.org
Signed-off-by: Aditya Garg <gargaditya08@live.com>
Signed-off-by: Jiri Kosina <jkosina@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/hid/hid-apple.c

index 746b2abfc8fde75db7304956df9665472265a42b..76b76b67fa860af817106b5db924f7cf0a6491e1 100644 (file)
@@ -824,10 +824,12 @@ static int apple_probe(struct hid_device *hdev,
                return ret;
        }
 
-       timer_setup(&asc->battery_timer, apple_battery_timer_tick, 0);
-       mod_timer(&asc->battery_timer,
-                 jiffies + msecs_to_jiffies(APPLE_BATTERY_TIMEOUT_MS));
-       apple_fetch_battery(hdev);
+       if (quirks & APPLE_RDESC_BATTERY) {
+               timer_setup(&asc->battery_timer, apple_battery_timer_tick, 0);
+               mod_timer(&asc->battery_timer,
+                         jiffies + msecs_to_jiffies(APPLE_BATTERY_TIMEOUT_MS));
+               apple_fetch_battery(hdev);
+       }
 
        if (quirks & APPLE_BACKLIGHT_CTL)
                apple_backlight_init(hdev);
@@ -839,7 +841,8 @@ static void apple_remove(struct hid_device *hdev)
 {
        struct apple_sc *asc = hid_get_drvdata(hdev);
 
-       del_timer_sync(&asc->battery_timer);
+       if (asc->quirks & APPLE_RDESC_BATTERY)
+               del_timer_sync(&asc->battery_timer);
 
        hid_hw_stop(hdev);
 }