Skip to content

Commit 7614f94

Browse files
AdityaGarg8gregkh
authored andcommitted
HID: apple: avoid setting up battery timer for devices without battery
commit c061046 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: 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]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 85b10c0 commit 7614f94

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

drivers/hid/hid-apple.c

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

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);
937+
if (quirks & APPLE_RDESC_BATTERY) {
938+
timer_setup(&asc->battery_timer, apple_battery_timer_tick, 0);
939+
mod_timer(&asc->battery_timer,
940+
jiffies + msecs_to_jiffies(APPLE_BATTERY_TIMEOUT_MS));
941+
apple_fetch_battery(hdev);
942+
}
941943

942944
if (quirks & APPLE_BACKLIGHT_CTL)
943945
apple_backlight_init(hdev);
@@ -951,7 +953,9 @@ static int apple_probe(struct hid_device *hdev,
951953
return 0;
952954

953955
out_err:
954-
timer_delete_sync(&asc->battery_timer);
956+
if (quirks & APPLE_RDESC_BATTERY)
957+
timer_delete_sync(&asc->battery_timer);
958+
955959
hid_hw_stop(hdev);
956960
return ret;
957961
}
@@ -960,7 +964,8 @@ static void apple_remove(struct hid_device *hdev)
960964
{
961965
struct apple_sc *asc = hid_get_drvdata(hdev);
962966

963-
timer_delete_sync(&asc->battery_timer);
967+
if (asc->quirks & APPLE_RDESC_BATTERY)
968+
timer_delete_sync(&asc->battery_timer);
964969

965970
hid_hw_stop(hdev);
966971
}

0 commit comments

Comments
 (0)