linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] i2c: virtio: Avoid hang by using interruptible completion wait
@ 2025-07-03 11:31 Viresh Kumar
  2025-07-11 14:51 ` Andi Shyti
  2025-07-14 21:21 ` Andi Shyti
  0 siblings, 2 replies; 4+ messages in thread
From: Viresh Kumar @ 2025-07-03 11:31 UTC (permalink / raw)
  To: Viresh Kumar, Chen, Jian Jun, Andi Shyti
  Cc: Vincent Guittot, linux-i2c, virtualization, linux-kernel

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] i2c: virtio: Avoid hang by using interruptible completion wait
  2025-07-03 11:31 [PATCH] i2c: virtio: Avoid hang by using interruptible completion wait Viresh Kumar
@ 2025-07-11 14:51 ` Andi Shyti
  2025-07-14  3:39   ` Viresh Kumar
  2025-07-14 21:21 ` Andi Shyti
  1 sibling, 1 reply; 4+ messages in thread
From: Andi Shyti @ 2025-07-11 14:51 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Chen, Jian Jun, Vincent Guittot, linux-i2c, virtualization,
	linux-kernel

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] i2c: virtio: Avoid hang by using interruptible completion wait
  2025-07-11 14:51 ` Andi Shyti
@ 2025-07-14  3:39   ` Viresh Kumar
  0 siblings, 0 replies; 4+ messages in thread
From: Viresh Kumar @ 2025-07-14  3:39 UTC (permalink / raw)
  To: Andi Shyti
  Cc: Chen, Jian Jun, Vincent Guittot, linux-i2c, virtualization,
	linux-kernel

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] i2c: virtio: Avoid hang by using interruptible completion wait
  2025-07-03 11:31 [PATCH] i2c: virtio: Avoid hang by using interruptible completion wait Viresh Kumar
  2025-07-11 14:51 ` Andi Shyti
@ 2025-07-14 21:21 ` Andi Shyti
  1 sibling, 0 replies; 4+ messages in thread
From: Andi Shyti @ 2025-07-14 21:21 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Chen, Jian Jun, Vincent Guittot, linux-i2c, virtualization,
	linux-kernel

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-07-14 21:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-03 11:31 [PATCH] i2c: virtio: Avoid hang by using interruptible completion wait Viresh Kumar
2025-07-11 14:51 ` Andi Shyti
2025-07-14  3:39   ` Viresh Kumar
2025-07-14 21:21 ` Andi Shyti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).