Skip to content

Commit c061046

Browse files
AdityaGarg8Jiri Kosina
authored andcommitted
HID: apple: avoid setting up battery timer for devices without battery
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: 6e14329 ("HID: apple: Report Magic Keyboard battery over USB") Cc: [email protected] Signed-off-by: Aditya Garg <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 8a20830 commit c061046

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

drivers/hid/hid-apple.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -933,10 +933,12 @@ static int apple_probe(struct hid_device *hdev,
933933
return ret;
934934
}
935935

936-
timer_setup(&asc->battery_timer, apple_battery_timer_tick, 0);
937-
mod_timer(&asc->battery_timer,
938-
jiffies + msecs_to_jiffies(APPLE_BATTERY_TIMEOUT_MS));
939-
apple_fetch_battery(hdev);
936+
if (quirks & APPLE_RDESC_BATTERY) {
937+
timer_setup(&asc->battery_timer, apple_battery_timer_tick, 0);
938+
mod_timer(&asc->battery_timer,
939+
jiffies + msecs_to_jiffies(APPLE_BATTERY_TIMEOUT_MS));
940+
apple_fetch_battery(hdev);
941+
}
940942

941943
if (quirks & APPLE_BACKLIGHT_CTL)
942944
apple_backlight_init(hdev);
@@ -950,7 +952,9 @@ static int apple_probe(struct hid_device *hdev,
950952
return 0;
951953

952954
out_err:
953-
timer_delete_sync(&asc->battery_timer);
955+
if (quirks & APPLE_RDESC_BATTERY)
956+
timer_delete_sync(&asc->battery_timer);
957+
954958
hid_hw_stop(hdev);
955959
return ret;
956960
}
@@ -959,7 +963,8 @@ static void apple_remove(struct hid_device *hdev)
959963
{
960964
struct apple_sc *asc = hid_get_drvdata(hdev);
961965

962-
timer_delete_sync(&asc->battery_timer);
966+
if (asc->quirks & APPLE_RDESC_BATTERY)
967+
timer_delete_sync(&asc->battery_timer);
963968

964969
hid_hw_stop(hdev);
965970
}

0 commit comments

Comments
 (0)