public inbox for linux-input@vger.kernel.org
 help / color / mirror / Atom feed
From: "José Expósito" <jose.exposito89@gmail.com>
To: Aditya Garg <gargaditya08@live.com>
Cc: Jiri Kosina <jikos@kernel.org>,
	Benjamin Tissoires <bentiss@kernel.org>,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] HID: apple: avoid setting up battery timer for devices without battery
Date: Mon, 30 Jun 2025 11:33:56 +0200	[thread overview]
Message-ID: <aGJaBJLwA7vbq32k@fedora> (raw)
In-Reply-To: <PN3PR01MB9597321C9A619D3CB336FB23B87BA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM>

On Wed, Jun 25, 2025 at 07:46:03PM +0530, Aditya Garg wrote:
> 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>
> ---
>  drivers/hid/hid-apple.c | 13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
> index b8b99eb01..b9f45c089 100644
> --- a/drivers/hid/hid-apple.c
> +++ b/drivers/hid/hid-apple.c
> @@ -959,10 +959,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);
> +	}
>

The same here, the `out_err:` error case uses the timer and it can
be uninitialized.

Jose

>  	if (quirks & APPLE_BACKLIGHT_CTL)
>  		apple_backlight_init(hdev);
> @@ -985,7 +987,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);
>  }
> -- 
> 2.43.0
> 

  reply	other threads:[~2025-06-30  9:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-25 14:16 [PATCH 0/2] HID: avoid setting up battery timer when not needed in hid-apple and magicmouse Aditya Garg
2025-06-25 14:16 ` [PATCH 1/2] HID: apple: avoid setting up battery timer for devices without battery Aditya Garg
2025-06-30  9:33   ` José Expósito [this message]
2025-06-30 10:10     ` Aditya Garg
2025-06-25 14:16 ` [PATCH 2/2] HID: magicmouse: avoid setting up battery timer when not needed Aditya Garg
2025-06-30  9:32   ` José Expósito

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aGJaBJLwA7vbq32k@fedora \
    --to=jose.exposito89@gmail.com \
    --cc=bentiss@kernel.org \
    --cc=gargaditya08@live.com \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox