From patchwork Tue Dec 1 12:44:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 336353 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35E90C64E90 for ; Tue, 1 Dec 2020 12:45:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CC0D22087C for ; Tue, 1 Dec 2020 12:45:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=xs4all.nl header.i=@xs4all.nl header.b="aNw2u9WB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387460AbgLAMpe (ORCPT ); Tue, 1 Dec 2020 07:45:34 -0500 Received: from lb3-smtp-cloud8.xs4all.net ([194.109.24.29]:45329 "EHLO lb3-smtp-cloud8.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726930AbgLAMpd (ORCPT ); Tue, 1 Dec 2020 07:45:33 -0500 Received: from cust-b5b5937f ([IPv6:fc0c:c16d:66b8:757f:c639:739b:9d66:799d]) by smtp-cloud8.xs4all.net with ESMTPA id k51SkssSADuFjk51Wk2RYB; Tue, 01 Dec 2020 13:44:50 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xs4all.nl; s=s2; t=1606826690; bh=lpFvz7FMsArL/DJgewT5bpfZA5TI4nFcVt2r/u2mcvw=; h=From:To:Subject:Date:Message-Id:MIME-Version:From:Subject; b=aNw2u9WBqlpu5whjbAnzPKBTLRoh0jwAQpKvYxMFFgRAupFlNVKjR4KRKa75Mql5a N920PhMHPAAW/UiixdnXLd9WrOZpd/dE1vq7MrJGg55VtXJ827QJk36DSANDk+0Wu1 r3SKb4JphpChEcy5v1J1zU/penxlfHK6Ug+7ZUN3N5WZbEqnzXLonXhpe68wC77J1D GvLWMCizZLaBNpm6vVTs9WdcH9hRz0Dni7WQUC/5RES/4/h5rgagj14pEqtXK2P6lG wrtLRHr2tlRMqy1pVHhkS5ort2gmUC7/MQADZpWzHqiGuZAfAaDWhOnPPrgDY01Dg2 5HihPPD9masOg== From: Hans Verkuil To: linux-media@vger.kernel.org Cc: Alexandre Courbot , Tomasz Figa , Marek Szyprowski , Hans Verkuil Subject: [PATCHv3 1/7] vivid: fix 'disconnect' error injection Date: Tue, 1 Dec 2020 13:44:40 +0100 Message-Id: <20201201124446.448595-2-hverkuil-cisco@xs4all.nl> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201201124446.448595-1-hverkuil-cisco@xs4all.nl> References: <20201201124446.448595-1-hverkuil-cisco@xs4all.nl> MIME-Version: 1.0 X-CMAE-Envelope: MS4xfFkHQGEe/WNE17j2Pqpap/I6PUyHGeDV+XAwspn8n04YoldWB3SG1os5YmmaHEO8O2DYHvzAsTuGAy9KEibQhJWP+8d2KtFBGo89vNSkFYVL3bNJ7Wns R+MjOyFFvIlFZW/IF5Vm/I/qmJaJUznueuAiax50umMA1t+Ab4zntMB743pKwzi2N1aoZ//PQXGFJcdTp92MGo7uu45RqhfnPfwrlzJFpgLP3EwO7ryrXONY wutBsthjqJGTxmb/ootsXemf7eR8V8OFCU7tJfTLTiHLNx/ouN4jgeNf/pIQiqVewUZeJIHWRXN2Te6Fx/DpW9dERVvRdNc9nCe9BUOoyKI= Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The 'disconnect' error injection functionality suffered from bit rot. New device nodes were added without updating vivid_user_gen_s_ctrl(), so that function had to be updated for the new device nodes. Also, vivid didn't check if specific device nodes were actually ever created, so the vivid_is_last_user() would fail on that (it would return true instead of false in that case). Finally, selecting Disconnect, then unbind the vivid driver would fail since the remove() would think that the device nodes were already unregistered. Keep track of whether disconnect was pressed and re-register the device nodes in remove() before doing the real unregister. Signed-off-by: Hans Verkuil --- drivers/media/test-drivers/vivid/vivid-core.c | 65 ++++++++++++------- drivers/media/test-drivers/vivid/vivid-core.h | 1 + .../media/test-drivers/vivid/vivid-ctrls.c | 29 ++++++--- 3 files changed, 65 insertions(+), 30 deletions(-) diff --git a/drivers/media/test-drivers/vivid/vivid-core.c b/drivers/media/test-drivers/vivid/vivid-core.c index aa8d350fd682..5ddd31fdf102 100644 --- a/drivers/media/test-drivers/vivid/vivid-core.c +++ b/drivers/media/test-drivers/vivid/vivid-core.c @@ -547,11 +547,13 @@ static int vivid_s_fmt_cap_mplane(struct file *file, void *priv, return vidioc_s_fmt_vid_cap_mplane(file, priv, f); } -static bool vivid_is_in_use(struct video_device *vdev) +static bool vivid_is_in_use(bool valid, struct video_device *vdev) { unsigned long flags; bool res; + if (!valid) + return false; spin_lock_irqsave(&vdev->fh_lock, flags); res = !list_empty(&vdev->fh_list); spin_unlock_irqrestore(&vdev->fh_lock, flags); @@ -560,20 +562,45 @@ static bool vivid_is_in_use(struct video_device *vdev) static bool vivid_is_last_user(struct vivid_dev *dev) { - unsigned uses = vivid_is_in_use(&dev->vid_cap_dev) + - vivid_is_in_use(&dev->vid_out_dev) + - vivid_is_in_use(&dev->vbi_cap_dev) + - vivid_is_in_use(&dev->vbi_out_dev) + - vivid_is_in_use(&dev->sdr_cap_dev) + - vivid_is_in_use(&dev->radio_rx_dev) + - vivid_is_in_use(&dev->radio_tx_dev) + - vivid_is_in_use(&dev->meta_cap_dev) + - vivid_is_in_use(&dev->meta_out_dev) + - vivid_is_in_use(&dev->touch_cap_dev); + unsigned uses = vivid_is_in_use(dev->has_vid_cap, &dev->vid_cap_dev) + + vivid_is_in_use(dev->has_vid_out, &dev->vid_out_dev) + + vivid_is_in_use(dev->has_vbi_cap, &dev->vbi_cap_dev) + + vivid_is_in_use(dev->has_vbi_out, &dev->vbi_out_dev) + + vivid_is_in_use(dev->has_radio_rx, &dev->radio_rx_dev) + + vivid_is_in_use(dev->has_radio_tx, &dev->radio_tx_dev) + + vivid_is_in_use(dev->has_sdr_cap, &dev->sdr_cap_dev) + + vivid_is_in_use(dev->has_meta_cap, &dev->meta_cap_dev) + + vivid_is_in_use(dev->has_meta_out, &dev->meta_out_dev) + + vivid_is_in_use(dev->has_touch_cap, &dev->touch_cap_dev); return uses == 1; } +static void vivid_reconnect(struct vivid_dev *dev) +{ + if (dev->has_vid_cap) + set_bit(V4L2_FL_REGISTERED, &dev->vid_cap_dev.flags); + if (dev->has_vid_out) + set_bit(V4L2_FL_REGISTERED, &dev->vid_out_dev.flags); + if (dev->has_vbi_cap) + set_bit(V4L2_FL_REGISTERED, &dev->vbi_cap_dev.flags); + if (dev->has_vbi_out) + set_bit(V4L2_FL_REGISTERED, &dev->vbi_out_dev.flags); + if (dev->has_radio_rx) + set_bit(V4L2_FL_REGISTERED, &dev->radio_rx_dev.flags); + if (dev->has_radio_tx) + set_bit(V4L2_FL_REGISTERED, &dev->radio_tx_dev.flags); + if (dev->has_sdr_cap) + set_bit(V4L2_FL_REGISTERED, &dev->sdr_cap_dev.flags); + if (dev->has_meta_cap) + set_bit(V4L2_FL_REGISTERED, &dev->meta_cap_dev.flags); + if (dev->has_meta_out) + set_bit(V4L2_FL_REGISTERED, &dev->meta_out_dev.flags); + if (dev->has_touch_cap) + set_bit(V4L2_FL_REGISTERED, &dev->touch_cap_dev.flags); + dev->disconnect_error = false; +} + static int vivid_fop_release(struct file *file) { struct vivid_dev *dev = video_drvdata(file); @@ -581,23 +608,15 @@ static int vivid_fop_release(struct file *file) mutex_lock(&dev->mutex); if (!no_error_inj && v4l2_fh_is_singular_file(file) && - !video_is_registered(vdev) && vivid_is_last_user(dev)) { + dev->disconnect_error && !video_is_registered(vdev) && + vivid_is_last_user(dev)) { /* * I am the last user of this driver, and a disconnect * was forced (since this video_device is unregistered), * so re-register all video_device's again. */ v4l2_info(&dev->v4l2_dev, "reconnect\n"); - set_bit(V4L2_FL_REGISTERED, &dev->vid_cap_dev.flags); - set_bit(V4L2_FL_REGISTERED, &dev->vid_out_dev.flags); - set_bit(V4L2_FL_REGISTERED, &dev->vbi_cap_dev.flags); - set_bit(V4L2_FL_REGISTERED, &dev->vbi_out_dev.flags); - set_bit(V4L2_FL_REGISTERED, &dev->sdr_cap_dev.flags); - set_bit(V4L2_FL_REGISTERED, &dev->radio_rx_dev.flags); - set_bit(V4L2_FL_REGISTERED, &dev->radio_tx_dev.flags); - set_bit(V4L2_FL_REGISTERED, &dev->meta_cap_dev.flags); - set_bit(V4L2_FL_REGISTERED, &dev->meta_out_dev.flags); - set_bit(V4L2_FL_REGISTERED, &dev->touch_cap_dev.flags); + vivid_reconnect(dev); } mutex_unlock(&dev->mutex); if (file->private_data == dev->overlay_cap_owner) @@ -1968,6 +1987,8 @@ static int vivid_remove(struct platform_device *pdev) if (!dev) continue; + if (dev->disconnect_error) + vivid_reconnect(dev); #ifdef CONFIG_MEDIA_CONTROLLER media_device_unregister(&dev->mdev); #endif diff --git a/drivers/media/test-drivers/vivid/vivid-core.h b/drivers/media/test-drivers/vivid/vivid-core.h index 99e69b8f770f..9c2d1470b597 100644 --- a/drivers/media/test-drivers/vivid/vivid-core.h +++ b/drivers/media/test-drivers/vivid/vivid-core.h @@ -303,6 +303,7 @@ struct vivid_dev { struct fb_fix_screeninfo fb_fix; /* Error injection */ + bool disconnect_error; bool queue_setup_error; bool buf_prepare_error; bool start_streaming_error; diff --git a/drivers/media/test-drivers/vivid/vivid-ctrls.c b/drivers/media/test-drivers/vivid/vivid-ctrls.c index 334130568dcb..11e3b5617f52 100644 --- a/drivers/media/test-drivers/vivid/vivid-ctrls.c +++ b/drivers/media/test-drivers/vivid/vivid-ctrls.c @@ -107,14 +107,27 @@ static int vivid_user_gen_s_ctrl(struct v4l2_ctrl *ctrl) switch (ctrl->id) { case VIVID_CID_DISCONNECT: v4l2_info(&dev->v4l2_dev, "disconnect\n"); - clear_bit(V4L2_FL_REGISTERED, &dev->vid_cap_dev.flags); - clear_bit(V4L2_FL_REGISTERED, &dev->vid_out_dev.flags); - clear_bit(V4L2_FL_REGISTERED, &dev->vbi_cap_dev.flags); - clear_bit(V4L2_FL_REGISTERED, &dev->vbi_out_dev.flags); - clear_bit(V4L2_FL_REGISTERED, &dev->sdr_cap_dev.flags); - clear_bit(V4L2_FL_REGISTERED, &dev->radio_rx_dev.flags); - clear_bit(V4L2_FL_REGISTERED, &dev->radio_tx_dev.flags); - clear_bit(V4L2_FL_REGISTERED, &dev->meta_cap_dev.flags); + dev->disconnect_error = true; + if (dev->has_vid_cap) + clear_bit(V4L2_FL_REGISTERED, &dev->vid_cap_dev.flags); + if (dev->has_vid_out) + clear_bit(V4L2_FL_REGISTERED, &dev->vid_out_dev.flags); + if (dev->has_vbi_cap) + clear_bit(V4L2_FL_REGISTERED, &dev->vbi_cap_dev.flags); + if (dev->has_vbi_out) + clear_bit(V4L2_FL_REGISTERED, &dev->vbi_out_dev.flags); + if (dev->has_radio_rx) + clear_bit(V4L2_FL_REGISTERED, &dev->radio_rx_dev.flags); + if (dev->has_radio_tx) + clear_bit(V4L2_FL_REGISTERED, &dev->radio_tx_dev.flags); + if (dev->has_sdr_cap) + clear_bit(V4L2_FL_REGISTERED, &dev->sdr_cap_dev.flags); + if (dev->has_meta_cap) + clear_bit(V4L2_FL_REGISTERED, &dev->meta_cap_dev.flags); + if (dev->has_meta_out) + clear_bit(V4L2_FL_REGISTERED, &dev->meta_out_dev.flags); + if (dev->has_touch_cap) + clear_bit(V4L2_FL_REGISTERED, &dev->touch_cap_dev.flags); break; case VIVID_CID_BUTTON: dev->button_pressed = 30; From patchwork Tue Dec 1 12:44:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 335452 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6AC6C64E7A for ; Tue, 1 Dec 2020 12:45:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2084320857 for ; Tue, 1 Dec 2020 12:45:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=xs4all.nl header.i=@xs4all.nl header.b="g3PZlU2n" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730037AbgLAMpd (ORCPT ); Tue, 1 Dec 2020 07:45:33 -0500 Received: from lb2-smtp-cloud8.xs4all.net ([194.109.24.25]:33091 "EHLO lb2-smtp-cloud8.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726908AbgLAMpd (ORCPT ); Tue, 1 Dec 2020 07:45:33 -0500 Received: from cust-b5b5937f ([IPv6:fc0c:c16d:66b8:757f:c639:739b:9d66:799d]) by smtp-cloud8.xs4all.net with ESMTPA id k51SkssSADuFjk51Wk2RYH; Tue, 01 Dec 2020 13:44:51 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xs4all.nl; s=s2; t=1606826691; bh=I6nlLMkqsPAumJd3p0jB3ACQybnxN4viHsxwYMpd1gw=; h=From:To:Subject:Date:Message-Id:MIME-Version:From:Subject; b=g3PZlU2nL3z6U9eOW3PQJomnbwNWU6RLtMse4QwNGZL/h08x0IuQxU8gPjBe/WWmN gUuWnv4MpTsMpVPc3FEzBGkB4PhWsWQdZZpvzuD8yT6s+mBOc91JnJlGFmBLSHX5cY KVY1aKjfirc3eljKlD9KAeAB/NZE66dnEJQWIgQ/g+nTQonpCODpdTyfyN43zvOq5U Hl+T6kGChid7G4ClkqThsXPJ/e/pjaaee57mdWgAG/DC8ZBGztBRox3ILdGWx5OHO4 LCLngEslyVNFRv9FyUXheq75tdu9HE6YhIejwPl1oPUq5ZROUNbpg0wSC5KZfbkCJr w3mcNbqGM/klQ== From: Hans Verkuil To: linux-media@vger.kernel.org Cc: Alexandre Courbot , Tomasz Figa , Marek Szyprowski Subject: [PATCHv3 2/7] media: videobuf2: always call poll_wait() on queues Date: Tue, 1 Dec 2020 13:44:41 +0100 Message-Id: <20201201124446.448595-3-hverkuil-cisco@xs4all.nl> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201201124446.448595-1-hverkuil-cisco@xs4all.nl> References: <20201201124446.448595-1-hverkuil-cisco@xs4all.nl> MIME-Version: 1.0 X-CMAE-Envelope: MS4xfEbbHtBtxZMg25ky9HguRnroC3luigL0X3xjmVl4YcEzAC4cF8zkGuoLHem70fyJetudArdmqSFaOjSG3F1c3boTMJIp10+2Z3Tv1K3d+QorJtFvji5A 3rvHhZZTNh/UBzA0H62Vwq3RpvnXjrmfRFH6izGW5hR6qwAzJVmeDdkaMDdBDRrKH730cfzU7uh5GTd05hyx4yUwSZzQKnNw7SMBcI9a1bvAAMfoiL3OgdVy KOEVOj1M54FOx7LzFy3nZlkf9z1CftOh0jhDkTcDBu/jME171E/b8ZAOGza0/MVu Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Alexandre Courbot do_poll()/do_select() seem to set the _qproc member of poll_table to NULL the first time they are called on a given table, making subsequent calls of poll_wait() on that table no-ops. This is a problem for vb2 which calls poll_wait() on the V4L2 queues' waitqueues only when a queue-related event is requested, which may not necessarily be the case during the first poll. Fix this by making the call to poll_wait() happen first thing and unconditionally in vb2_core_poll(). Signed-off-by: Alexandre Courbot --- drivers/media/common/videobuf2/videobuf2-core.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 4eab6d81cce1..ef06f90f5c6b 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -2363,13 +2363,20 @@ __poll_t vb2_core_poll(struct vb2_queue *q, struct file *file, struct vb2_buffer *vb = NULL; unsigned long flags; + /* + * poll_wait() MUST be called on the first invocation on all the + * potential queues of interest, even if we are not interested in their + * events during this first call. Failure to do so will result in + * queue's events to be ignored because the poll_table won't be capable + * of adding new wait queues thereafter. + */ + poll_wait(file, &q->done_wq, wait); + if (!q->is_output && !(req_events & (EPOLLIN | EPOLLRDNORM))) return 0; if (q->is_output && !(req_events & (EPOLLOUT | EPOLLWRNORM))) return 0; - poll_wait(file, &q->done_wq, wait); - /* * Start file I/O emulator only if streaming API has not been used yet. */ From patchwork Tue Dec 1 12:44:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 336354 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E81F9C83012 for ; Tue, 1 Dec 2020 12:45:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 85D5620870 for ; Tue, 1 Dec 2020 12:45:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=xs4all.nl header.i=@xs4all.nl header.b="jyFRDw85" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387480AbgLAMpf (ORCPT ); Tue, 1 Dec 2020 07:45:35 -0500 Received: from lb1-smtp-cloud8.xs4all.net ([194.109.24.21]:40633 "EHLO lb1-smtp-cloud8.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728790AbgLAMpe (ORCPT ); Tue, 1 Dec 2020 07:45:34 -0500 Received: from cust-b5b5937f ([IPv6:fc0c:c16d:66b8:757f:c639:739b:9d66:799d]) by smtp-cloud8.xs4all.net with ESMTPA id k51SkssSADuFjk51Xk2RYb; Tue, 01 Dec 2020 13:44:51 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xs4all.nl; s=s2; t=1606826691; bh=yaK72aXZCzXgohnr5ja0NWya+CJblYdNgX23+aCm0kA=; h=From:To:Subject:Date:Message-Id:MIME-Version:From:Subject; b=jyFRDw85teQ02+eQhrcheM7Q3508qHfUQuWDoX8M3Q/elteg97motY82WX46EPYkq s3V54YNrm4uoxX+UwSysZVHMA/c/aOlKrPAMFAeltHKHHETmyGnVa00MLiNUgx/VYN cPb7D9MYLLfzRNW2kFPdVKgrRlAOAGKZxdzMU9U49JkAiW/yR3z0KzdTN9VxWB1+yN 23U67SWl/6Jbygg/rPVXtL9eoYV9HGhOZIFnAuhQEiQqPHsLs/i7SBApYSIgcUDM4v YgHUlqAV1XUi7fBi0VyWWzDs6mmH1o2DKvnX3H7zXv/Z7SYIA/Nw+vYzR+Jjh28Qe5 ekbIeuHlVl7wQ== From: Hans Verkuil To: linux-media@vger.kernel.org Cc: Alexandre Courbot , Tomasz Figa , Marek Szyprowski Subject: [PATCHv3 3/7] media: v4l2-mem2mem: always call poll_wait() on queues Date: Tue, 1 Dec 2020 13:44:42 +0100 Message-Id: <20201201124446.448595-4-hverkuil-cisco@xs4all.nl> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201201124446.448595-1-hverkuil-cisco@xs4all.nl> References: <20201201124446.448595-1-hverkuil-cisco@xs4all.nl> MIME-Version: 1.0 X-CMAE-Envelope: MS4xfEbbHtBtxZMg25ky9HguRnroC3luigL0X3xjmVl4YcEzAC4cF8zkGuoLHem70fyJetudArdmqSFaOjSG3F1c3boTMJIp10+2Z3Tv1K3d+QorJtFvji5A 3rvHhZZTNh/UBzA0H62Vwq3RpvnXjrmfRFH6izGW5hR6qwAzJVmeDdkaMDdBDRrKH730cfzU7uh5GTd05hyx4yUwSZzQKnNw7SMBcI9a1bvAAMfoiL3OgdVy KOEVOj1M54FOx7LzFy3nZlkf9z1CftOh0jhDkTcDBu/jME171E/b8ZAOGza0/MVu Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Alexandre Courbot do_poll()/do_select() seem to set the _qproc member of poll_table to NULL the first time they are called on a given table, making subsequent calls of poll_wait() on that table no-ops. This is a problem for mem2mem which calls poll_wait() on the V4L2 queues' waitqueues only when a queue-related event is requested, which may not necessarily be the case during the first poll. For instance, a stateful decoder is typically only interested in EPOLLPRI events when it starts, and will switch to listening to both EPOLLPRI and EPOLLIN after receiving the initial resolution change event and configuring the CAPTURE queue. However by the time that switch happens and v4l2_m2m_poll_for_data() is called for the first time, poll_wait() has become a no-op and the V4L2 queues waitqueues thus cannot be registered. Fix this by moving the registration to v4l2_m2m_poll() and do it whether or not one of the queue-related events are requested. Signed-off-by: Alexandre Courbot --- drivers/media/v4l2-core/v4l2-mem2mem.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c b/drivers/media/v4l2-core/v4l2-mem2mem.c index b221b4e438a1..e7f4bf5bc8dd 100644 --- a/drivers/media/v4l2-core/v4l2-mem2mem.c +++ b/drivers/media/v4l2-core/v4l2-mem2mem.c @@ -887,9 +887,6 @@ static __poll_t v4l2_m2m_poll_for_data(struct file *file, src_q = v4l2_m2m_get_src_vq(m2m_ctx); dst_q = v4l2_m2m_get_dst_vq(m2m_ctx); - poll_wait(file, &src_q->done_wq, wait); - poll_wait(file, &dst_q->done_wq, wait); - /* * There has to be at least one buffer queued on each queued_list, which * means either in driver already or waiting for driver to claim it @@ -922,9 +919,21 @@ __poll_t v4l2_m2m_poll(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, struct poll_table_struct *wait) { struct video_device *vfd = video_devdata(file); + struct vb2_queue *src_q = v4l2_m2m_get_src_vq(m2m_ctx); + struct vb2_queue *dst_q = v4l2_m2m_get_dst_vq(m2m_ctx); __poll_t req_events = poll_requested_events(wait); __poll_t rc = 0; + /* + * poll_wait() MUST be called on the first invocation on all the + * potential queues of interest, even if we are not interested in their + * events during this first call. Failure to do so will result in + * queue's events to be ignored because the poll_table won't be capable + * of adding new wait queues thereafter. + */ + poll_wait(file, &src_q->done_wq, wait); + poll_wait(file, &dst_q->done_wq, wait); + if (req_events & (EPOLLOUT | EPOLLWRNORM | EPOLLIN | EPOLLRDNORM)) rc = v4l2_m2m_poll_for_data(file, m2m_ctx, wait); From patchwork Tue Dec 1 12:44:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 335451 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0EC6C71156 for ; Tue, 1 Dec 2020 12:45:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 44EFE2087C for ; Tue, 1 Dec 2020 12:45:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=xs4all.nl header.i=@xs4all.nl header.b="aRuEK3Cg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730126AbgLAMpe (ORCPT ); Tue, 1 Dec 2020 07:45:34 -0500 Received: from lb1-smtp-cloud8.xs4all.net ([194.109.24.21]:45353 "EHLO lb1-smtp-cloud8.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728570AbgLAMpe (ORCPT ); Tue, 1 Dec 2020 07:45:34 -0500 Received: from cust-b5b5937f ([IPv6:fc0c:c16d:66b8:757f:c639:739b:9d66:799d]) by smtp-cloud8.xs4all.net with ESMTPA id k51SkssSADuFjk51Xk2RYn; Tue, 01 Dec 2020 13:44:51 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xs4all.nl; s=s2; t=1606826691; bh=U8mWCSYP2Eq4lCnjfIsVMvB2loExRhRj4TBhggJVWEY=; h=From:To:Subject:Date:Message-Id:MIME-Version:From:Subject; b=aRuEK3Cg2nyhQ7GYGxcjbNkbErQ+PS24SXLY97C0iH8JED9RJCUKZoqUguXXKdiNt g9MRZl43HKj5v6Rv71/KkKc1o/VAIcLJTBnia3hBj4UXlBG+CNoaHaiKDOwTLs8IsR s3E/4dsPsZc3uiJ6ecoIT0tE1n2vCjJ5gUFUOGfp6ZibRjYHkFMzut7TCkwhr0bBXA 74R46y7+tF+4qIEbuoMJmYGwi8P5SIF+q2PVLQtk5uCsIe3YEEs5JytNFm2ILfi7AI JE3bRZJXwGcxSiCM1c1e2zD/gvUvVaHteUKgvSpESeLeVRaA7p4yfMsMMMvVgM74sc EY8Zdf722ZF/w== From: Hans Verkuil To: linux-media@vger.kernel.org Cc: Alexandre Courbot , Tomasz Figa , Marek Szyprowski , Hans Verkuil Subject: [PATCHv3 4/7] v4l2-dev/event: add v4l2_event_wake_all() Date: Tue, 1 Dec 2020 13:44:43 +0100 Message-Id: <20201201124446.448595-5-hverkuil-cisco@xs4all.nl> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201201124446.448595-1-hverkuil-cisco@xs4all.nl> References: <20201201124446.448595-1-hverkuil-cisco@xs4all.nl> MIME-Version: 1.0 X-CMAE-Envelope: MS4xfEbbHtBtxZMg25ky9HguRnroC3luigL0X3xjmVl4YcEzAC4cF8zkGuoLHem70fyJetudArdmqSFaOjSG3F1c3boTMJIp10+2Z3Tv1K3d+QorJtFvji5A 3rvHhZZTNh/UB8vbRgFoIZyK1Nc/yLr8zJ2dwr3J9h6I8+v2a79tvM19hHNzjGNo3BrVsTClsc0i9OSYI1MBsFLVZMEjXqNxG6XhiMiZGuQytTPQWa/o9NrM edPmE+vGANYx6lv8z1TLuVoKsOZIsJKGRlOlpxtQrSMD6eAze0uVrOrcvVREwdcOpyDQ6KDjZ8RoD6G+b1jEQEO/czQX1ts1ltowKUFp7TA= Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org When unregistering a V4L2 device node, make sure any filehandles that are waiting for an event are woken up. Add v4l2_event_wake_all() to v4l2-event.c and call it from video_unregister_device(). Otherwise userspace might never know that a device node was removed. Signed-off-by: Hans Verkuil --- drivers/media/v4l2-core/v4l2-dev.c | 3 +++ drivers/media/v4l2-core/v4l2-event.c | 17 +++++++++++++++++ include/media/v4l2-event.h | 13 +++++++++++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c index a593ea0598b5..0ddc3554f1a4 100644 --- a/drivers/media/v4l2-core/v4l2-dev.c +++ b/drivers/media/v4l2-core/v4l2-dev.c @@ -28,6 +28,7 @@ #include #include #include +#include #define VIDEO_NUM_DEVICES 256 #define VIDEO_NAME "video4linux" @@ -1086,6 +1087,8 @@ void video_unregister_device(struct video_device *vdev) */ clear_bit(V4L2_FL_REGISTERED, &vdev->flags); mutex_unlock(&videodev_lock); + if (test_bit(V4L2_FL_USES_V4L2_FH, &vdev->flags)) + v4l2_event_wake_all(vdev); device_unregister(&vdev->dev); } EXPORT_SYMBOL(video_unregister_device); diff --git a/drivers/media/v4l2-core/v4l2-event.c b/drivers/media/v4l2-core/v4l2-event.c index 290c6b213179..207a9ad80ea2 100644 --- a/drivers/media/v4l2-core/v4l2-event.c +++ b/drivers/media/v4l2-core/v4l2-event.c @@ -187,6 +187,23 @@ int v4l2_event_pending(struct v4l2_fh *fh) } EXPORT_SYMBOL_GPL(v4l2_event_pending); +void v4l2_event_wake_all(struct video_device *vdev) +{ + struct v4l2_fh *fh; + unsigned long flags; + + if (vdev == NULL) + return; + + spin_lock_irqsave(&vdev->fh_lock, flags); + + list_for_each_entry(fh, &vdev->fh_list, list) + wake_up_all(&fh->wait); + + spin_unlock_irqrestore(&vdev->fh_lock, flags); +} +EXPORT_SYMBOL_GPL(v4l2_event_wake_all); + static void __v4l2_event_unsubscribe(struct v4l2_subscribed_event *sev) { struct v4l2_fh *fh = sev->fh; diff --git a/include/media/v4l2-event.h b/include/media/v4l2-event.h index 3f0281d06ec7..4ffa914ade3a 100644 --- a/include/media/v4l2-event.h +++ b/include/media/v4l2-event.h @@ -101,7 +101,7 @@ int v4l2_event_dequeue(struct v4l2_fh *fh, struct v4l2_event *event, * * .. note:: * The driver's only responsibility is to fill in the type and the data - * fields.The other fields will be filled in by V4L2. + * fields. The other fields will be filled in by V4L2. */ void v4l2_event_queue(struct video_device *vdev, const struct v4l2_event *ev); @@ -116,10 +116,19 @@ void v4l2_event_queue(struct video_device *vdev, const struct v4l2_event *ev); * * .. note:: * The driver's only responsibility is to fill in the type and the data - * fields.The other fields will be filled in by V4L2. + * fields. The other fields will be filled in by V4L2. */ void v4l2_event_queue_fh(struct v4l2_fh *fh, const struct v4l2_event *ev); +/** + * v4l2_event_wake_all - Wake all filehandles. + * + * Used when unregistering a video device. + * + * @vdev: pointer to &struct video_device + */ +void v4l2_event_wake_all(struct video_device *vdev); + /** * v4l2_event_pending - Check if an event is available * From patchwork Tue Dec 1 12:44:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 335450 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B381C83014 for ; Tue, 1 Dec 2020 12:45:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C40682087C for ; Tue, 1 Dec 2020 12:45:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=xs4all.nl header.i=@xs4all.nl header.b="hPXZOzwn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387510AbgLAMpf (ORCPT ); Tue, 1 Dec 2020 07:45:35 -0500 Received: from lb1-smtp-cloud8.xs4all.net ([194.109.24.21]:53491 "EHLO lb1-smtp-cloud8.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728987AbgLAMpe (ORCPT ); Tue, 1 Dec 2020 07:45:34 -0500 Received: from cust-b5b5937f ([IPv6:fc0c:c16d:66b8:757f:c639:739b:9d66:799d]) by smtp-cloud8.xs4all.net with ESMTPA id k51SkssSADuFjk51Xk2RYx; Tue, 01 Dec 2020 13:44:52 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xs4all.nl; s=s2; t=1606826692; bh=BXusA+CIrGWKf3/SqjzlEkdnmGnMvYpEsKkSCTIgqf4=; h=From:To:Subject:Date:Message-Id:MIME-Version:From:Subject; b=hPXZOzwnXkbSMENcwuqypNtDTdcNV+DfV300uarPRKeVyHLF/8/PyGIXnNHi99h/g fZMwpgsThI5xOtG/uYwh6RCbHRFel/fpuzqnOOn641JDqqNAvq1fbh7fELbP/v/nrE GWFT4SSqdP/2eygWjDa2xOOeUoLOa2OSWepfJTPoDOBIduBmJT8gH3EEo88gGQ1ab2 dUGhhtPi7YHT+KxC2qZwZuxvoUPJtwmUQ4sNrLA9bDMW+dfYmy4O5JFm8XIP91xSXZ 8l3FHpNFP2UcSWQQRIpRaXPEOxCh2xdoYgWnKfVWy9KjpqN7AEw0L+VAM4/+jEcMw5 NGT7X/5Coa8Pw== From: Hans Verkuil To: linux-media@vger.kernel.org Cc: Alexandre Courbot , Tomasz Figa , Marek Szyprowski , Hans Verkuil Subject: [PATCHv3 5/7] vivid: call v4l2_event_wake_all() on disconnect Date: Tue, 1 Dec 2020 13:44:44 +0100 Message-Id: <20201201124446.448595-6-hverkuil-cisco@xs4all.nl> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201201124446.448595-1-hverkuil-cisco@xs4all.nl> References: <20201201124446.448595-1-hverkuil-cisco@xs4all.nl> MIME-Version: 1.0 X-CMAE-Envelope: MS4xfMpvkjAk6HI2j3BveW2MEiCLvzzeRn4nnBO1V+ZM2q1Y2N6RUcSw8tTmOeRBj720LACdfRQKS6lKxmZf0IA1VBi176pkOz94HuIUN5ejM+oQDNve9s2j FT/XqBztnHKZqx7uUyd4pwR0S6tIPGDzzwA7xgVn7c/LeKSY+gnXNsmLzw5HOTL2MWcXoaze0r0+PnSI3u3uZzUMrYLvah+1NqcbUsnrYnyw5CTF1POWvWj5 iIfUzUGIFnPwd+jQq6loI/HX7KoQKJSH8XtwhtS8rvKvtXsmn3pF17jScEBzdmH+8vlxZI1DG/o6rvgJBh72CtGC12ghXWXpvLxcfsX5P+A= Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org When the disconnect error injection control is set, then besides faking unregistering the device nodes, also call v4l2_event_wake_all() to ensure any userspace applications will wake up as per a 'normal' unregister. Signed-off-by: Hans Verkuil --- .../media/test-drivers/vivid/vivid-ctrls.c | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/drivers/media/test-drivers/vivid/vivid-ctrls.c b/drivers/media/test-drivers/vivid/vivid-ctrls.c index 11e3b5617f52..7957eadf3e2b 100644 --- a/drivers/media/test-drivers/vivid/vivid-ctrls.c +++ b/drivers/media/test-drivers/vivid/vivid-ctrls.c @@ -100,6 +100,14 @@ /* General User Controls */ +static void vivid_unregister_dev(bool valid, struct video_device *vdev) +{ + if (!valid) + return; + clear_bit(V4L2_FL_REGISTERED, &vdev->flags); + v4l2_event_wake_all(vdev); +} + static int vivid_user_gen_s_ctrl(struct v4l2_ctrl *ctrl) { struct vivid_dev *dev = container_of(ctrl->handler, struct vivid_dev, ctrl_hdl_user_gen); @@ -108,26 +116,16 @@ static int vivid_user_gen_s_ctrl(struct v4l2_ctrl *ctrl) case VIVID_CID_DISCONNECT: v4l2_info(&dev->v4l2_dev, "disconnect\n"); dev->disconnect_error = true; - if (dev->has_vid_cap) - clear_bit(V4L2_FL_REGISTERED, &dev->vid_cap_dev.flags); - if (dev->has_vid_out) - clear_bit(V4L2_FL_REGISTERED, &dev->vid_out_dev.flags); - if (dev->has_vbi_cap) - clear_bit(V4L2_FL_REGISTERED, &dev->vbi_cap_dev.flags); - if (dev->has_vbi_out) - clear_bit(V4L2_FL_REGISTERED, &dev->vbi_out_dev.flags); - if (dev->has_radio_rx) - clear_bit(V4L2_FL_REGISTERED, &dev->radio_rx_dev.flags); - if (dev->has_radio_tx) - clear_bit(V4L2_FL_REGISTERED, &dev->radio_tx_dev.flags); - if (dev->has_sdr_cap) - clear_bit(V4L2_FL_REGISTERED, &dev->sdr_cap_dev.flags); - if (dev->has_meta_cap) - clear_bit(V4L2_FL_REGISTERED, &dev->meta_cap_dev.flags); - if (dev->has_meta_out) - clear_bit(V4L2_FL_REGISTERED, &dev->meta_out_dev.flags); - if (dev->has_touch_cap) - clear_bit(V4L2_FL_REGISTERED, &dev->touch_cap_dev.flags); + vivid_unregister_dev(dev->has_vid_cap, &dev->vid_cap_dev); + vivid_unregister_dev(dev->has_vid_out, &dev->vid_out_dev); + vivid_unregister_dev(dev->has_vbi_cap, &dev->vbi_cap_dev); + vivid_unregister_dev(dev->has_vbi_out, &dev->vbi_out_dev); + vivid_unregister_dev(dev->has_radio_rx, &dev->radio_rx_dev); + vivid_unregister_dev(dev->has_radio_tx, &dev->radio_tx_dev); + vivid_unregister_dev(dev->has_sdr_cap, &dev->sdr_cap_dev); + vivid_unregister_dev(dev->has_meta_cap, &dev->meta_cap_dev); + vivid_unregister_dev(dev->has_meta_out, &dev->meta_out_dev); + vivid_unregister_dev(dev->has_touch_cap, &dev->touch_cap_dev); break; case VIVID_CID_BUTTON: dev->button_pressed = 30; From patchwork Tue Dec 1 12:44:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 336352 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8ABCC83016 for ; Tue, 1 Dec 2020 12:45:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6892E21D46 for ; Tue, 1 Dec 2020 12:45:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=xs4all.nl header.i=@xs4all.nl header.b="YpoyBm7E" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387717AbgLAMpf (ORCPT ); Tue, 1 Dec 2020 07:45:35 -0500 Received: from lb2-smtp-cloud8.xs4all.net ([194.109.24.25]:48499 "EHLO lb2-smtp-cloud8.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728623AbgLAMpf (ORCPT ); Tue, 1 Dec 2020 07:45:35 -0500 Received: from cust-b5b5937f ([IPv6:fc0c:c16d:66b8:757f:c639:739b:9d66:799d]) by smtp-cloud8.xs4all.net with ESMTPA id k51SkssSADuFjk51Yk2RZB; Tue, 01 Dec 2020 13:44:52 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xs4all.nl; s=s2; t=1606826692; bh=4qbHEJdiN8hY9S+Fm3WxNty6LYiWWcjJlDO8CtQih0k=; h=From:To:Subject:Date:Message-Id:MIME-Version:From:Subject; b=YpoyBm7E/I87661RgKDTB7V5Ou2RsKZ7pIQSUzG+ajD3iKMvbZDvE5WmGvIoBhdPD sGjkNpDRPtjUJF/b12GbvC+LfzA7XoJSu09WFdeOeDIGUDomUwsbDanltt6RXlQZnR 4rBUnz0a4+eVy3s79aTFyaUecNAe452w790dIRdjNGmeLi73fH0s1jUeKAXKJSYS92 TO9TwwZCRCyMvcQvR8AgaCi/Ss70ciE6pFoUzBMZZ2QIFeDwAHMhF4OyrhKggB34HR XXjMcdrMf408V/Nl68qqgglaup7bvEey493Q6R5UzIqMGnqTQerFl4V6kdatLhn8Mz upa8WfRfkYMJA== From: Hans Verkuil To: linux-media@vger.kernel.org Cc: Alexandre Courbot , Tomasz Figa , Marek Szyprowski , Hans Verkuil Subject: [PATCHv3 6/7] v4l2-dev: add EPOLLPRI in v4l2_poll() when dev is unregistered Date: Tue, 1 Dec 2020 13:44:45 +0100 Message-Id: <20201201124446.448595-7-hverkuil-cisco@xs4all.nl> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201201124446.448595-1-hverkuil-cisco@xs4all.nl> References: <20201201124446.448595-1-hverkuil-cisco@xs4all.nl> MIME-Version: 1.0 X-CMAE-Envelope: MS4xfMpvkjAk6HI2j3BveW2MEiCLvzzeRn4nnBO1V+ZM2q1Y2N6RUcSw8tTmOeRBj720LACdfRQKS6lKxmZf0IA1VBi176pkOz94HuIUN5ejM+oQDNve9s2j FT/XqBztnHKZqx7uUyd4pwR0S6tIPGDzzwA7xgVn7c/LeKSY+gnXNsmLzw5HOTL2MWcXoaze0r0+PnSI3u3uZzUMrYLvah+1NqcbUsnrYnyw5CTF1POWvWj5 iIfUzUGIFnPwd+jQq6loI/HX7KoQKJSH8XtwhtS8rvKvtXsmn3pF17jScEBzdmH+8vlxZI1DG/o6rvgJBh72CtGC12ghXWXpvLxcfsX5P+A= Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org If the V4L2 device was unregistered, then add EPOLLPRI to the poll mask. Otherwise a select() that only waits for exceptions will not wake up. A select() that waits for read and/or write events *will* wake up on an EPOLLERR, but not (for some reason) if it just waits for exceptions. Strangly the epoll functionality will wakeup on EPOLLERR if you just wait for an exception, so in this respect select() and epoll differ. In the end it doesn't really matter, what matters is that polling file handles are woken up on device unregistration. It also improves the code a bit if vdev->fops->poll is NULL: this didn't check for device unregistration. Signed-off-by: Hans Verkuil --- drivers/media/v4l2-core/v4l2-dev.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c index 0ddc3554f1a4..f9cff033d0dc 100644 --- a/drivers/media/v4l2-core/v4l2-dev.c +++ b/drivers/media/v4l2-core/v4l2-dev.c @@ -339,12 +339,14 @@ static ssize_t v4l2_write(struct file *filp, const char __user *buf, static __poll_t v4l2_poll(struct file *filp, struct poll_table_struct *poll) { struct video_device *vdev = video_devdata(filp); - __poll_t res = EPOLLERR | EPOLLHUP; + __poll_t res = EPOLLERR | EPOLLHUP | EPOLLPRI; - if (!vdev->fops->poll) - return DEFAULT_POLLMASK; - if (video_is_registered(vdev)) - res = vdev->fops->poll(filp, poll); + if (video_is_registered(vdev)) { + if (!vdev->fops->poll) + res = DEFAULT_POLLMASK; + else + res = vdev->fops->poll(filp, poll); + } if (vdev->dev_debug & V4L2_DEV_DEBUG_POLL) dprintk("%s: poll: %08x\n", video_device_node_name(vdev), res); From patchwork Tue Dec 1 12:44:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 335449 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7AECFC83013 for ; Tue, 1 Dec 2020 12:45:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 23AED20870 for ; Tue, 1 Dec 2020 12:45:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=xs4all.nl header.i=@xs4all.nl header.b="V5J5slFU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387499AbgLAMpf (ORCPT ); Tue, 1 Dec 2020 07:45:35 -0500 Received: from lb1-smtp-cloud8.xs4all.net ([194.109.24.21]:58927 "EHLO lb1-smtp-cloud8.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727852AbgLAMpe (ORCPT ); Tue, 1 Dec 2020 07:45:34 -0500 Received: from cust-b5b5937f ([IPv6:fc0c:c16d:66b8:757f:c639:739b:9d66:799d]) by smtp-cloud8.xs4all.net with ESMTPA id k51SkssSADuFjk51Yk2RZW; Tue, 01 Dec 2020 13:44:52 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xs4all.nl; s=s2; t=1606826692; bh=mt5bsHjinTMK9UeaLEBSzlWAehCdkQv0m8nPyh/7k4Y=; h=From:To:Subject:Date:Message-Id:MIME-Version:From:Subject; b=V5J5slFU1SmuQJ6ej80igbipy2/r3BcX2JOQn9UnmofHYPRzS3lhClWHcDWdiQ4Lw zii//mzWTgnCDsTiiIcyxHV8SMkwlINqbWBJSzMuvVC9cXR+/j7sIvhowPVd8pl02I qXB17nO07TnV02bVw49DJgYxmf4iMSc5sVeToU5CrZot4faSSk4c8Yha7Rp+mRqovD HTvYOiyi1YMPHdMEadlmAJmSllGt/rWwCiU8jMKlJlPP7jg6RVZWHfBLPfvNe4764T 6/lenJrmjsxwhcDAJ7rNYcYnsv4+kJ9Huk7KyyA/guWYhoHC+HXk3yC33vCsZJIDO1 uF3d/+d1emWOA== From: Hans Verkuil To: linux-media@vger.kernel.org Cc: Alexandre Courbot , Tomasz Figa , Marek Szyprowski , Hans Verkuil Subject: [PATCHv3 7/7] cec: add EPOLLPRI in poll() when dev is unregistered Date: Tue, 1 Dec 2020 13:44:46 +0100 Message-Id: <20201201124446.448595-8-hverkuil-cisco@xs4all.nl> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201201124446.448595-1-hverkuil-cisco@xs4all.nl> References: <20201201124446.448595-1-hverkuil-cisco@xs4all.nl> MIME-Version: 1.0 X-CMAE-Envelope: MS4xfMpvkjAk6HI2j3BveW2MEiCLvzzeRn4nnBO1V+ZM2q1Y2N6RUcSw8tTmOeRBj720LACdfRQKS6lKxmZf0IA1VBi176pkOz94HuIUN5ejM+oQDNve9s2j FT/XqBztnHKZqx7uUyd4pwR0S6tIPGDzzwA7xgVn7c/LeKSY+gnXNsmLzw5HOTL2MWcXoaze0r0+PnSI3u3uZzUMrYLvah+1NqcbUsnrYnyw5CTF1POWvWj5 iIfUzUGIFnPwd+jQq6loI/HX7KoQKJSH8XtwhtS8rvKvtXsmn3pF17jScEBzdmH+8vlxZI1DG/o6rvgJBh72CtGC12ghXWXpvLxcfsX5P+A= Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org If the CEC device was unregistered, then add EPOLLPRI to the poll() mask. Otherwise a select() that only waits for exceptions will not wake up. A select() that waits for read and/or write events *will* wake up on an EPOLLERR, but not (for some reason) if it just waits for exceptions. Strangly the epoll functionality will wakeup on EPOLLERR if you just wait for an exception, so in this respect select() and epoll differ. In the end it doesn't really matter, what matters is that polling file handles are woken up on device unregistration. Signed-off-by: Hans Verkuil --- drivers/media/cec/core/cec-api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/cec/core/cec-api.c b/drivers/media/cec/core/cec-api.c index f922a2196b2b..769e6b4cddce 100644 --- a/drivers/media/cec/core/cec-api.c +++ b/drivers/media/cec/core/cec-api.c @@ -40,7 +40,7 @@ static __poll_t cec_poll(struct file *filp, poll_wait(filp, &fh->wait, poll); if (!cec_is_registered(adap)) - return EPOLLERR | EPOLLHUP; + return EPOLLERR | EPOLLHUP | EPOLLPRI; mutex_lock(&adap->lock); if (adap->is_configured && adap->transmit_queue_sz < CEC_MAX_MSG_TX_QUEUE_SZ)