[EXT] [PATCH 14/65] media: amphion: Delete v4l2_fh synchronously in .release()

Ming Qian ming.qian at nxp.com
Mon Aug 4 18:43:48 PDT 2025



>-----Original Message-----
>From: Jacopo Mondi <jacopo.mondi at ideasonboard.com>
>Sent: Saturday, August 2, 2025 5:23 PM
>To: Mauro Carvalho Chehab <mchehab at kernel.org>; Devarsh Thakkar
><devarsht at ti.com>; Benoit Parrot <bparrot at ti.com>; Hans Verkuil
><hverkuil at kernel.org>; Mike Isely <isely at pobox.com>; Laurent Pinchart
><laurent.pinchart at ideasonboard.com>; Hans de Goede <hansg at kernel.org>;
>Parthiban Veerasooran <parthiban.veerasooran at microchip.com>; Christian
>Gromm <christian.gromm at microchip.com>; Greg Kroah-Hartman
><gregkh at linuxfoundation.org>; Alex Shi <alexs at kernel.org>; Yanteng Si
><si.yanteng at linux.dev>; Dongliang Mu <dzm91 at hust.edu.cn>; Jonathan
>Corbet <corbet at lwn.net>; Tomasz Figa <tfiga at chromium.org>; Marek
>Szyprowski <m.szyprowski at samsung.com>; Andy Walls
><awalls at md.metrocast.net>; Michael Tretter <m.tretter at pengutronix.de>;
>Pengutronix Kernel Team <kernel at pengutronix.de>; Bin Liu
><bin.liu at mediatek.com>; Matthias Brugger <matthias.bgg at gmail.com>;
>AngeloGioacchino Del Regno <angelogioacchino.delregno at collabora.com>;
>Dmitry Osipenko <digetx at gmail.com>; Thierry Reding
><thierry.reding at gmail.com>; Jonathan Hunter <jonathanh at nvidia.com>;
>Mirela Rabulea <mirela.rabulea at nxp.com>; Shawn Guo
><shawnguo at kernel.org>; Sascha Hauer <s.hauer at pengutronix.de>; Fabio
>Estevam <festevam at gmail.com>; Kieran Bingham
><kieran.bingham+renesas at ideasonboard.com>; Michal Simek
><michal.simek at amd.com>; Ming Qian <ming.qian at nxp.com>; Eagle Zhou
><eagle.zhou at nxp.com>; Xavier Roumegue (OSS)
><xavier.roumegue at oss.nxp.com>; Philipp Zabel <p.zabel at pengutronix.de>;
>Vikash Garodia <quic_vgarodia at quicinc.com>; Dikshita Agarwal
><quic_dikshita at quicinc.com>; Abhinav Kumar <abhinav.kumar at linux.dev>;
>Bryan O'Donoghue <bryan.odonoghue at linaro.org>; Sylwester Nawrocki
><sylvester.nawrocki at gmail.com>; Jernej Skrabec <jernej.skrabec at gmail.com>;
>Chen-Yu Tsai <wens at csie.org>; Samuel Holland <samuel at sholland.org>;
>Daniel Almeida <daniel.almeida at collabora.com>; Neil Armstrong
><neil.armstrong at linaro.org>; Kevin Hilman <khilman at baylibre.com>; Jerome
>Brunet <jbrunet at baylibre.com>; Martin Blumenstingl
><martin.blumenstingl at googlemail.com>; Nas Chung
><nas.chung at chipsnmedia.com>; Jackson Lee
><jackson.lee at chipsnmedia.com>; Minghsiu Tsai
><minghsiu.tsai at mediatek.com>; Houlong Wei <houlong.wei at mediatek.com>;
>Andrew-CT Chen <andrew-ct.chen at mediatek.com>; Tiffany Lin
><tiffany.lin at mediatek.com>; Yunfei Dong <yunfei.dong at mediatek.com>;
>Geert Uytterhoeven <geert+renesas at glider.be>; Magnus Damm
><magnus.damm at gmail.com>; Mikhail Ulyanov
><mikhail.ulyanov at cogentembedded.com>; Jacob Chen <jacob-
>chen at iotwrt.com>; Ezequiel Garcia <ezequiel at vanguardiasur.com.ar>; Heiko
>Stuebner <heiko at sntech.de>; Detlev Casanova
><detlev.casanova at collabora.com>; Krzysztof Kozlowski <krzk at kernel.org>;
>Alim Akhtar <alim.akhtar at samsung.com>; Sylwester Nawrocki
><s.nawrocki at samsung.com>; Łukasz Stelmach <l.stelmach at samsung.com>;
>Andrzej Pietrasiewicz <andrzejtp2010 at gmail.com>; Jacek Anaszewski
><jacek.anaszewski at gmail.com>; Andrzej Hajda <andrzej.hajda at intel.com>;
>Fabien Dessenne <fabien.dessenne at foss.st.com>; Hugues Fruchet
><hugues.fruchet at foss.st.com>; Jean-Christophe Trotin <jean-
>christophe.trotin at foss.st.com>; Maxime Coquelin
><mcoquelin.stm32 at gmail.com>; Alexandre Torgue
><alexandre.torgue at foss.st.com>; Nicolas Dufresne
><nicolas.dufresne at collabora.com>; Benjamin Gaignard
><benjamin.gaignard at collabora.com>; Steve Longerbeam
><slongerbeam at gmail.com>; Maxime Ripard <mripard at kernel.org>; Paul
>Kocialkowski <paulk at sys-base.io>; Niklas Söderlund
><niklas.soderlund at ragnatech.se>; Robert Foss <rfoss at kernel.org>; Todor
>Tomov <todor.too at gmail.com>; Vladimir Zapolskiy
><vladimir.zapolskiy at linaro.org>; Corentin Labbe <clabbe at baylibre.com>;
>Sakari Ailus <sakari.ailus at linux.intel.com>; Bingbu Cao
><bingbu.cao at intel.com>; Tianshu Qiu <tian.shu.qiu at intel.com>; Stanislaw
>Gruszka <stanislaw.gruszka at linux.intel.com>
>Cc: linux-media at vger.kernel.org; linux-kernel at vger.kernel.org; linux-
>staging at lists.linux.dev; linux-doc at vger.kernel.org; linux-arm-
>kernel at lists.infradead.org; linux-mediatek at lists.infradead.org; linux-
>tegra at vger.kernel.org; imx at lists.linux.dev; linux-renesas-soc at vger.kernel.org;
>linux-arm-msm at vger.kernel.org; linux-samsung-soc at vger.kernel.org; linux-
>sunxi at lists.linux.dev; linux-usb at vger.kernel.org; linux-
>amlogic at lists.infradead.org; linux-rockchip at lists.infradead.org; linux-
>stm32 at st-md-mailman.stormreply.com; mjpeg-users at lists.sourceforge.net;
>Jacopo Mondi <jacopo.mondi at ideasonboard.com>
>Subject: [EXT] [PATCH 14/65] media: amphion: Delete v4l2_fh synchronously
>in .release()
>
>Caution: This is an external email. Please take care when clicking links or
>opening attachments. When in doubt, report the message using the 'Report
>this email' button
>
>
>From: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
>
>The v4l2_fh initialized and added in vpu_v4l2_open() is delete and cleaned up
>when the last reference to the vpu_inst is released. This may happen later than
>at vpu_v4l2_close() time.
>
>Not deleting and cleaning up the v4l2_fh when closing the file handle to the
>video device is not ideal, as the v4l2_fh will still be present in the video device's
>fh_list, and will store a copy of events queued to the video device. There may
>also be other side effects of keeping alive an object that represents an open file
>handle after the file handle is closed.
>
>The v4l2_fh instance is embedded in the vpu_inst structure, and is accessed in
>two different ways:
>
>- in vpu_notify_eos() and vpu_notify_source_change(), to queue V4L2
>  events to the file handle ; and
>
>- through the driver to access the v4l2_fh.m2m_ctx pointer.
>
>The v4l2_fh.m2m_ctx pointer is not touched by v4l2_fh_del() and
>v4l2_fh_exit(). It is set to NULL by the driver when closing the file handle, in
>vpu_v4l2_close().
>
>The vpu_notify_eos() and vpu_notify_source_change() functions are called in
>vpu_set_last_buffer_dequeued() and vdec_handle_resolution_change()
>respectively, only if the v4l2_fh.m2m_ctx pointer is not NULL. There is therefore
>a guarantee that no new event will be queued to the v4l2_fh after
>vpu_v4l2_close() destroys the m2m_ctx.
>
>The vpu_notify_eos() function is also called from vpu_vb2_buf_finish(), which
>is guaranteed to be called for all queued buffers when
>vpu_v4l2_close() calls v4l2_m2m_ctx_release(), and will not be called later.
>
>It is therefore safe to assume that the driver will not touch the v4l2_fh, except
>to check the m2m_ctx pointer, after vpu_v4l2_close() destroys the m2m_ctx.
>We can safely delete and cleanup the v4l2_fh synchronously in
>vpu_v4l2_close().
>
>Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
>Signed-off-by: Jacopo Mondi <jacopo.mondi at ideasonboard.com>

Reviewed-by: Ming Qian <ming.qian at oss.nxp.com>

>---
> drivers/media/platform/amphion/vpu_v4l2.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
>diff --git a/drivers/media/platform/amphion/vpu_v4l2.c
>b/drivers/media/platform/amphion/vpu_v4l2.c
>index
>306d94e0f8e79faaacfa35b28e5786860f7bd1ca..57ca6262bb04b356a85e217ef
>51cfb13cb9a0a36 100644
>--- a/drivers/media/platform/amphion/vpu_v4l2.c
>+++ b/drivers/media/platform/amphion/vpu_v4l2.c
>@@ -724,8 +724,6 @@ static int vpu_v4l2_release(struct vpu_inst *inst)
>
>        v4l2_ctrl_handler_free(&inst->ctrl_handler);
>        mutex_destroy(&inst->lock);
>-       v4l2_fh_del(&inst->fh);
>-       v4l2_fh_exit(&inst->fh);
>
>        call_void_vop(inst, cleanup);
>
>@@ -794,6 +792,8 @@ int vpu_v4l2_open(struct file *file, struct vpu_inst
>*inst)
>
>        return 0;
> error:
>+       v4l2_fh_del(&inst->fh);
>+       v4l2_fh_exit(&inst->fh);
>        vpu_inst_put(inst);
>        return ret;
> }
>@@ -813,6 +813,9 @@ int vpu_v4l2_close(struct file *file)
>        call_void_vop(inst, release);
>        vpu_inst_unlock(inst);
>
>+       v4l2_fh_del(&inst->fh);
>+       v4l2_fh_exit(&inst->fh);
>+
>        vpu_inst_unregister(inst);
>        vpu_inst_put(inst);
>
>
>--
>2.49.0



More information about the linux-amlogic mailing list