Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
e001361
hid: ipts: Fix double list_del race in ipts_mei_search()
Sep 3, 2026
410814a
hid: ipts: Reference-count the context and free it after its last user
loafecho Nov 3, 2026
224f261
hid: ipts: Bound the wait for the receiver thread on stop
loafecho Nov 3, 2026
9df2c85
hid: ipts: Never wait for the message lock, a reply or a send forever
loafecho Nov 3, 2026
e7f4e4e
hid: ipts: Always remove the HID device when stopping
loafecho Nov 3, 2026
c3e3cb4
hid: ipts: Stop the receiver loops promptly and wait for the stop con…
loafecho Nov 3, 2026
011d585
hid: ipts: Run the EDS1 mode-switch restart from a work item
loafecho Nov 3, 2026
17b09af
hid: ipts: Wait for running HID callbacks before stopping
loafecho Nov 3, 2026
6e15adc
hid: ipts: Undo a failed start
loafecho Nov 3, 2026
7001787
hid: ipts: Keep each FEEDBACK reply with the command it answers
loafecho Nov 14, 2026
f8e0bf5
hid: ipts: Drop stale responses when starting the device
Nov 2, 2026
f6bc791
hid: ipts: Restart the device if switching modes failed
Nov 1, 2026
43a7183
hid: ipts: Reconnect to the ME when restarting after a failed mode sw…
Nov 2, 2026
9bc1f5a
hid: ipts: Read every response that is ready when one arrives
loafecho Nov 15, 2026
cf18c1f
hid: ipts: Stop the device before every restart attempt
Nov 16, 2026
9bdb25f
hid: ipts: Retry a failed restart in the mode that was asked for
Nov 16, 2026
72edf1f
hid: ipts: Accept EDS1 mode switches while the device restarts
Nov 16, 2026
0c6f05d
hid: ipts: Count the ME reconnect in how long remove waits for a restart
Nov 16, 2026
61ff821
hid: ipts: Keep a blocked device stopped, and check the EDS1 mode
loafecho Nov 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion drivers/hid/ipts/cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @rsp: The address that the received response will be copied to.
* @timeout: How many milliseconds the function will wait at most.
*
* A negative timeout means to wait forever.
* A timeout of 0 means to check once and return.
*
* Returns: 0 on success, <0 on error, -EAGAIN if no response has been received.
*/
Expand Down
93 changes: 93 additions & 0 deletions drivers/hid/ipts/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
#ifndef IPTS_CONTEXT_H
#define IPTS_CONTEXT_H

#include <linux/atomic.h>
#include <linux/completion.h>
#include <linux/device.h>
#include <linux/hid.h>
#include <linux/kref.h>
#include <linux/mei_cl_bus.h>
#include <linux/mutex.h>
#include <linux/sched.h>
#include <linux/types.h>
#include <linux/wait.h>
#include <linux/workqueue.h>

#include "mei.h"
#include "resources.h"
Expand All @@ -33,6 +37,13 @@ struct ipts_context {
struct mutex feature_lock;
struct completion feature_event;

/*
* Allows one FEEDBACK command at a time, held from the send until its reply is taken,
* and guards the hid2me buffer a hid2me FEEDBACK hands to the device. GET_FEATURE takes
* it while holding feature_lock; never take feature_lock while holding it.
*/
struct mutex feedback_lock;

/*
* These are not inside of struct ipts_resources
* because they don't own the memory they point to.
Expand All @@ -43,10 +54,92 @@ struct ipts_context {
bool hid_active;
struct hid_device *hid;

/*
* Number of HID callbacks currently running driver code. Stopping waits, bounded,
* until it drops to 0.
*/
atomic_t hid_users;
wait_queue_head_t hid_users_wq;

/*
* Serializes a restart with remove. Restarts requested from a HID callback (the EDS1
* mode switch) run from restart_work, never inside the callback.
*/
struct mutex ctl_lock;
struct delayed_work restart_work;
bool removing;

/*
* When a restart fails to start the device again: how many restarts were tried.
* Retries run from restart_work, too.
*/
unsigned int restart_attempts;

/*
* EDS1: the mode that the last mode switch asked for. restart_work applies it to mode
* under ctl_lock, so a switch that arrives during a restart does not change the mode
* under a start that is running.
*/
enum ipts_mode requested_mode;

/*
* Set when a stop for a restart failed or leaked the buffers: the device must not be
* started again, and mode switches are refused, until the next probe.
*/
bool restart_blocked;

/*
* Freed when the last reference is dropped. Probe holds one (dropped by devres), and the
* receiver thread, the HID device, every holder of message_lock and a queued restart
* hold one each.
*/
struct kref refcount;

/*
* Users other than probe. ipts_remove() waits, bounded, for this to reach zero. That
* narrows the window in which the module code is freed under a user that is about to
* return, but does not close it: the last user wakes remove from inside its own put.
*/
atomic_t users;
wait_queue_head_t users_wq;

struct ipts_device_info info;
struct ipts_resources resources;

/*
* Set by a stop whose wait for running HID callbacks timed out: a callback that outlived
* the wait may have sent the device a command after it confirmed the stop. The buffers
* are then leaked instead of freed, by that stop or, if it kept everything, by the next.
*/
bool buffers_unconfirmed;

struct ipts_thread receiver_loop;
};

void ipts_context_release(struct kref *refcount);

/*
* Every user of the context (the receiver thread, the HID device, a holder of message_lock, a
* queued restart) takes a reference, so the context is freed only after the last user is gone.
*/
static inline void ipts_context_get(struct ipts_context *ipts)
{
if (!ipts)
return;

kref_get(&ipts->refcount);
atomic_inc(&ipts->users);
}

static inline void ipts_context_put(struct ipts_context *ipts)
{
if (!ipts)
return;

if (atomic_dec_and_test(&ipts->users))
wake_up_all(&ipts->users_wq);

kref_put(&ipts->refcount, ipts_context_release);
}

#endif /* IPTS_CONTEXT_H */
Loading