From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 95EA0CCD193 for ; Mon, 20 Oct 2025 11:59:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:References:Cc:To:Subject: From:MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=2RqeU1Dl3Yk7sqAsxYqvy4Vra37K070PmccQVVJgBZU=; b=jXUQ/uF7ztvgRV WXFh5PFkEYIyLq9yvImpPkF1lqCUohUn8dO2To83ISkcvathfOJi1sCjXlHB69EtB7hIBJaFnqZtB jKckQpKHvuastBPZey8uA3dImGIUCMeiyuERsQw9gAVkvPPw+T6dU75N8dqwQZy8/Uw4UbgXhICBe e2g/wpnljmXiW0nN82lnowKoGmvHL6OTTobkqlHCYYkNU+cdFD+bEFDDCjVEI7p6XR/PvzYNSPGHZ sVklplIyKTSgy3yMSgzKb4MmtHPU4z7NNUzl2S96+SsduMAAaRHUIX2s9i6qMl0TzBRe7HpUT1jrf 1X0P5pzYT+5mXGrNMApg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vAoXy-0000000DCIe-0vUv; Mon, 20 Oct 2025 11:59:30 +0000 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1uk7aY-00000001WBE-21yU; Thu, 07 Aug 2025 20:51:51 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 80B3245D71; Thu, 7 Aug 2025 20:51:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5E24C4CEEB; Thu, 7 Aug 2025 20:51:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1754599909; bh=3UV5qhXZXz0ktSdSl82KFH6CLaqHyQ8hq27qnvFqsF4=; h=Date:From:Subject:To:Cc:References:In-Reply-To:From; b=biLZ/OQDls4nl6Hrl1TOawbeNOsUJlBiS0so447501RA+Ciq+3SfdZMRm6kJOmtF6 ZUCqJfhm47QhZTXkeeTj2bMyqKEp+zJKFT8OBVsy3nXotNYfY7tB8qrNvi2ha9E0mc ie7Rkl2zwQAp/Bc68S6eKHQgtfmOmju7vHPhRrMij1h2mJoHZF2EyxIqOi+hshdZAK TyQNuv1FslwU6TGZbxxINtp7+8jSpepa7u3jDT8epbxrqYiitDtiw3IQGRKMuDAG9U PFZjxGZ7xMbNcopbxl/725NVJ7hymuuwEstWQFaJmvgQdHqICyps/WPvOpGB8fM2XF 6f0P7AdCK7nmw== Message-ID: <7605f778-6b20-47e4-bd65-7a0d85fff736@kernel.org> Date: Thu, 7 Aug 2025 22:51:27 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Hans Verkuil Subject: Re: [PATCH 27/65] media: Reset file->private_data to NULL in v4l2_fh_del() To: Laurent Pinchart Cc: Jacopo Mondi , Mauro Carvalho Chehab , Devarsh Thakkar , Benoit Parrot , Hans Verkuil , Mike Isely , Hans de Goede , Parthiban Veerasooran , Christian Gromm , Greg Kroah-Hartman , Alex Shi , Yanteng Si , Dongliang Mu , Jonathan Corbet , Tomasz Figa , Marek Szyprowski , Andy Walls , Michael Tretter , Pengutronix Kernel Team , Bin Liu , Matthias Brugger , AngeloGioacchino Del Regno , Dmitry Osipenko , Thierry Reding , Jonathan Hunter , Mirela Rabulea , Shawn Guo , Sascha Hauer , Fabio Estevam , Kieran Bingham , Michal Simek , Ming Qian , Zhou Peng , Xavier Roumegue , Philipp Zabel , Vikash Garodia , Dikshita Agarwal , Abhinav Kumar , Bryan O'Donoghue , Sylwester Nawrocki , Jernej Skrabec , Chen-Yu Tsai , Samuel Holland , Daniel Almeida , Neil Armstrong , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , Nas Chung , Jackson Lee , Minghsiu Tsai , Houlong Wei , Andrew-CT Chen , Tiffany Lin , Yunfei Dong , Geert Uytterhoeven , Magnus Damm , Mikhail Ulyanov , Jacob Chen , Ezequiel Garcia , Heiko Stuebner , Detlev Casanova , Krzysztof Kozlowski , Alim Akhtar , Sylwester Nawrocki , =?UTF-8?Q?=C5=81ukasz_Stelmach?= , Andrzej Pietrasiewicz , Jacek Anaszewski , Andrzej Hajda , Fabien Dessenne , Hugues Fruchet , Jean-Christophe Trotin , Maxime Coquelin , Alexandre Torgue , Nicolas Dufresne , Benjamin Gaignard , Steve Longerbeam , Maxime Ripard , Paul Kocialkowski , =?UTF-8?Q?Niklas_S=C3=B6derlund?= , Robert Foss , Todor Tomov , Vladimir Zapolskiy , Corentin Labbe , Sakari Ailus , Bingbu Cao , Tianshu Qiu , Stanislaw Gruszka , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-staging@lists.linux.dev, linux-doc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-tegra@vger.kernel.org, imx@lists.linux.dev, linux-renesas-soc@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-usb@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, mjpeg-users@lists.sourceforge.net References: <20250802-media-private-data-v1-0-eb140ddd6a9d@ideasonboard.com> <20250802-media-private-data-v1-27-eb140ddd6a9d@ideasonboard.com> <20250807085003.GE11583@pendragon.ideasonboard.com> <20250807170004.GG11583@pendragon.ideasonboard.com> <20250807202553.GB28610@pendragon.ideasonboard.com> Content-Language: en-US, nl In-Reply-To: <20250807202553.GB28610@pendragon.ideasonboard.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250807_135150_574325_002864D3 X-CRM114-Status: GOOD ( 25.04 ) X-Mailman-Approved-At: Mon, 20 Oct 2025 04:56:32 -0700 X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org On 07/08/2025 22:25, Laurent Pinchart wrote: > On Thu, Aug 07, 2025 at 08:00:06PM +0300, Laurent Pinchart wrote: >> On Thu, Aug 07, 2025 at 11:50:07AM +0300, Laurent Pinchart wrote: >>> On Wed, Aug 06, 2025 at 02:45:14PM +0200, Hans Verkuil wrote: >>>> On 02/08/2025 11:22, Jacopo Mondi wrote: >>>>> From: Laurent Pinchart >>>>> >>>>> Multiple drivers that use v4l2_fh and call v4l2_fh_del() manually reset >>>>> the file->private_data pointer to NULL in their video device .release() >>>>> file operation handler. Move the code to the v4l2_fh_del() function to >>>>> avoid direct access to file->private_data in drivers. This requires >>>>> adding a file pointer argument to the function. >>>>> >>>>> Changes to drivers have been generated with the following coccinelle >>>>> semantic patch: >>>>> >>>>> @@ >>>>> expression fh; >>>>> identifier filp; >>>>> identifier release; >>>>> type ret; >>>>> @@ >>>>> ret release(..., struct file *filp, ...) >>>>> { >>>>> <... >>>>> - filp->private_data = NULL; >>>>> ... >>>>> - v4l2_fh_del(fh); >>>>> + v4l2_fh_del(fh, filp); >>>>> ...> >>>>> } >>>>> >>>>> @@ >>>>> expression fh; >>>>> identifier filp; >>>>> identifier release; >>>>> type ret; >>>>> @@ >>>>> ret release(..., struct file *filp, ...) >>>>> { >>>>> <... >>>>> - v4l2_fh_del(fh); >>>>> + v4l2_fh_del(fh, filp); >>>>> ... >>>>> - filp->private_data = NULL; >>>>> ...> >>>>> } >>>>> >>>>> @@ >>>>> expression fh; >>>>> identifier filp; >>>>> identifier release; >>>>> type ret; >>>>> @@ >>>>> ret release(..., struct file *filp, ...) >>>>> { >>>>> <... >>>>> - v4l2_fh_del(fh); >>>>> + v4l2_fh_del(fh, filp); >>>>> ...> >>>>> } >>>>> >>>>> Manual changes have been applied to Documentation/ to update the usage >>>>> patterns, to drivers/media/v4l2-core/v4l2-fh.c to update the >>>>> v4l2_fh_del() prototype and reset file->private_data, and to >>>>> include/media/v4l2-fh.h to update the v4l2_fh_del() function prototype >>>>> and its documentation. >>>>> >>>>> Additionally, white space issues have been fixed manually in >>>>> drivers/usb/gadget/function/uvc_v4l2.c >>>>> >>>>> Signed-off-by: Laurent Pinchart >>>>> Signed-off-by: Jacopo Mondi >>>>> --- >>>>> Documentation/driver-api/media/v4l2-fh.rst | 4 ++-- >>>>> Documentation/translations/zh_CN/video4linux/v4l2-framework.txt | 4 ++-- >>>>> drivers/media/pci/cx18/cx18-fileops.c | 4 ++-- >>>>> drivers/media/pci/ivtv/ivtv-fileops.c | 4 ++-- >>>>> drivers/media/pci/saa7164/saa7164-encoder.c | 2 +- >>>>> drivers/media/pci/saa7164/saa7164-vbi.c | 2 +- >>>>> drivers/media/platform/allegro-dvt/allegro-core.c | 2 +- >>>>> drivers/media/platform/amlogic/meson-ge2d/ge2d.c | 2 +- >>>>> drivers/media/platform/amphion/vpu_v4l2.c | 4 ++-- >>>>> drivers/media/platform/chips-media/coda/coda-common.c | 4 ++-- >>>>> drivers/media/platform/chips-media/wave5/wave5-helper.c | 2 +- >>>>> drivers/media/platform/imagination/e5010-jpeg-enc.c | 4 ++-- >>>>> drivers/media/platform/m2m-deinterlace.c | 2 +- >>>>> drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c | 4 ++-- >>>>> drivers/media/platform/mediatek/mdp/mtk_mdp_m2m.c | 4 ++-- >>>>> drivers/media/platform/mediatek/mdp3/mtk-mdp3-m2m.c | 4 ++-- >>>>> .../media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.c | 4 ++-- >>>>> .../media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.c | 4 ++-- >>>>> drivers/media/platform/nvidia/tegra-vde/v4l2.c | 2 +- >>>>> drivers/media/platform/nxp/dw100/dw100.c | 2 +- >>>>> drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c | 4 ++-- >>>>> drivers/media/platform/nxp/imx-pxp.c | 2 +- >>>>> drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c | 2 +- >>>>> drivers/media/platform/nxp/mx2_emmaprp.c | 2 +- >>>>> drivers/media/platform/qcom/iris/iris_vidc.c | 3 +-- >>>>> drivers/media/platform/qcom/venus/core.c | 2 +- >>>>> drivers/media/platform/renesas/rcar_fdp1.c | 2 +- >>>>> drivers/media/platform/renesas/rcar_jpu.c | 4 ++-- >>>>> drivers/media/platform/renesas/vsp1/vsp1_video.c | 2 +- >>>>> drivers/media/platform/rockchip/rga/rga.c | 2 +- >>>>> drivers/media/platform/rockchip/rkvdec/rkvdec.c | 2 +- >>>>> drivers/media/platform/samsung/exynos-gsc/gsc-m2m.c | 4 ++-- >>>>> drivers/media/platform/samsung/exynos4-is/fimc-m2m.c | 4 ++-- >>>>> drivers/media/platform/samsung/s5p-g2d/g2d.c | 2 +- >>>>> drivers/media/platform/samsung/s5p-jpeg/jpeg-core.c | 4 ++-- >>>>> drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c | 4 ++-- >>>>> drivers/media/platform/st/sti/bdisp/bdisp-v4l2.c | 4 ++-- >>>>> drivers/media/platform/st/sti/delta/delta-v4l2.c | 4 ++-- >>>>> drivers/media/platform/st/sti/hva/hva-v4l2.c | 4 ++-- >>>>> drivers/media/platform/st/stm32/dma2d/dma2d.c | 2 +- >>>>> drivers/media/platform/sunxi/sun8i-di/sun8i-di.c | 2 +- >>>>> drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c | 2 +- >>>>> drivers/media/platform/ti/omap3isp/ispvideo.c | 5 ++--- >>>>> drivers/media/platform/ti/vpe/vpe.c | 2 +- >>>>> drivers/media/platform/verisilicon/hantro_drv.c | 4 ++-- >>>>> drivers/media/test-drivers/vicodec/vicodec-core.c | 2 +- >>>>> drivers/media/test-drivers/vim2m.c | 2 +- >>>>> drivers/media/test-drivers/visl/visl-core.c | 2 +- >>>>> drivers/media/usb/pvrusb2/pvrusb2-v4l2.c | 3 +-- >>>>> drivers/media/v4l2-core/v4l2-fh.c | 7 ++++--- >>>>> drivers/media/v4l2-core/v4l2-subdev.c | 5 ++--- >>>>> drivers/staging/media/imx/imx-media-csc-scaler.c | 4 ++-- >>>>> drivers/staging/media/meson/vdec/vdec.c | 2 +- >>>>> drivers/staging/media/sunxi/cedrus/cedrus.c | 2 +- >>>>> drivers/staging/most/video/video.c | 4 ++-- >>>>> drivers/usb/gadget/function/uvc_v4l2.c | 3 +-- >>>>> include/media/v4l2-fh.h | 5 ++++- >>>>> 57 files changed, 89 insertions(+), 90 deletions(-) >>>>> >>>> >>>> >>>> >>>>> diff --git a/drivers/media/v4l2-core/v4l2-fh.c b/drivers/media/v4l2-core/v4l2-fh.c >>>>> index b59b1084d8cdf1b62da12879e21dbe56c2109648..df3ba9d4674bd25626cfcddc2d0cb28c233e3cc3 100644 >>>>> --- a/drivers/media/v4l2-core/v4l2-fh.c >>>>> +++ b/drivers/media/v4l2-core/v4l2-fh.c >>>>> @@ -67,7 +67,7 @@ int v4l2_fh_open(struct file *filp) >>>>> } >>>>> EXPORT_SYMBOL_GPL(v4l2_fh_open); >>>>> >>>>> -void v4l2_fh_del(struct v4l2_fh *fh) >>>>> +void v4l2_fh_del(struct v4l2_fh *fh, struct file *filp) >>>> >>>> Instead of adding a second argument, perhaps it is better to >>>> just provide the filp pointer. After all, you can get the v4l2_fh >>>> from filp->private_data. >>>> >>>> It simplifies the code a bit. >>> >>> That's an interesting idea. I'll give it a try. >> >> We end up with code like (e.g. in v4l2_fh_release(), with similar >> constructs in lots of drivers) >> >> if (fh) { >> v4l2_fh_del(filp); >> v4l2_fh_exit(fh); >> kfree(fh); >> } >> >> compared to >> >> if (fh) { >> v4l2_fh_del(fh, filp); >> v4l2_fh_exit(fh); >> kfree(fh); >> } >> >> with the existing patch. I find the fact that v4l2_fh_del() takes a >> different pointer than v4l2_fh_exit() a bit disturbing. If you think >> it's better I'll drop the fh argument in v2. > > I gave it a try, and looking at the function prototype, its > documentation, the imbalance with v4l2_fh_add(), and the code in the > callers, I think keeping both arguments would look cleaner. Please tell > me if you feel strongly about this, I can still submit a patch to drop > the argument. It can very easily be scripted with coccinelle and doesn't > conflict with the rest of the series, so it could also be done later. Looking at all the drivers that call v4l2_fh_del/exit I always see v4l2_fh_del() directly followed by v4l2_fh_exit(). I think it would make a lot of sense to just combine the two as a single function: v4l2_fh_del_exit(filp). That simplifies the code and solves the imbalance. Regards, Hans > >>>>> { >>>>> unsigned long flags; >>>>> >>>>> @@ -75,6 +75,8 @@ void v4l2_fh_del(struct v4l2_fh *fh) >>>>> list_del_init(&fh->list); >>>>> spin_unlock_irqrestore(&fh->vdev->fh_lock, flags); >>>>> v4l2_prio_close(fh->vdev->prio, fh->prio); >>>>> + >>>>> + filp->private_data = NULL; >>>>> } >>>>> EXPORT_SYMBOL_GPL(v4l2_fh_del); >>>>> >>>>> @@ -94,10 +96,9 @@ int v4l2_fh_release(struct file *filp) >>>>> struct v4l2_fh *fh = file_to_v4l2_fh(filp); >>>>> >>>>> if (fh) { >>>>> - v4l2_fh_del(fh); >>>>> + v4l2_fh_del(fh, filp); >>>>> v4l2_fh_exit(fh); >>>>> kfree(fh); >>>>> - filp->private_data = NULL; >>>>> } >>>>> return 0; >>>>> } >>>> >>>> >>>> >>>>> diff --git a/include/media/v4l2-fh.h b/include/media/v4l2-fh.h >>>>> index d8fcf49f10e09452b73499f4a9bd1285bc2835a5..5e4c761635120608e0b588e0b0daf63e69588d38 100644 >>>>> --- a/include/media/v4l2-fh.h >>>>> +++ b/include/media/v4l2-fh.h >>>>> @@ -114,12 +114,15 @@ int v4l2_fh_open(struct file *filp); >>>>> * v4l2_fh_del - Remove file handle from the list of file handles. >>>>> * >>>>> * @fh: pointer to &struct v4l2_fh >>>>> + * @filp: pointer to &struct file associated with @fh >>>>> + * >>>>> + * The function resets filp->private_data to NULL. >>>>> * >>>>> * .. note:: >>>>> * Must be called in v4l2_file_operations->release\(\) handler if the driver >>>>> * uses &struct v4l2_fh. >>>>> */ >>>>> -void v4l2_fh_del(struct v4l2_fh *fh); >>>>> +void v4l2_fh_del(struct v4l2_fh *fh, struct file *filp); >>>>> >>>>> /** >>>>> * v4l2_fh_exit - Release resources related to a file handle. > _______________________________________________ Linux-rockchip mailing list Linux-rockchip@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-rockchip