Skip to content

Commit

Permalink
HID: apple: avoid setting up battery timer for devices without battery
Browse files Browse the repository at this point in the history
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: 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>
  • Loading branch information
Aditya Garg authored and Greg Kroah-Hartman committed Aug 15, 2025
1 parent 85b10c0 commit 7614f94
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions drivers/hid/hid-apple.c
Original file line number Diff line number Diff line change
Expand Up @@ -934,10 +934,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);
Expand All @@ -951,7 +953,9 @@ static int apple_probe(struct hid_device *hdev,
return 0;

out_err:
timer_delete_sync(&asc->battery_timer);
if (quirks & APPLE_RDESC_BATTERY)
timer_delete_sync(&asc->battery_timer);

hid_hw_stop(hdev);
return ret;
}
Expand All @@ -960,7 +964,8 @@ static void apple_remove(struct hid_device *hdev)
{
struct apple_sc *asc = hid_get_drvdata(hdev);

timer_delete_sync(&asc->battery_timer);
if (asc->quirks & APPLE_RDESC_BATTERY)
timer_delete_sync(&asc->battery_timer);

hid_hw_stop(hdev);
}
Expand Down

0 comments on commit 7614f94

Please sign in to comment.