Skip to content

Commit a663b3c

Browse files
vireshkAndi Shyti
authored andcommitted
i2c: virtio: Avoid hang by using interruptible completion wait
The current implementation uses wait_for_completion(), which can cause the caller to hang indefinitely if the transfer never completes. Switch to wait_for_completion_interruptible() so that the operation can be interrupted by signals. Fixes: 84e1d0b ("i2c: virtio: disable timeout handling") Signed-off-by: Viresh Kumar <[email protected]> Cc: <[email protected]> # v5.16+ Signed-off-by: Andi Shyti <[email protected]> Link: https://lore.kernel.org/r/b8944e9cab8eb959d888ae80add6f2a686159ba2.1751541962.git.viresh.kumar@linaro.org
1 parent 56344e2 commit a663b3c

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

drivers/i2c/busses/i2c-virtio.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,16 @@ static int virtio_i2c_complete_reqs(struct virtqueue *vq,
116116
for (i = 0; i < num; i++) {
117117
struct virtio_i2c_req *req = &reqs[i];
118118

119-
wait_for_completion(&req->completion);
120-
121-
if (!failed && req->in_hdr.status != VIRTIO_I2C_MSG_OK)
122-
failed = true;
119+
if (!failed) {
120+
if (wait_for_completion_interruptible(&req->completion))
121+
failed = true;
122+
else if (req->in_hdr.status != VIRTIO_I2C_MSG_OK)
123+
failed = true;
124+
else
125+
j++;
126+
}
123127

124128
i2c_put_dma_safe_msg_buf(reqs[i].buf, &msgs[i], !failed);
125-
126-
if (!failed)
127-
j++;
128129
}
129130

130131
return j;

0 commit comments

Comments
 (0)