linux/include
Jose Villaseñor Montfort d07644524b HID: input: read battery capacity from its actual report offset
hidinput_query_battery_capacity() assumes the state-of-charge value is
the first byte following the report ID (buf[1]) and ignores where the
battery field actually sits within the report.

An Apple Magic Trackpad 2 precedes the AbsoluteStateOfCharge byte with a
byte of status flags in its battery reports, so this query returns the
flags byte instead of the charge level.

The device happens to make that easy to observe, because it exposes the
same cell twice: its report descriptor declares AbsoluteStateOfCharge in
two reports (0x90 and 0x9b), so hidinput_setup_battery() registers two
power supplies. Only the first one is refreshed by hid-magicmouse -- it
uses hid_get_battery(), which returns the first battery of the list --
and that refresh goes through the report event path, which parses the
field correctly. Nothing ever reports the second one, so every read of
its capacity takes the query path above. On a USB-C Magic Trackpad over
USB, on an unpatched 7.1.5:

  hid-<serial>-battery-144 = 100%  (Charging)      <- report event path
  hid-<serial>-battery-155 =   3%  (Discharging)   <- query path

Both are the same physical battery. A raw HIDIOCGINPUT of the two
reports at that same moment:

  report 0x90 -> [90 03 64]
  report 0x9b -> [9b 03 64 64 00 00 10 00 00 00 00 00 00 00]
                     ^flags ^SoC = 0x64 = 100%

The device answers correctly in both cases; only the offset the kernel
reads the capacity from is wrong. 0x03 is the flags byte (present,
charging), reported as "3%".

Bluetooth takes the same query path for its capacity, where the trackpad
reported a bogus near-constant ~4% -- 0b100, the FullyCharged flag --
regardless of the real charge.

Store the battery field's offset within the report at setup time and use
it when querying, so the capacity is read from its real position. The
report event path already parses the field correctly through the HID
core; only the explicit GET_REPORT query was wrong.

Devices whose capacity field is the first field in the report have a
report_offset of 0 and are unaffected (buf[1 + 0] == buf[1]).

Fixes: 581c448476 ("HID: input: map digitizer battery usage")
Cc: stable@vger.kernel.org
Signed-off-by: Jose Villaseñor Montfort <pepemontfort@gmail.com>
Reviewed-by: Alec Hall <signshop.alec@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.com>
2026-08-03 20:38:09 +02:00
..
acpi Driver core changes for 7.2-rc1 2026-06-15 12:41:17 +05:30
asm-generic bitmap updates for v7.2 2026-06-17 11:38:38 +01:00
clocksource
crypto Networking changes for 7.2. 2026-06-17 08:17:00 +01:00
cxl
drm drm-next for 7.2-rc1 2026-06-17 10:21:00 +01:00
dt-bindings soc: drivers for 7.2 2026-06-17 11:21:40 -07:00
hyperv hyperv: Clean up and fix the guest ID comment in hvgdk.h 2026-05-27 15:05:26 -07:00
keys
kunit linux_kselftest-kunit-7.2-rc1 2026-06-16 16:33:57 +05:30
kvm
linux HID: input: read battery capacity from its actual report offset 2026-08-03 20:38:09 +02:00
math-emu
media
memory
misc
net Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2026-06-16 14:59:58 -07:00
pcmcia
ras
rdma RDMA v7.2 merge window 2026-06-18 08:16:21 -07:00
rv rv: Prevent task migration while handling per-CPU events 2026-06-03 12:33:25 +02:00
scsi
soc soc: drivers for 7.2 2026-06-17 11:21:40 -07:00
sound ASoC: Updates for v7.2 2026-06-15 20:19:22 +02:00
target
trace Various ext4 updates for 7.2-rc1: 2026-06-18 09:42:02 -07:00
uapi NFSD 7.2 Release Notes 2026-06-18 09:14:15 -07:00
ufs scsi: ufs: core: Fix bRefClkFreq write failure in HS-LSS mode 2026-04-21 20:58:06 -04:00
vdso futex: Provide infrastructure to plug the non contended robust futex unlock race 2026-06-03 11:38:52 +02:00
video fbdev: udlfb: add vm_ops to dlfb_ops_mmap to prevent use-after-free 2026-05-04 10:35:55 +02:00
xen xen: constify xsd_errors array 2026-06-08 09:00:06 +02:00
Kbuild