[PATCH] i2c: virtio: Avoid hang by using interruptible completion wait

Viresh Kumar posted 1 patch 3 months ago
drivers/i2c/busses/i2c-virtio.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
[PATCH] i2c: virtio: Avoid hang by using interruptible completion wait
Posted by Viresh Kumar 3 months ago
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.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/i2c/busses/i2c-virtio.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/i2c/busses/i2c-virtio.c b/drivers/i2c/busses/i2c-virtio.c
index 2a351f961b89..c8c40ff9765d 100644
--- a/drivers/i2c/busses/i2c-virtio.c
+++ b/drivers/i2c/busses/i2c-virtio.c
@@ -116,15 +116,16 @@ static int virtio_i2c_complete_reqs(struct virtqueue *vq,
 	for (i = 0; i < num; i++) {
 		struct virtio_i2c_req *req = &reqs[i];
 
-		wait_for_completion(&req->completion);
-
-		if (!failed && req->in_hdr.status != VIRTIO_I2C_MSG_OK)
-			failed = true;
+		if (!failed) {
+			if (wait_for_completion_interruptible(&req->completion))
+				failed = true;
+			else if (req->in_hdr.status != VIRTIO_I2C_MSG_OK)
+				failed = true;
+			else
+				j++;
+		}
 
 		i2c_put_dma_safe_msg_buf(reqs[i].buf, &msgs[i], !failed);
-
-		if (!failed)
-			j++;
 	}
 
 	return j;
-- 
2.31.1.272.g89b43f80a514
Re: [PATCH] i2c: virtio: Avoid hang by using interruptible completion wait
Posted by Andi Shyti 2 months, 3 weeks ago
Hi Viresh,

On Thu, Jul 03, 2025 at 05:01:02PM +0530, Viresh Kumar wrote:
> 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.
> 
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>

merged to i2c/i2c-host-fixes.

Thanks,
Andi
Re: [PATCH] i2c: virtio: Avoid hang by using interruptible completion wait
Posted by Andi Shyti 2 months, 4 weeks ago
Hi Viresh,

On Thu, Jul 03, 2025 at 05:01:02PM +0530, Viresh Kumar wrote:
> 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.
> 
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>

Do we need the Fixes tag here?

Thanks,
Andi
Re: [PATCH] i2c: virtio: Avoid hang by using interruptible completion wait
Posted by Viresh Kumar 2 months, 3 weeks ago
On 11-07-25, 16:51, Andi Shyti wrote:
> Hi Viresh,
> 
> On Thu, Jul 03, 2025 at 05:01:02PM +0530, Viresh Kumar wrote:
> > 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.
> > 
> > Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> 
> Do we need the Fixes tag here?

Maybe we can add:

Fixes: 84e1d0bf1d71 ("i2c: virtio: disable timeout handling")

-- 
viresh