Commit a663b3c4 authored by Viresh Kumar's avatar Viresh Kumar Committed by Andi Shyti
Browse files

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: 84e1d0bf ("i2c: virtio: disable timeout handling")
Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
Cc: <stable@vger.kernel.org> # v5.16+
Signed-off-by: default avatarAndi Shyti <andi.shyti@kernel.org>
Link: https://lore.kernel.org/r/b8944e9cab8eb959d888ae80add6f2a686159ba2.1751541962.git.viresh.kumar@linaro.org
parent 56344e24
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -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)
		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;