lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID:
 <PN3PR01MB95970C5D46483D0367C1D63CB87BA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM>
Date: Wed, 25 Jun 2025 19:46:04 +0530
From: Aditya Garg <gargaditya08@...e.com>
To: Jiri Kosina <jikos@...nel.org>,
	Benjamin Tissoires <bentiss@...nel.org>
Cc: linux-input@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	José Expósito <jose.exposito89@...il.com>
Subject: [PATCH 2/2] HID: magicmouse: avoid setting up battery timer when not needed

Currently, the battery timer is set up for all devices using
hid-magicmouse, irrespective of whether they actually need it or not.

The current implementation requires the battery timer for Magic Mouse 2
and Magic Trackpad 2 when connected via USB only. Add checks to ensure
that the battery timer is only set up when they are connected via USB.

Fixes: 0b91b4e4dae6 ("HID: magicmouse: Report battery level over USB")
Cc: stable@...r.kernel.org
Signed-off-by: Aditya Garg <gargaditya08@...e.com>
---
 drivers/hid/hid-magicmouse.c | 36 +++++++++++++++++++++++-------------
 1 file changed, 23 insertions(+), 13 deletions(-)

diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
index f49405d38..3e531905b 100644
--- a/drivers/hid/hid-magicmouse.c
+++ b/drivers/hid/hid-magicmouse.c
@@ -863,18 +863,22 @@ static int magicmouse_probe(struct hid_device *hdev,
 		return ret;
 	}
 
-	timer_setup(&msc->battery_timer, magicmouse_battery_timer_tick, 0);
-	mod_timer(&msc->battery_timer,
-		  jiffies + msecs_to_jiffies(USB_BATTERY_TIMEOUT_MS));
-	magicmouse_fetch_battery(hdev);
-
-	if (id->vendor == USB_VENDOR_ID_APPLE &&
-	    (id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 ||
-	     id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC ||
-	     ((id->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 ||
-	       id->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC) &&
-	      hdev->type != HID_TYPE_USBMOUSE)))
-		return 0;
+	if (id->vendor == USB_VENDOR_ID_APPLE) {
+		bool is_mouse2 = (id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 ||
+				  id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC);
+		bool is_trackpad2 = (id->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 ||
+				     id->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC);
+
+		if (is_mouse2 || is_trackpad2) {
+			timer_setup(&msc->battery_timer, magicmouse_battery_timer_tick, 0);
+			mod_timer(&msc->battery_timer,
+				  jiffies + msecs_to_jiffies(USB_BATTERY_TIMEOUT_MS));
+			magicmouse_fetch_battery(hdev);
+		}
+
+		if (is_mouse2 || (is_trackpad2 && hdev->type != HID_TYPE_USBMOUSE))
+			return 0;
+	}
 
 	if (!msc->input) {
 		hid_err(hdev, "magicmouse input not registered\n");
@@ -947,7 +951,13 @@ static void magicmouse_remove(struct hid_device *hdev)
 
 	if (msc) {
 		cancel_delayed_work_sync(&msc->work);
-		timer_delete_sync(&msc->battery_timer);
+		if (hdev->vendor == USB_VENDOR_ID_APPLE &&
+		    (hdev->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 ||
+		     hdev->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC ||
+		     hdev->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 ||
+		     hdev->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC))
+
+			timer_delete_sync(&msc->battery_timer);
 	}
 
 	hid_hw_stop(hdev);
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ