HID: logitech-hidpp: G920 force-feedback and battery fixes
Subsystems (4)
v3 cover HID: logitech-hidpp: G920 force-feedback and battery fixes
Per Jiri Kosina's request, the v2 series has been split into this 14-patch bug-fix series targeting v7.4 and a separate 18-patch rework and cleanup series targeting v7.5. The open-evdev-across-unbind force-feedback teardown use-after-free (v2 patch 22/33) is now handled in input core ("Input: destroy force-feedback device on input unregistration") and has been dropped.
This series starts from Gideon Heinz's report of Logitech G920 force-feedback initialization timing out in v7.3 and addresses several pre-existing bugs and lifetime races in hid-logitech-hidpp.
The force-feedback and teardown fixes temporarily enable device I/O around g920_get_config() in hidpp_input_configured(), switch hidpp_ff_queue_work() to GFP_ATOMIC since callbacks run under the input event spinlock, drain the G920 FF workqueue before closing the HID transport on input close, synchronously disable driver work items and disconnect input devices with device I/O enabled before stopping the transport on removal and probe failure, avoid storing an ERR_PTR in battery->ps on registration failure, avoid NULL pointer subtraction in the HID++ 1.0 consumer keys report fixup, and fix an off-by-one in G920 slot tracking that made the 63rd user effect in slot 64 unusable and leaked it across reopen.
The transport and battery fixes update hidpp_send_message_sync() to stop retrying timeouts and transport errors, initialize response buffers before publishing send_receive_buf to eliminate races with concurrent or spurious packets, fix HID++ 1.0 battery mileage event parsing and state updates, properly propagate negative errors in ADC measurement (0x1f20) queries, mark devices online on unified battery (0x1004) events while gating 0x1000/0x1004 dispatch, fix K750 solar battery feature lookup and reconnect handling, and expose and correctly map the charge_type property for the battery voltage (0x1001) feature.
Note that device removal teardown still has limitations due to how HID core's hid_device_io_start() and hid_device_io_stop() (via driver_input_lock) gate both driver raw command/response I/O and subdriver event forwarding, disabling I/O before .remove() and hid_disconnect(). For instance, HIDPP_QUIRK_DELAYED_INIT devm-managed input devices are still unregistered after hid_hw_stop(), and hidpp_connect_event() publishes hidpp->input before input registration completes. Resolving these teardown edge cases cleanly will require follow-up work in HID core and driver input registration.
Thanks.
---
Changes in v3:
- Split out the 14 bug fixes into this series for v7.4 per Jiri Kosina,
moving the 18 rework and cleanup patches into a separate series for
v7.5 and dropping v2 patch 22/33 in favor of input core teardown.
- Collected Tested-by tags from Gideon Heinz on all unchanged patches in
this series (omitted from patches 12 and 14 which were updated after
v2 testing).
- Gated event dispatch in hidpp_raw_hidpp_event() on HIDPP_CAPABILITY_UNIFIED_BATTERY so 0x1000 and 0x1004 events are
routed to their respective handlers instead of cross-corrupting
battery state.
- In hidpp20_battery_map_status_voltage(), set charge_type to unknown
when status is unknown, to none when discharging, full, or not
charging, and to standard, fast, or trickle only when charging.
- Reset charge_type to unknown on wireless disconnect in
hidpp_connect_event().
- Link to v2: https://patch.msgid.link/[email protected]
Changes in v2:
- Rebased the series on top of linux-next.
- Collected Tested-by tags from Gideon Heinz for 17 v1 patches (omitted from patch 4 where hidpp_remove() was significantly altered).
- Reorganized the series to place all 14 stable bug fixes upfront,
followed by next refactorings and modernizations.
- Updated hidpp_remove() to enable device I/O while draining work
items and disconnecting hidinput so in-flight transfers and force-feedback teardown can receive device replies (noting that
complete resolution of delayed-init and transport teardown ordering requires follow-up work in HID core).
- Stopped retrying non-busy errors (timeouts and negative transport failures) in hidpp_send_message_sync().
- Initialized response buffers before publishing send_receive_buf to prevent stale response reads on concurrent or spurious events.
- Fixed HID++ 1.0 battery mileage event parsing to read capacity from
the correct report byte and update battery state.
- Handled negative transport and timeout errors properly in ADC
measurement (0x1f20) queries.
- Marked devices online when receiving unified battery (0x1004) events.
- Fixed K750 solar battery feature lookup and reconnect handling.
- Exposed charge_type property for battery voltage (0x1001) feature.
- Link to v1: https://patch.msgid.link/[email protected]
---
Dmitry Torokhov (14):
HID: logitech-hidpp: fix G920 force-feedback initialization timeout
HID: logitech-hidpp: use GFP_ATOMIC in hidpp_ff_queue_work()
HID: logitech-hidpp: drain G920 FF workqueue before closing transport
HID: logitech-hidpp: disable works before stopping transport
HID: logitech-hidpp: do not store ERR_PTR in battery->ps
HID: logitech-hidpp: avoid NULL subtraction in consumer key report fixup
HID: logitech-hidpp: fix off-by-one in G920 force-feedback slot tracking
HID: logitech-hidpp: do not retry timeouts and transport errors in hidpp_send_message_sync()
HID: logitech-hidpp: initialize response buffer before publishing send_receive_buf
HID: logitech-hidpp: fix HID++ 1.0 battery mileage event parsing
HID: logitech-hidpp: handle negative errors in hidpp20_get_adc_measurement_1f20()
HID: logitech-hidpp: mark device online on unified battery 0x1004 events
HID: logitech-hidpp: fix K750 solar battery feature lookup and reconnect
HID: logitech-hidpp: expose charge_type property for battery voltage feature
drivers/hid/hid-logitech-hidpp.c | 150 ++++++++++++++++++++++++++++----------- 1 file changed, 107 insertions(+), 43 deletions(-)
---
base-commit: 84abb955b1015477aa11a96e2f3ac1b938b77f48
change-id: 20261110-hid-logitech-hidpp-6884bfb6a348
Thanks.
Signature · 1 line
Dmitry
PATCH v3 1/14 HID: logitech-hidpp: fix G920 force-feedback initialization timeout
Commit 544315e40172 ("HID: logitech-hidpp: move FF initialization to .input_configured()") moved Logitech G920 force-feedback querying and initialization into hidpp_input_configured(), which runs during hid_connect(). Because hidpp_probe() calls hid_device_io_stop() across hid_connect(), incoming HID++ responses from the device are blocked and g920_get_config() times out with -ETIMEDOUT.
Temporarily re-enable HID device I/O around g920_get_config() in hidpp_input_configured() so the hardware configuration queries receive their replies during input setup.
--- drivers/hid/hid-logitech-hidpp.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/hid/hid-logitech-hidpp.c +2 -0
@@ -4096,7 +4096,9 @@ static int hidpp_input_configured(struct hid_device *hdev, struct hid_input *hidif (!list_is_first (&hidinput->list, &hdev->inputs))return 0 ; +hid_device_io_start (hdev); ret =g920_get_config (hidpp, &data); +hid_device_io_stop (hdev);if (!ret) ret =hidpp_ff_init (hidpp, &data);
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH v3 2/14 HID: logitech-hidpp: use GFP_ATOMIC in hidpp_ff_queue_work()
In reply to Dmitry TorokhovForce-feedback playback, gain, and autocenter updates are invoked by the input force-feedback core while holding the input device event spinlock with interrupts disabled. Allocating work items with GFP_KERNEL in hidpp_ff_queue_work() can therefore sleep in atomic context.
Allocate work items with GFP_ATOMIC instead so force-feedback commands can be queued safely while event locks are held.
--- drivers/hid/hid-logitech-hidpp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hid/hid-logitech-hidpp.c +2 -1
@@ -2542,9 +2542,10 @@ static void hidpp_ff_work_handler(struct work_struct *w)static int hidpp_ff_queue_work (struct hidpp_ff_private_data *data,int effect_id,u8 command,u8 *params,u8 size) { -struct hidpp_ff_work_data *wd =kzalloc_obj (*wd); +struct hidpp_ff_work_data *wd;int s; + wd =kzalloc_obj (*wd,GFP_ATOMIC );if (!wd)return -ENOMEM ;
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH v3 3/14 HID: logitech-hidpp: drain G920 FF workqueue before closing transport
In reply to Dmitry TorokhovProbe no longer keeps the HID transport open indefinitely, so the underlying USB interrupt IN endpoint only stays active while the HID transport is held open. When the last input user closes the device after input core flushes active effects, or when the device is inhibited with commands still queued, releasing the HID transport shuts down transport I/O unless another client holds it open. Queued force-feedback commands then fail to receive their HID++ replies, causing command timeouts and leaving stale slot mappings behind.
Override the input open and close callbacks once G920 force feedback is initialized so the force-feedback send queue drains completely before closing the HID transport.
--- drivers/hid/hid-logitech-hidpp.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
drivers/hid/hid-logitech-hidpp.c +19 -0
@@ -2815,6 +2815,22 @@ static void hidpp_ff_destroy(struct ff_device *ff)kfree (data->effect_ids); } +static int g920_input_open (struct input_dev *dev) +{ +struct hid_device *hid =input_get_drvdata (dev); + +return hid_hw_open (hid); +} + +static void g920_input_close (struct input_dev *dev) +{ +struct hid_device *hid =input_get_drvdata (dev); +struct hidpp_ff_private_data *data = dev->ff->private; + +flush_workqueue (data->wq); +hid_hw_close (hid); +} +static int hidpp_ff_init (struct hidpp_device *hidpp,struct hidpp_ff_private_data *data) {
@@ -2897,6 +2913,9 @@ static int hidpp_ff_init(struct hidpp_device *hidpp, ff->set_autocenter = hidpp_ff_set_autocenter; ff->destroy = hidpp_ff_destroy; + dev->open = g920_input_open; + dev->close = g920_input_close; +/* Create sysfs interface */ error =device_create_file (&(hidpp->hid_dev->dev), &dev_attr_range);if (error)
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH v3 4/14 HID: logitech-hidpp: disable works before stopping transport
In reply to Dmitry TorokhovDevice removal and the probe error unwind path cancel the connect-event and hi-res-reset work items only after closing and stopping the HID transport, leaving in-flight work handlers able to issue HID++ transfers or register power-supply and input devices while transport teardown is underway. Moving cancel_work_sync() ahead of transport shutdown is not sufficient because incoming reports remain active until the transport stops and can re-schedule the work items before hid_hw_stop() completes.
Disable both work items synchronously before closing or stopping the HID transport on device removal and on the post-I/O probe failure path, and drop the unreachable cancellations from early transport start and open failure paths where incoming packets have not been enabled yet.
On device removal where HID core enters with device I/O stopped and driver_input_lock held, temporarily re-enable device I/O to flush pending work handlers and disconnect input devices before stopping the transport. Clear HID_CLAIMED_INPUT and hidpp->input upfront so incoming reports can still wake synchronous commands without dispatching events to the disconnecting input device.
--- drivers/hid/hid-logitech-hidpp.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
drivers/hid/hid-logitech-hidpp.c +15 -4
@@ -4805,13 +4805,13 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)return ret; hid_hw_init_fail: +disable_work_sync (&hidpp->work); +disable_work_sync (&hidpp->reset_hi_res_work);hid_hw_close (hdev); hid_hw_open_fail:hid_hw_stop (hdev); hid_hw_start_fail:sysfs_remove_group (&hdev->dev.kobj, &ps_attribute_group); -cancel_work_sync (&hidpp->work); -cancel_work_sync (&hidpp->reset_hi_res_work);mutex_destroy (&hidpp->send_mutex);return ret; }
@@ -4819,15 +4819,26 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)static void hidpp_remove (struct hid_device *hdev) {struct hidpp_device *hidpp =hid_get_drvdata (hdev); +bool claimed_input;if (!hidpp)return hid_hw_stop (hdev);sysfs_remove_group (&hdev->dev.kobj, &ps_attribute_group); + claimed_input = hdev->claimed &HID_CLAIMED_INPUT ; + hdev->claimed &= ~HID_CLAIMED_INPUT ; +if (claimed_input) + hidpp->input =NULL ; + +hid_device_io_start (hdev); +disable_work_sync (&hidpp->work); +disable_work_sync (&hidpp->reset_hi_res_work); +if (claimed_input) +hidinput_disconnect (hdev); +hid_device_io_stop (hdev); +hid_hw_stop (hdev); -cancel_work_sync (&hidpp->work); -cancel_work_sync (&hidpp->reset_hi_res_work);mutex_destroy (&hidpp->send_mutex); }
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
[email protected]
AI reviewRe: [PATCH v3 04/14] HID: logitech-hidpp: disable works before stopping transport
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] HID: logitech-hidpp: work flush with I/O stopped in hidpp_probe() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] HID: logitech-hidpp: work flush with I/O stopped in hidpp_probe()
--
commit 43c05e6ba16082cedbdbc71e25086acb4e9b0851
Author: Dmitry Torokhov <[email protected]>
HID: logitech-hidpp: disable works before stopping transport
This commit synchronously disables hidpp->work and hidpp->reset_hi_res_work before closing and stopping the HID transport during probe failure and device removal.
drivers/hid/hid-logitech-hidpp.c static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) · line 4810
Quoted 11 lines
drivers/hid/hid-logitech-hidpp.c +2
-0@@ -4805,13 +4805,13 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)return ret; hid_hw_init_fail: +disable_work_sync (&hidpp->work); +disable_work_sync (&hidpp->reset_hi_res_work);hid_hw_close (hdev);
[Severity: Medium]
Can disable_work_sync() here stall waiting for in-flight work items while device I/O is stopped?
In hidpp_probe(), hid_device_io_start() enables incoming reports during device initialization, which can schedule hidpp->work or hidpp->reset_hi_res_work. Before calling hid_connect(), hidpp_probe() calls hid_device_io_stop(), acquiring hdev->driver_input_lock. If hid_connect() fails and jumps to hid_hw_init_fail, disable_work_sync() waits for those work handlers with hdev->driver_input_lock held, so any synchronous HID++ command inside hidpp_connect_event() or hidpp_reset_hi_res_handler() cannot receive its reply report and stalls until each 5-second command timeout expires. Should hid_hw_init_fail bracket disable_work_sync() with hid_device_io_start() and hid_device_io_stop() like hidpp_remove() does?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Jiri Kosina
maintainerRe: [PATCH v3 04/14] HID: logitech-hidpp: disable works before stopping transport
In reply to Dmitry TorokhovQuoted 60 lines · Dmitry Torokhov
Device removal and the probe error unwind path cancel the connect-event and hi-res-reset work items only after closing and stopping the HID transport, leaving in-flight work handlers able to issue HID++ transfers or register power-supply and input devices while transport teardown is underway. Moving
cancel_work_sync()ahead of transport shutdown is not sufficient because incoming reports remain active until the transport stops and can re-schedule the work items beforehid_hw_stop()completes.Disable both work items synchronously before closing or stopping the HID transport on device removal and on the post-I/O probe failure path, and drop the unreachable cancellations from early transport start and open failure paths where incoming packets have not been enabled yet.
On device removal where HID core enters with device I/O stopped and
driver_input_lockheld, temporarily re-enable device I/O to flush pending work handlers and disconnect input devices before stopping the transport. ClearHID_CLAIMED_INPUTandhidpp->inputupfront so incoming reports can still wake synchronous commands without dispatching events to the disconnecting input device.Fixes 7bfd2927adca ("HID: hid-logitech-hidpp: Add basic support for Logitech G920")Fixes ed80cc4667ac ("HID: logitech-hidpp: Add HIDPP_QUIRK_RESET_HI_RES_SCROLL")Tested-by Gideon Heinz <[email protected]>Signed-off-by Dmitry Torokhov <[email protected]>--- drivers/hid/hid-logitech-hidpp.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)drivers/hid/hid-logitech-hidpp.c +3
-2@@ -4805,13 +4805,13 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)return ret; hid_hw_init_fail: +disable_work_sync (&hidpp->work); +disable_work_sync (&hidpp->reset_hi_res_work);hid_hw_close (hdev); hid_hw_open_fail:hid_hw_stop (hdev); hid_hw_start_fail:sysfs_remove_group (&hdev->dev.kobj, &ps_attribute_group); -cancel_work_sync (&hidpp->work); -cancel_work_sync (&hidpp->reset_hi_res_work);mutex_destroy (&hidpp->send_mutex);return ret; }@@ -4819,15 +4819,26 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)static void hidpp_remove (struct hid_device *hdev) {struct hidpp_device *hidpp =hid_get_drvdata (hdev); +bool claimed_input;if (!hidpp)return hid_hw_stop (hdev);sysfs_remove_group (&hdev->dev.kobj, &ps_attribute_group);
drivers/hid/hid-logitech-hidpp.c static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) · line 4838
Quoted 10 lines
drivers/hid/hid-logitech-hidpp.c +10
-0+ claimed_input = hdev->claimed &HID_CLAIMED_INPUT ; + hdev->claimed &= ~HID_CLAIMED_INPUT ; +if (claimed_input) + hidpp->input =NULL ; + +hid_device_io_start (hdev); +disable_work_sync (&hidpp->work); +disable_work_sync (&hidpp->reset_hi_res_work); +if (claimed_input) +hidinput_disconnect (hdev);
This fails to build, because hidinput_disconnect is defined in hid-core and there is no declaration for it in logitech code.
I'll drop this series for now, please fix it and resubmit a version that compiles :))
Thanks!
Signature · 2 lines
Jiri Kosina SUSE Labs
Re: [PATCH v3 04/14] HID: logitech-hidpp: disable works before stopping transport
Quoted 76 lines · Jiri Kosina
Quoted 60 lines · Dmitry Torokhov
Device removal and the probe error unwind path cancel the connect-event and hi-res-reset work items only after closing and stopping the HID transport, leaving in-flight work handlers able to issue HID++ transfers or register power-supply and input devices while transport teardown is underway. Moving
cancel_work_sync()ahead of transport shutdown is not sufficient because incoming reports remain active until the transport stops and can re-schedule the work items beforehid_hw_stop()completes.Disable both work items synchronously before closing or stopping the HID transport on device removal and on the post-I/O probe failure path, and drop the unreachable cancellations from early transport start and open failure paths where incoming packets have not been enabled yet.
On device removal where HID core enters with device I/O stopped and
driver_input_lockheld, temporarily re-enable device I/O to flush pending work handlers and disconnect input devices before stopping the transport. ClearHID_CLAIMED_INPUTandhidpp->inputupfront so incoming reports can still wake synchronous commands without dispatching events to the disconnecting input device.Fixes 7bfd2927adca ("HID: hid-logitech-hidpp: Add basic support for Logitech G920")Fixes ed80cc4667ac ("HID: logitech-hidpp: Add HIDPP_QUIRK_RESET_HI_RES_SCROLL")Tested-by Gideon Heinz <[email protected]>Signed-off-by Dmitry Torokhov <[email protected]>--- drivers/hid/hid-logitech-hidpp.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)drivers/hid/hid-logitech-hidpp.c +3
-2@@ -4805,13 +4805,13 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)return ret; hid_hw_init_fail: +disable_work_sync (&hidpp->work); +disable_work_sync (&hidpp->reset_hi_res_work);hid_hw_close (hdev); hid_hw_open_fail:hid_hw_stop (hdev); hid_hw_start_fail:sysfs_remove_group (&hdev->dev.kobj, &ps_attribute_group); -cancel_work_sync (&hidpp->work); -cancel_work_sync (&hidpp->reset_hi_res_work);mutex_destroy (&hidpp->send_mutex);return ret; }@@ -4819,15 +4819,26 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)static void hidpp_remove (struct hid_device *hdev) {struct hidpp_device *hidpp =hid_get_drvdata (hdev); +bool claimed_input;if (!hidpp)return hid_hw_stop (hdev);sysfs_remove_group (&hdev->dev.kobj, &ps_attribute_group);drivers/hid/hid-logitech-hidpp.c static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) · line 4838
Quoted 10 lines
drivers/hid/hid-logitech-hidpp.c +10
-0+ claimed_input = hdev->claimed &HID_CLAIMED_INPUT ; + hdev->claimed &= ~HID_CLAIMED_INPUT ; +if (claimed_input) + hidpp->input =NULL ; + +hid_device_io_start (hdev); +disable_work_sync (&hidpp->work); +disable_work_sync (&hidpp->reset_hi_res_work); +if (claimed_input) +hidinput_disconnect (hdev);This fails to build, because
hidinput_disconnectis defined in hid-core and there is no declaration for it in logitech code.
Quoted 2 lines
I'll drop this series for now, please fix it and resubmit a version that compiles :))
Ah, yes, I un-exported it in my hidraw cleanup patch series that you just applied.
Hoisted by my own petard ;)
I guess we need to re-export it now that there is a valid (IMO) use case to have it available outside of the hid core.
Thanks.
Signature · 1 line
Dmitry
Jiri Kosina
maintainerRe: [PATCH v3 04/14] HID: logitech-hidpp: disable works before stopping transport
Quoted 2 lines · Dmitry Torokhov
Ah, yes, I un-exported it in my hidraw cleanup patch series that you just applied.
Hmm, but that cleanup is sitting in hid.git#for-7.5/hidraw, while this build breakage occured in for-7.4/upstream-fixes, which is based on Linus' tree and doesn't include that hidraw cleanup ...
Quoted 1 line
Hoisted by my own petard ;)
:))
Thanks,
Signature · 2 lines
Jiri Kosina SUSE Labs
Re: [PATCH v3 04/14] HID: logitech-hidpp: disable works before stopping transport
Quoted 8 lines · Jiri Kosina
Quoted 2 lines · Dmitry Torokhov
Ah, yes, I un-exported it in my hidraw cleanup patch series that you just applied.
Hmm, but that cleanup is sitting in hid.git#for-7.5/hidraw, while this build breakage occured in for-7.4/upstream-fixes, which is based on Linus' tree and doesn't include that hidraw cleanup ...
Doesn't next mix it all together?
Quoted 7 lines
Quoted 2 lines
Hoisted by my own petard ;)
:))
Thanks,
Signature · 1 line
Dmitry
Jiri Kosina
maintainerRe: [PATCH v3 04/14] HID: logitech-hidpp: disable works before stopping transport
Quoted 8 lines · Dmitry Torokhov
Quoted 6 lines
Quoted 2 lines
Ah, yes, I un-exported it in my hidraw cleanup patch series that you just applied.
Hmm, but that cleanup is sitting in hid.git#for-7.5/hidraw, while this build breakage occured in for-7.4/upstream-fixes, which is based on Linus' tree and doesn't include that hidraw cleanup ...
Doesn't next mix it all together?
Right, the build fails on for-next, which is a super-merge of all the topic branches. Sorry for the noise,
Signature · 2 lines
Jiri Kosina SUSE Labs
Re: [PATCH v3 04/14] HID: logitech-hidpp: disable works before stopping transport
Quoted 5 lines · Jiri Kosina
Quoted 3 lines · Dmitry Torokhov
Quoted 3 lines
Quoted 2 lines
Ah, yes, I un-exported it in my hidraw cleanup patch series that you just applied.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Hmm, but that cleanup is sitting in hid.git#for-7.5/hidraw, while this build breakage occured in for-7.4/upstream-fixes, which is based on Linus' tree and doesn't include that hidraw cleanup ...
Doesn't next mix it all together?
Right, the build fails on for-next, which is a super-merge of all the topic branches. Sorry for the noise,
So how do you want to handle this? Keep this series as is, and apply, and drop either entire hidraw rework or just the offending patch and I will resubmit it once Logitech rework settles in?
Thanks.
Signature · 1 line
Dmitry
PATCH v3 5/14 HID: logitech-hidpp: do not store ERR_PTR in battery->ps
In reply to Dmitry TorokhovWhen power supply registration fails, storing the error pointer directly in the battery supply field leaves it non-NULL. Callers such as the connect handler and battery event handlers only check for non-NULL before notifying the power supply core, causing an error-pointer dereference oops and blocking retries on subsequent reconnect events.
Capture the registered power supply pointer in a local variable and publish it to device state only after registration and sysfs linking succeed.
--- drivers/hid/hid-logitech-hidpp.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/hid/hid-logitech-hidpp.c +9 -7
@@ -4333,6 +4333,7 @@ static int hidpp_initialize_battery(struct hidpp_device *hidpp)struct power_supply_desc *desc = &hidpp->battery.desc;enum power_supply_property *battery_props;struct hidpp_battery *battery; +struct power_supply *ps;unsigned int num_battery_props;unsigned long n;int ret;
@@ -4413,15 +4414,16 @@ static int hidpp_initialize_battery(struct hidpp_device *hidpp) desc->type =POWER_SUPPLY_TYPE_BATTERY ; desc->use_for_apm =0 ; - battery->ps =devm_power_supply_register (&hidpp->hid_dev->dev, - &battery->desc, - &cfg); -if (IS_ERR (battery->ps)) -return PTR_ERR (battery->ps); + ps =devm_power_supply_register (&hidpp->hid_dev->dev, + &battery->desc, + &cfg); +if (IS_ERR (ps)) +return PTR_ERR (ps); -power_supply_powers (battery->ps, &hidpp->hid_dev->dev); +power_supply_powers (ps, &hidpp->hid_dev->dev); + battery->ps = ps; -return ret; +return 0 ; }/* Get name + serial for USB and Bluetooth HID++ devices */
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH v3 6/14 HID: logitech-hidpp: avoid NULL subtraction in consumer key report fixup
In reply to Dmitry TorokhovReport fixup runs for all 27 MHz devices because the keyboard quirk is only determined later after parsing the report descriptor. For mice and other devices without the consumer collection, searching for the descriptor fragment returns NULL, yet the remaining length calculation subtracts the base descriptor pointer from NULL before checking the search result, triggering pointer-subtraction undefined behavior.
Ensure the search result is non-NULL before computing the remaining descriptor length.
--- drivers/hid/hid-logitech-hidpp.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/hid/hid-logitech-hidpp.c +1 -3
@@ -3872,11 +3872,9 @@ static u8 *hidpp10_consumer_keys_report_fixup(struct hidpp_device *hidpp, 0x26, 0x00 /* LOGICAL_MAX (... */ };char *consumer_rdesc, *rdesc = (char *)_rdesc; -unsigned int size; consumer_rdesc =strnstr (rdesc, consumer_rdesc_start, *rsize); - size = *rsize - (consumer_rdesc - rdesc); -if (consumer_rdesc && size >=25 ) { +if (consumer_rdesc && *rsize - (consumer_rdesc - rdesc) >=25 ) { consumer_rdesc[15 ] =0x7f ; consumer_rdesc[16 ] =0x10 ; consumer_rdesc[20 ] =0x7f ;
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH v3 7/14 HID: logitech-hidpp: fix off-by-one in G920 force-feedback slot tracking
In reply to Dmitry TorokhovLogitech G920 firmware reports 64 total 1-based hardware effect slots, reserving one slot for the built-in autocenter spring while allocating the remaining 63 user effects across 1-based slots 2 through 64. Because the driver subtracts the reserved slot count upfront before sizing and bounds-checking its slot mapping table, the 63rd concurrent user effect is assigned hardware slot 64 and exceeds the stored limit, so its slot mapping is never recorded or released and remains leaked in wheel memory across device close and reopen.
Keep the full hardware slot count for table sizing, lookups, and slot bounds checks, and withhold the reserved slot count only when creating the input force-feedback device.
--- drivers/hid/hid-logitech-hidpp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hid/hid-logitech-hidpp.c +2 -2
@@ -2872,7 +2872,7 @@ static int hidpp_ff_init(struct hidpp_device *hidpp,for (j =0 ; hidpp_ff_effects_v2[j] >=0 ; j++)set_bit (hidpp_ff_effects_v2[j], dev->ffbit); - error =input_ff_create (dev, num_slots); + error =input_ff_create (dev, num_slots -HIDPP_FF_RESERVED_SLOTS );if (error) {hid_err (dev,"Failed to create FF device!\n" );
@@ -3486,7 +3486,7 @@ static int g920_get_config(struct hidpp_device *hidpp,return -EPROTO ; } - data->num_effects = response.fap.params[0 ] -HIDPP_FF_RESERVED_SLOTS ; + data->num_effects = response.fap.params[0 ];/* reset all forces */ ret = hidpp_send_fap_command_sync(hidpp, data->feature_index,
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH v3 8/14 HID: logitech-hidpp: do not retry timeouts and transport errors in hidpp_send_message_sync()
In reply to Dmitry TorokhovWhen a transport failure or timeout occurs, the synchronous send helper clears the response buffer, setting its report ID to zero. Because the retry loop only inspects valid HID++ short, long, and very long report IDs to decide whether to return, a cleared buffer misses both checks and falls through to the busy-retry path. Every transport error and timeout is therefore misidentified as a busy error and retried three times while holding the send mutex.
Return immediately when the low-level helper reports success or a negative error code, and only retry when the device responds with an explicit busy protocol error.
--- drivers/hid/hid-logitech-hidpp.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/hid/hid-logitech-hidpp.c +3 -0
@@ -364,6 +364,9 @@ static int hidpp_send_message_sync(struct hidpp_device *hidpp, do { ret = __do_hidpp_send_message_sync(hidpp, message, response); + if (ret <= 0) + break; + if (response->report_id == REPORT_ID_HIDPP_SHORT && ret != HIDPP_ERROR_BUSY) break;
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH v3 9/14 HID: logitech-hidpp: initialize response buffer before publishing send_receive_buf
In reply to Dmitry Torokhov__do_hidpp_send_message_sync() publishes send_receive_buf before initializing the response buffer. hidpp_raw_hidpp_event() runs in IRQ or softirq context without taking send_mutex whenever the mutex is locked, reading question and answer from send_receive_buf. If an incoming report arrives after send_receive_buf is published but before response is populated, hidpp_match_answer() inspects uninitialized memory.
Initialize response with the outgoing message and clear answer_available before publishing send_receive_buf with release semantics, clear the pointer with WRITE_ONCE() on completion, and read it once with acquire semantics in the event handler.
--- drivers/hid/hid-logitech-hidpp.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
drivers/hid/hid-logitech-hidpp.c +14 -7
@@ -300,14 +300,17 @@ static int __do_hidpp_send_message_sync(struct hidpp_device *hidpp,__must_hold (&hidpp->send_mutex); - hidpp->send_receive_buf = response; - hidpp->answer_available = false; -/* * So that we can later validate the answer when it arrives * in hidpp_raw_event */ *response = *message; + hidpp->answer_available = false; +/* +* Pairs with smp_load_acquire() in hidpp_raw_hidpp_event() to ensure +* the response buffer initialization is visible before publishing. +*/ +smp_store_release (&hidpp->send_receive_buf, response); ret =__hidpp_send_report (hidpp->hid_dev, message);if (ret) {
@@ -342,7 +345,7 @@ static int __do_hidpp_send_message_sync(struct hidpp_device *hidpp, ret =0 ; out: - hidpp->send_receive_buf =NULL ; +WRITE_ONCE (hidpp->send_receive_buf,NULL );return ret; }
@@ -4148,12 +4151,16 @@ static int hidpp_raw_hidpp_event(struct hidpp_device *hidpp, u8 *data,* previously sent command. */ if (unlikely (mutex_is_locked (&hidpp->send_mutex))) { - question = hidpp->send_receive_buf; - answer = hidpp->send_receive_buf; - +/* +* Pairs with smp_store_release() in __do_hidpp_send_message_sync() +* to ensure the initialized response buffer is observed. +*/ + question =smp_load_acquire (&hidpp->send_receive_buf);if (!question)return 0 ; + answer = question; +/* * Check for a correct hidpp20 answer or the corresponding * error
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH v3 10/14 HID: logitech-hidpp: fix HID++ 1.0 battery mileage event parsing
In reply to Dmitry TorokhovIn HID++ 1.0 battery mileage event notifications (register 0x0d), the register address occupies the sub_id field rather than reg_address, so the payload bytes start at rawbytes[1] (parameter p0). The driver previously read capacity from report->rap.params[0] (rawbytes[2]), extracting parameter p1 instead of the battery mileage percentage. Additionally, when a change was detected, hidpp10_battery_event() updated level and status but neglected to update battery.capacity, leaving capacity frozen and triggering spurious power supply updates on every subsequent event.
Read capacity from report->rawbytes[1] and store the updated capacity in hidpp->battery.capacity when changed.
--- drivers/hid/hid-logitech-hidpp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hid/hid-logitech-hidpp.c +2 -1
@@ -829,7 +829,7 @@ static int hidpp10_battery_event(struct hidpp_device *hidpp, u8 *data, int size) status =hidpp10_battery_status_map_status (report->rawbytes[2 ]);break ;case HIDPP_REG_BATTERY_MILEAGE : - capacity = report->rap.params[0 ]; + capacity = report->rawbytes[1 ]; level = hidpp->battery.level; status =hidpp10_battery_mileage_map_status (report->rawbytes[3 ]);break ;
@@ -846,6 +846,7 @@ static int hidpp10_battery_event(struct hidpp_device *hidpp, u8 *data, int size) status ==POWER_SUPPLY_STATUS_FULL ;if (changed) { + hidpp->battery.capacity = capacity; hidpp->battery.level = level; hidpp->battery.status = status;if (hidpp->battery.ps)
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH v3 11/14 HID: logitech-hidpp: handle negative errors in hidpp20_get_adc_measurement_1f20()
In reply to Dmitry TorokhovWhen hidpp_send_fap_command_sync() fails with a negative transport or timeout error (-ETIMEDOUT, -ENODEV, etc.), hidpp20_get_adc_measurement_1f20() only checked if (ret > 0) for protocol errors and fell through. It then parsed zeroed response parameters (0 mV) and returned true, marking a disconnected or unresponsive device online and triggering spurious "possibly using the wrong voltage curve" warnings.
Return false whenever ret is non-zero, logging the debug message only when ret is a positive protocol error.
--- drivers/hid/hid-logitech-hidpp.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/hid/hid-logitech-hidpp.c +4 -3
@@ -1952,9 +1952,10 @@ static bool hidpp20_get_adc_measurement_1f20(struct hidpp_device *hidpp,CMD_ADC_MEASUREMENT_GET_ADC_MEASUREMENT , NULL, 0, &response); -if (ret >0 ) { -hid_dbg (hidpp->hid_dev,"%s: received protocol error 0x%02x\n" , - __func__, ret); +if (ret) { +if (ret >0 ) +hid_dbg (hidpp->hid_dev,"%s: received protocol error 0x%02x\n" , + __func__, ret);return false; }
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH v3 12/14 HID: logitech-hidpp: mark device online on unified battery 0x1004 events
In reply to Dmitry TorokhovWhen a wireless device disconnects, its battery state is marked offline. However, when the device reconnects and sends an unsolicited unified battery status event (feature 0x1004), hidpp20_battery_event_1004() never updated hidpp->battery.online to true and did not include the online state in the changed check.
As a result, sysfs POWER_SUPPLY_PROP_ONLINE stayed 0, power supply listeners were not notified of the online transition, and the 0 to 1 online transition check in hidpp_raw_hidpp_event() failed to schedule reset_hi_res_work to reconfigure high-resolution scrolling on reconnect.
Furthermore, both feature 0x1000 and feature 0x1004 share the same hidpp->battery.feature_index, event ID 0x00, and return 0 from their event handlers. Because hidpp_raw_hidpp_event() previously called both handlers unconditionally, an event on a 0x1000 device also matched hidpp20_battery_event_1004(), corrupting the online state and decoded battery status.
Include !hidpp->battery.online in the changed check and mark hidpp->battery.online true when receiving a 0x1004 status event. Gate the event dispatch in hidpp_raw_hidpp_event() on HIDPP_CAPABILITY_UNIFIED_BATTERY so 0x1000 and 0x1004 events are routed to their respective handlers.
--- drivers/hid/hid-logitech-hidpp.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/hid/hid-logitech-hidpp.c +8 -5
@@ -1761,12 +1761,15 @@ static int hidpp20_battery_event_1004(struct hidpp_device *hidpp, status =hidpp20_unifiedbattery_map_status (hidpp, params[2 ], params[3 ]); level =hidpp20_unifiedbattery_map_level (hidpp, params[1 ]); - changed = status != hidpp->battery.status || + changed = !hidpp->battery.online || + status != hidpp->battery.status || (state_of_charge != hidpp->battery.capacity && hidpp->capabilities &HIDPP_CAPABILITY_BATTERY_PERCENTAGE ) || (level != hidpp->battery.level && hidpp->capabilities &HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS ); + hidpp->battery.online = true; +if (changed) { hidpp->battery.capacity = state_of_charge; hidpp->battery.status = status;
@@ -4200,10 +4203,10 @@ static int hidpp_raw_hidpp_event(struct hidpp_device *hidpp, u8 *data, last_online = hidpp->battery.online;if (hidpp->capabilities &HIDPP_CAPABILITY_HIDPP20_BATTERY ) { - ret =hidpp20_battery_event_1000 (hidpp, data, size); -if (ret !=0 ) -return ret; - ret =hidpp20_battery_event_1004 (hidpp, data, size); +if (hidpp->capabilities &HIDPP_CAPABILITY_UNIFIED_BATTERY ) + ret =hidpp20_battery_event_1004 (hidpp, data, size); +else + ret =hidpp20_battery_event_1000 (hidpp, data, size);if (ret !=0 )return ret; ret =hidpp_solar_battery_event (hidpp, data, size);
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH v3 13/14 HID: logitech-hidpp: fix K750 solar battery feature lookup and reconnect
In reply to Dmitry TorokhovIn hidpp_solar_request_battery_event(), the driver checked whether hidpp->battery.feature_index == 0xff instead of checking solar_feature_index, causing it to re-query the root feature table unnecessarily or misidentify whether the solar feature was resolved.
Furthermore, in hidpp_connect_event(), the HIDPP20_BATTERY block lacked a branch for HIDPP_QUIRK_CLASS_K750, causing wireless reconnects of a K750 keyboard to fall through to hidpp20_query_battery_info_1000() which fails because the K750 does not implement feature 0x1000.
Check solar_feature_index in hidpp_solar_request_battery_event() and re-enable solar battery reporting via the solar request helper on K750 reconnects.
--- drivers/hid/hid-logitech-hidpp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/hid/hid-logitech-hidpp.c +4 -2
@@ -2122,7 +2122,7 @@ static int hidpp_solar_request_battery_event(struct hidpp_device *hidpp)u8 params[2 ] = {1 ,1 };int ret; -if (hidpp->battery.feature_index ==0xff ) { +if (hidpp->battery.solar_feature_index ==0xff ) { ret =hidpp_root_get_feature (hidpp,HIDPP_PAGE_SOLAR_KEYBOARD , &hidpp->battery.solar_feature_index);
@@ -4582,7 +4582,9 @@ static void hidpp_connect_event(struct work_struct *work)else hidpp10_query_battery_status (hidpp); }else if (hidpp->capabilities &HIDPP_CAPABILITY_HIDPP20_BATTERY ) { -if (hidpp->capabilities &HIDPP_CAPABILITY_BATTERY_VOLTAGE ) +if (hidpp->quirks &HIDPP_QUIRK_CLASS_K750 ) +hidpp_solar_request_battery_event (hidpp); +else if (hidpp->capabilities &HIDPP_CAPABILITY_BATTERY_VOLTAGE )hidpp20_query_battery_voltage_info (hidpp);else if (hidpp->capabilities &HIDPP_CAPABILITY_UNIFIED_BATTERY )hidpp20_query_battery_info_1004 (hidpp);
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH v3 14/14 HID: logitech-hidpp: expose charge_type property for battery voltage feature
In reply to Dmitry TorokhovCommit be281368f297 ("hid-logitech-hidpp: read battery voltage from newer devices") added support for the 0x1001 battery voltage feature, populated battery->charge_type, and handled POWER_SUPPLY_PROP_CHARGE_TYPE in hidpp_battery_get_property(). However, it did not add a placeholder slot in hidpp_battery_props[] or register POWER_SUPPLY_PROP_CHARGE_TYPE in hidpp_initialize_battery() when HIDPP_CAPABILITY_BATTERY_VOLTAGE is set. Consequently, the charge_type attribute was never exposed via sysfs. Furthermore, hidpp20_battery_voltage_event() only checked whether voltage or status changed before updating cached battery values and notifying user space, ignoring changes in level and charge_type.
Additionally, hidpp20_battery_map_status_voltage() unconditionally set charge_type to standard (or fast/trickle) charging even when the device was discharging, full, not charging, or in an unknown status, and hidpp_connect_event() left charge_type stale on wireless disconnect.
Add a placeholder slot to hidpp_battery_props[], update the fixed property count in hidpp_initialize_battery(), append POWER_SUPPLY_PROP_CHARGE_TYPE when HIDPP_CAPABILITY_BATTERY_VOLTAGE is set, and include level and charge_type in the change detection condition in hidpp20_battery_voltage_event(). In hidpp20_battery_map_status_voltage(), map charge_type to unknown when status is unknown, to none when discharging, full, or not charging, and to standard, fast, or trickle only when charging. Reset charge_type to unknown on wireless disconnect in hidpp_connect_event().
--- drivers/hid/hid-logitech-hidpp.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-)
drivers/hid/hid-logitech-hidpp.c +22 -8
@@ -1428,12 +1428,17 @@ static int hidpp20_battery_map_status_voltage(u8 data[3], int *voltage,else status =POWER_SUPPLY_STATUS_DISCHARGING ; - *charge_type =POWER_SUPPLY_CHARGE_TYPE_STANDARD ; -if (test_bit (3 , &flags)) { - *charge_type =POWER_SUPPLY_CHARGE_TYPE_FAST ; - } -if (test_bit (4 , &flags)) { - *charge_type =POWER_SUPPLY_CHARGE_TYPE_TRICKLE ; +if (status ==POWER_SUPPLY_STATUS_CHARGING ) { +if (test_bit (4 , &flags)) + *charge_type =POWER_SUPPLY_CHARGE_TYPE_TRICKLE ; +else if (test_bit (3 , &flags)) + *charge_type =POWER_SUPPLY_CHARGE_TYPE_FAST ; +else + *charge_type =POWER_SUPPLY_CHARGE_TYPE_STANDARD ; + }else if (status ==POWER_SUPPLY_STATUS_UNKNOWN ) { + *charge_type =POWER_SUPPLY_CHARGE_TYPE_UNKNOWN ; + }else { + *charge_type =POWER_SUPPLY_CHARGE_TYPE_NONE ; }if (test_bit (5 , &flags)) { *level =POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL ;
@@ -1553,7 +1558,10 @@ static int hidpp20_battery_voltage_event(struct hidpp_device *hidpp, hidpp->battery.online = status !=POWER_SUPPLY_STATUS_NOT_CHARGING ; -if (voltage != hidpp->battery.voltage || status != hidpp->battery.status) { +if (voltage != hidpp->battery.voltage || + status != hidpp->battery.status || + level != hidpp->battery.level || + charge_type != hidpp->battery.charge_type) { hidpp->battery.voltage = voltage; hidpp->battery.capacity =hidpp20_map_battery_capacity (hidpp->hid_dev, voltage);
@@ -1795,6 +1803,7 @@ static enum power_supply_property hidpp_battery_props[] = {0 ,/* placeholder for POWER_SUPPLY_PROP_CAPACITY, */ 0 ,/* placeholder for POWER_SUPPLY_PROP_CAPACITY_LEVEL, */ 0 ,/* placeholder for POWER_SUPPLY_PROP_VOLTAGE_NOW, */ + 0, /* placeholder for POWER_SUPPLY_PROP_CHARGE_TYPE, */ }; static int hidpp_battery_get_property(struct power_supply *psy,
@@ -4398,7 +4407,7 @@ static int hidpp_initialize_battery(struct hidpp_device *hidpp)if (!battery_props)return -ENOMEM ; - num_battery_props =ARRAY_SIZE (hidpp_battery_props) -3 ; + num_battery_props =ARRAY_SIZE (hidpp_battery_props) -4 ; if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_MILEAGE || hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_PERCENTAGE ||
@@ -4416,6 +4425,10 @@ static int hidpp_initialize_battery(struct hidpp_device *hidpp) battery_props[num_battery_props++] =POWER_SUPPLY_PROP_VOLTAGE_NOW ; +if (hidpp->capabilities &HIDPP_CAPABILITY_BATTERY_VOLTAGE ) + battery_props[num_battery_props++] = +POWER_SUPPLY_PROP_CHARGE_TYPE ; + battery = &hidpp->battery; n =atomic_inc_return (&battery_no) -1 ;
@@ -4511,6 +4524,7 @@ static void hidpp_connect_event(struct work_struct *work) hidpp->battery.online = false; hidpp->battery.status =POWER_SUPPLY_STATUS_UNKNOWN ; hidpp->battery.level =POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN ; + hidpp->battery.charge_type =POWER_SUPPLY_CHARGE_TYPE_UNKNOWN ;power_supply_changed (hidpp->battery.ps); }return ;
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
[email protected]
AI reviewRe: [PATCH v3 14/14] HID: logitech-hidpp: expose charge_type property for battery voltage feature
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] HID: logitech-hidpp: unexposed capacity_level for battery voltage feature --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] HID: logitech-hidpp: unexposed capacity_level for battery voltage feature
--
commit b4d76869d226ccd595e36b0b248b61047a51210e
Author: Dmitry Torokhov <[email protected]>
HID: logitech-hidpp: expose charge_type property for battery voltage feature
This commit exposes POWER_SUPPLY_PROP_CHARGE_TYPE for devices supporting the 0x1001 battery voltage feature, refines charge_type mapping based on battery status, updates change detection in hidpp20_battery_voltage_event(), and resets charge_type on disconnect.
Quoted 4 lines
drivers/hid/hid-logitech-hidpp.c +0
-0
[ ... ]
Quoted 12 lines
drivers/hid/hid-logitech-hidpp.c +4
-1@@ -1553,7 +1558,10 @@ static int hidpp20_battery_voltage_event(struct hidpp_device *hidpp, hidpp->battery.online = status !=POWER_SUPPLY_STATUS_NOT_CHARGING ; -if (voltage != hidpp->battery.voltage || status != hidpp->battery.status) { +if (voltage != hidpp->battery.voltage || + status != hidpp->battery.status || + level != hidpp->battery.level || + charge_type != hidpp->battery.charge_type) { hidpp->battery.voltage = voltage; hidpp->battery.capacity =hidpp20_map_battery_capacity (hidpp->hid_dev, voltage);
[ ... ]
drivers/hid/hid-logitech-hidpp.c static int hidpp_initialize_battery(struct hidpp_device *hidpp) · line 4430
Quoted 7 lines
drivers/hid/hid-logitech-hidpp.c +3
-0@@ -4416,6 +4425,10 @@ static int hidpp_initialize_battery(struct hidpp_device *hidpp) battery_props[num_battery_props++] =POWER_SUPPLY_PROP_VOLTAGE_NOW ; +if (hidpp->capabilities &HIDPP_CAPABILITY_BATTERY_VOLTAGE ) + battery_props[num_battery_props++] = +POWER_SUPPLY_PROP_CHARGE_TYPE ;
[Severity: Medium]
Should hidpp_initialize_battery() also register POWER_SUPPLY_PROP_CAPACITY_LEVEL when HIDPP_CAPABILITY_BATTERY_VOLTAGE is set?
hidpp20_battery_map_status_voltage() populates battery.level (setting POWER_SUPPLY_CAPACITY_LEVEL_FULL when full and POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL when bit 5 of flags is set), and hidpp20_battery_voltage_event() now checks level != hidpp->battery.level before calling power_supply_changed(). However, hidpp_initialize_battery() only appends POWER_SUPPLY_PROP_CAPACITY_LEVEL to battery_props[] for HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS:
drivers/hid/hid-logitech-hidpp.c:hidpp_initialize_battery() {
...
if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS)
battery_props[num_battery_props++] =
POWER_SUPPLY_PROP_CAPACITY_LEVEL;
...
}As a result, capacity_level is never exposed in sysfs for 0x1001 battery voltage devices, and a change in battery.level alone (such as the critical flag toggling at the same voltage and status) emits a power_supply_changed() uevent with no user-visible property change.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=14
Quoted 56 lines · Dmitry Torokhov
Per Jiri Kosina's request, the v2 series has been split into this 14-patch bug-fix series targeting v7.4 and a separate 18-patch rework and cleanup series targeting v7.5. The open-evdev-across-unbind force-feedback teardown use-after-free (v2 patch 22/33) is now handled in input core ("Input: destroy force-feedback device on input unregistration") and has been dropped.
This series starts from Gideon Heinz's report of Logitech G920 force-feedback initialization timing out in v7.3 and addresses several pre-existing bugs and lifetime races in hid-logitech-hidpp.
The force-feedback and teardown fixes temporarily enable device I/O around
g920_get_config()inhidpp_input_configured(), switchhidpp_ff_queue_work()toGFP_ATOMICsince callbacks run under the input event spinlock, drain the G920 FF workqueue before closing the HID transport on input close, synchronously disable driver work items and disconnect input devices with device I/O enabled before stopping the transport on removal and probe failure, avoid storing anERR_PTRinbattery->pson registration failure, avoid NULL pointer subtraction in the HID++ 1.0 consumer keys report fixup, and fix an off-by-one in G920 slot tracking that made the 63rd user effect in slot 64 unusable and leaked it across reopen.The transport and battery fixes update
hidpp_send_message_sync()to stop retrying timeouts and transport errors, initialize response buffers before publishingsend_receive_bufto eliminate races with concurrent or spurious packets, fix HID++ 1.0 battery mileage event parsing and state updates, properly propagate negative errors in ADC measurement (0x1f20) queries, mark devices online on unified battery (0x1004) events while gating 0x1000/0x1004 dispatch, fix K750 solar battery feature lookup and reconnect handling, and expose and correctly map thecharge_typeproperty for the battery voltage (0x1001) feature.Note that device removal teardown still has limitations due to how HID core's
hid_device_io_start()andhid_device_io_stop()(viadriver_input_lock) gate both driver raw command/response I/O and subdriver event forwarding, disabling I/O before .remove() andhid_disconnect(). For instance,HIDPP_QUIRK_DELAYED_INITdevm-managed input devices are still unregistered afterhid_hw_stop(), andhidpp_connect_event()publisheshidpp->inputbefore input registration completes. Resolving these teardown edge cases cleanly will require follow-up work in HID core and driver input registration.Thanks.
Signed-off-by Dmitry Torokhov <[email protected]>---
Changes in v3:
- Split out the 14 bug fixes into this series for v7.4 per Jiri Kosina, moving the 18 rework and cleanup patches into a separate series for v7.5 and dropping v2 patch 22/33 in favor of input core teardown.
- Collected Tested-by tags from Gideon Heinz on all unchanged patches in this series (omitted from patches 12 and 14 which were updated after v2 testing).
- Gated event dispatch inhidpp_raw_hidpp_event()onHIDPP_CAPABILITY_UNIFIED_BATTERYso0x1000and0x1004events are
Quoted 8 lines
routed to their respective handlers instead of cross-corrupting
battery state.
- Inhidpp20_battery_map_status_voltage(), setcharge_typeto unknown
when status is unknown, to none when discharging, full, or not
charging, and to standard, fast, or trickle only when charging.
- Resetcharge_typeto unknown on wireless disconnect in
hidpp_connect_event().
- Link to v2: https://patch.msgid.link/[email protected]
Applied to hid.git#for-7.4/upstream-fixes.
Thanks,
Signature · 2 lines
Jiri Kosina SUSE Labs