Skip to content

Commit 9c0f59e

Browse files
covanamJiri Kosina
authored andcommitted
HID: i2c-hid: remove I2C_HID_READ_PENDING flag to prevent lock-up
The flag I2C_HID_READ_PENDING is used to serialize I2C operations. However, this is not necessary, because I2C core already has its own locking for that. More importantly, this flag can cause a lock-up: if the flag is set in i2c_hid_xfer() and an interrupt happens, the interrupt handler (i2c_hid_irq) will check this flag and return immediately without doing anything, then the interrupt handler will be invoked again in an infinite loop. Since interrupt handler is an RT task, it takes over the CPU and the flag-clearing task never gets scheduled, thus we have a lock-up. Delete this unnecessary flag. Reported-and-tested-by: Eva Kurchatova <[email protected]> Closes: https://lore.kernel.org/r/CA+eeCSPUDpUg76ZO8dszSbAGn+UHjcyv8F1J-CUPVARAzEtW9w@mail.gmail.com Fixes: 4a200c3 ("HID: i2c-hid: introduce HID over i2c specification implementation") Cc: <[email protected]> Signed-off-by: Nam Cao <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 3e78a6c commit 9c0f59e

File tree

1 file changed

+0
-9
lines changed

1 file changed

+0
-9
lines changed

drivers/hid/i2c-hid/i2c-hid-core.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
/* flags */
6565
#define I2C_HID_STARTED 0
6666
#define I2C_HID_RESET_PENDING 1
67-
#define I2C_HID_READ_PENDING 2
6867

6968
#define I2C_HID_PWR_ON 0x00
7069
#define I2C_HID_PWR_SLEEP 0x01
@@ -190,15 +189,10 @@ static int i2c_hid_xfer(struct i2c_hid *ihid,
190189
msgs[n].len = recv_len;
191190
msgs[n].buf = recv_buf;
192191
n++;
193-
194-
set_bit(I2C_HID_READ_PENDING, &ihid->flags);
195192
}
196193

197194
ret = i2c_transfer(client->adapter, msgs, n);
198195

199-
if (recv_len)
200-
clear_bit(I2C_HID_READ_PENDING, &ihid->flags);
201-
202196
if (ret != n)
203197
return ret < 0 ? ret : -EIO;
204198

@@ -556,9 +550,6 @@ static irqreturn_t i2c_hid_irq(int irq, void *dev_id)
556550
{
557551
struct i2c_hid *ihid = dev_id;
558552

559-
if (test_bit(I2C_HID_READ_PENDING, &ihid->flags))
560-
return IRQ_HANDLED;
561-
562553
i2c_hid_get_input(ihid);
563554

564555
return IRQ_HANDLED;

0 commit comments

Comments
 (0)