From: Hans Verkuil <hverkuil+cisco@kernel.org>
To: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>,
dmitry.torokhov@gmail.com
Cc: floe@butterbrot.org, linux-input@vger.kernel.org,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH v1 1/2] Input: sur40 - don't wait for buffers nothing will complete
Date: Wed, 30 Sep 2026 10:04:35 +0200 [thread overview]
Message-ID: <d2c9da65-ea4a-403e-8512-26897e0bc26f@kernel.org> (raw)
In-Reply-To: <20260920113949.12726-2-ngocthang2710.1999@gmail.com>
On 20/09/2026 13:39, Nguyen Ngoc Thang wrote:
> sur40_stop_streaming() calls vb2_wait_for_all_buffers() before handing
> the queued buffers back. Those buffers are only completed from the input
> poll callback, which is gone once the device is unplugged. Closing a
> video node that is still streaming after a disconnect then sleeps
> forever in vb2_wait_for_all_buffers():
>
> vb2_wait_for_all_buffers+0x20f/0x330
> sur40_stop_streaming+0x45/0x310
> __vb2_queue_cancel+0xc5/0xf70
> vb2_core_streamoff+0x5d/0x180
> __vb2_cleanup_fileio+0x6e/0x190
> vb2_core_queue_release+0x1f/0x190
> _vb2_fop_release+0xe8/0x280
> v4l2_release+0x280/0x430
>
> It has not been noticed so far because sur40_disconnect() frees the
> device state under the open file, and the close then crashes earlier.
>
> Return the queued buffers first. A buffer that sur40_process_video()
> has already taken off the list still completes by itself, so the wait
> afterwards only covers that one.
>
> Fixes: 6a8588156657 ("[media] sur40: fix occasional oopses on device close")
> Cc: stable@vger.kernel.org
> Signed-off-by: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>
> ---
> drivers/input/touchscreen/sur40.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/input/touchscreen/sur40.c b/drivers/input/touchscreen/sur40.c
> index 09d8c5f8d09f..7020bcf9b81a 100644
> --- a/drivers/input/touchscreen/sur40.c
> +++ b/drivers/input/touchscreen/sur40.c
> @@ -929,11 +929,11 @@ static int sur40_start_streaming(struct vb2_queue *vq, unsigned int count)
> static void sur40_stop_streaming(struct vb2_queue *vq)
> {
> struct sur40_state *sur40 = vb2_get_drv_priv(vq);
> - vb2_wait_for_all_buffers(vq);
> - sur40->sequence = -1;
>
> - /* Release all active buffers */
> + /* Release queued buffers first: nothing completes them after unplug */
> return_all_buffers(sur40, VB2_BUF_STATE_ERROR);
> + vb2_wait_for_all_buffers(vq);
> + sur40->sequence = -1;
> }
>
> /* V4L ioctl */
I think you should make one more change: replace the video_unregister_device calls by
vb2_video_unregister_device(). This ensures that at unregister time all streaming is
canceled and stop_streaming is called.
Having streaming continue after unregistering a device is in general not a good idea,
which is why we added that vb2_video_unregister_device call.
I think you still need to have that change in stop_streaming for this specific driver,
but it might be worth testing without it.
Regards,
Hans
next prev parent reply other threads:[~2026-09-30 8:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-20 11:39 [PATCH v1 0/2] Input: sur40 - fix UAF/hang on closing the video node after unplug Nguyen Ngoc Thang
2026-09-20 11:39 ` [PATCH v1 1/2] Input: sur40 - don't wait for buffers nothing will complete Nguyen Ngoc Thang
2026-09-30 8:04 ` Hans Verkuil [this message]
2026-09-20 11:39 ` [PATCH v1 2/2] Input: sur40 - keep device state alive until the video node is released Nguyen Ngoc Thang
2026-09-30 8:05 ` Hans Verkuil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d2c9da65-ea4a-403e-8512-26897e0bc26f@kernel.org \
--to=hverkuil+cisco@kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=floe@butterbrot.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=ngocthang2710.1999@gmail.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®