From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Julius Lehmann <lehmanju@devpi.de>,
Jiri Kosina <jkosina@suse.com>, Sasha Levin <sashal@kernel.org>,
jikos@kernel.org, bentiss@kernel.org,
linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH AUTOSEL 6.19-5.15] HID: magicmouse: fix battery reporting for Apple Magic Trackpad 2
Date: Tue, 10 Mar 2026 05:01:36 -0400 [thread overview]
Message-ID: <20260310090145.2709021-36-sashal@kernel.org> (raw)
In-Reply-To: <20260310090145.2709021-1-sashal@kernel.org>
From: Julius Lehmann <lehmanju@devpi.de>
[ Upstream commit 5f3518d77419255f8b12bb23c8ec22acbeb6bc5b ]
Battery reporting does not work for the Apple Magic Trackpad 2 if it is
connected via USB. The current hid descriptor fixup code checks for a
hid descriptor length of exactly 83 bytes. If the hid descriptor is
larger, which is the case for newer apple mice, the fixup is not
applied.
This fix checks for hid descriptor sizes greater/equal 83 bytes which
applies the fixup for newer devices as well.
Signed-off-by: Julius Lehmann <lehmanju@devpi.de>
Signed-off-by: Jiri Kosina <jkosina@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
LLM Generated explanations, may be completely bogus:
## Analysis
### Problem
Battery reporting doesn't work for Apple Magic Trackpad 2 when connected
via USB if the HID descriptor is larger than exactly 83 bytes. Newer
Apple devices have expanded HID descriptors, so the original strict
equality check (`*rsize == 83`) causes the battery report fixup to be
silently skipped.
### The Fix
A single-character change: `*rsize == 83` becomes `*rsize >= 83`. This
allows the descriptor fixup to apply for newer devices with larger
descriptors.
### Safety Analysis
The fix is safe because:
1. The `>= 83` check still guarantees the descriptor is at least 83
bytes, so accessing `rdesc[46]` and `rdesc[58]` is within bounds.
2. The additional content checks (`rdesc[46] == 0x84 && rdesc[58] ==
0x85`) still validate the descriptor format before applying any
modification.
3. The device type is still checked (`is_usb_magicmouse2` or
`is_usb_magictrackpad2`), so unrelated devices are unaffected.
### Stable Criteria Assessment
- **Fixes a real bug**: Yes — battery reporting completely broken for
newer Apple trackpad/mouse devices over USB.
- **Obviously correct**: Yes — the original check was overly
restrictive; the `>=` check is the natural fix while maintaining
safety through the other validation checks.
- **Small and contained**: Yes — single character change in one file,
one driver.
- **No new features**: Correct — just enables existing battery reporting
functionality for devices it should already work with.
- **Low regression risk**: Very low — only affects Apple Magic Mouse 2 /
Magic Trackpad 2 USB devices, and the content validation guards
against incorrect application.
### User Impact
Apple Magic Mouse 2 and Magic Trackpad 2 are widely used peripherals.
Users connecting via USB (e.g., for charging) lose battery level
reporting without this fix. This affects real hardware that many people
use daily.
### Verification
- `git blame` confirmed the original `*rsize == 83` check was introduced
in commit `0b91b4e4dae63` ("HID: magicmouse: Report battery level over
USB", Nov 2021), so the bug has existed since then.
- Read the surrounding code (lines 973-1006) to confirm the `rdesc[46]`
and `rdesc[58]` access is safe with `>= 83` guard.
- `git log --grep` confirmed multiple battery-related fixes to this
driver, indicating ongoing maintenance and real user interest.
- The device checks (`is_usb_magicmouse2`, `is_usb_magictrackpad2`)
limit scope to specific Apple products only.
- The fix is self-contained with no dependencies on other commits.
**YES**
drivers/hid/hid-magicmouse.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
index 91f621ceb924b..f4cf29c2e8330 100644
--- a/drivers/hid/hid-magicmouse.c
+++ b/drivers/hid/hid-magicmouse.c
@@ -990,7 +990,7 @@ static const __u8 *magicmouse_report_fixup(struct hid_device *hdev, __u8 *rdesc,
*/
if ((is_usb_magicmouse2(hdev->vendor, hdev->product) ||
is_usb_magictrackpad2(hdev->vendor, hdev->product)) &&
- *rsize == 83 && rdesc[46] == 0x84 && rdesc[58] == 0x85) {
+ *rsize >= 83 && rdesc[46] == 0x84 && rdesc[58] == 0x85) {
hid_info(hdev,
"fixing up magicmouse battery report descriptor\n");
*rsize = *rsize - 1;
--
2.51.0
next prev parent reply other threads:[~2026-03-10 9:02 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260310090145.2709021-1-sashal@kernel.org>
2026-03-10 9:01 ` [PATCH AUTOSEL 6.19-6.6] HID: asus: add xg mobile 2023 external hardware support Sasha Levin
2026-03-10 9:01 ` [PATCH AUTOSEL 6.19-5.10] HID: mcp2221: cancel last I2C command on read error Sasha Levin
2026-03-10 9:01 ` [PATCH AUTOSEL 6.19-5.10] HID: asus: avoid memory leak in asus_report_fixup() Sasha Levin
2026-03-10 9:01 ` [PATCH AUTOSEL 6.19-5.10] platform/x86: touchscreen_dmi: Add quirk for y-inverted Goodix touchscreen on SUPI S10 Sasha Levin
2026-03-10 9:01 ` [PATCH AUTOSEL 6.19-6.1] HID: apple: avoid memory leak in apple_report_fixup() Sasha Levin
2026-03-10 9:01 ` [PATCH AUTOSEL 6.19-6.12] HID: apple: Add EPOMAKER TH87 to the non-apple keyboards list Sasha Levin
2026-03-10 9:01 ` Sasha Levin [this message]
2026-03-10 9:01 ` [PATCH AUTOSEL 6.19-6.18] HID: intel-ish-hid: ipc: Add Nova Lake-H/S PCI device IDs Sasha Levin
2026-03-10 9:01 ` [PATCH AUTOSEL 6.19-5.15] HID: magicmouse: avoid memory leak in magicmouse_report_fixup() Sasha Levin
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=20260310090145.2709021-36-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=bentiss@kernel.org \
--cc=jikos@kernel.org \
--cc=jkosina@suse.com \
--cc=lehmanju@devpi.de \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=patches@lists.linux.dev \
--cc=stable@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