From nobody Sun Oct 5 16:16:32 2025 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3949D224891; Sat, 2 Aug 2025 09:25:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754126732; cv=none; b=in/z1/dNzS7pj1laqgEXT78T48w3MNXa+ael0fe7j4EED2MlxSSMz8MJ+381+Lw/J3O3D1d+O2CZcsEC8LiMvSz+GoqEFXf+E/isY9YG8jbBJ9Fq+0smPGtbW5Aw6cvqQhMf9zc1T1BiJHcowcEftFe9aq1zsodXkBvvPZ2usqo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754126732; c=relaxed/simple; bh=h5udZ1SzPumXnE7xu2zWQT6vfdKtMoA3NyZ01lPUHuA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=k2/cttjHGI3lWhgQHO3z6Pan0nFLpo0oUYn0brZuyAClPbgvZPa4RxpsLCrusNafxE3HngnJDYKnYBKpf4e45K1FZFl0FQYB1blSfPMj9ZOfCLOkJJR8hAGdpSo6AB9xF5guOtweJDGZ1+CrrQi8vYoCHbYmFkQ6IHd3BNs/KUc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=iM9OfLxj; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="iM9OfLxj" Received: from [192.168.0.172] (mob-5-90-138-121.net.vodafone.it [5.90.138.121]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A80C42F0D; Sat, 2 Aug 2025 11:24:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1754126683; bh=h5udZ1SzPumXnE7xu2zWQT6vfdKtMoA3NyZ01lPUHuA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=iM9OfLxjFezRevsFSM+DHzmuj7nNeL7ocIFelwKtOOkub03t9gmFJnj5/MndtBa1u 1XukpB+YRy0Co1GOWWW3SG+Dxx0BaUMXn+oMf3Bj0kz24biyJYcQAGPxrgLXbniG5N a+YY9PwN+Cv72yF31/RICanxWaiXB8p++jEUVsBE= From: Jacopo Mondi Date: Sat, 02 Aug 2025 11:22:34 +0200 Subject: [PATCH 12/65] media: pci: ivtv: Don't create fake v4l2_fh Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250802-media-private-data-v1-12-eb140ddd6a9d@ideasonboard.com> References: <20250802-media-private-data-v1-0-eb140ddd6a9d@ideasonboard.com> In-Reply-To: <20250802-media-private-data-v1-0-eb140ddd6a9d@ideasonboard.com> To: Mauro Carvalho Chehab , Devarsh Thakkar , Benoit Parrot , Hans Verkuil , Mike Isely , Laurent Pinchart , 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 Cc: 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, Jacopo Mondi X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=6700; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=2/+7JKVHQ0FUPAMFvnWgDgM7Mra+DCKmELJTQXBkvDA=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBojdj4n5+bYKeplnUHvNaRht9BxmiwNfWLvjFfp RrwjLb0lYOJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaI3Y+AAKCRByNAaPFqFW PAmHD/4mhFhl/805WB3JLxIhy7zUPvIxr2/l7bll6BZb+Uwp4egXUM6l3Wr+RH/zsD/o7f2JO4p IKeuRxRQTW4A6Tbfa0RzfC6hysVeMWcv3mjkcBug3surPW4kuftKxbMbnm1t5Jk5jwN+j3H3q3P eCxZdeV65ONT4MJT2N8YblptRqH6aV9BdTdCP6b30dJwQy1e14T37qbNRtfHQBhxT7rML4K1DDj c6Qj1hrlyc/CkG07XT9hZUhGcwB7ra0b/2L7bp+8ijuhR0q7KGvXTKZ/Oq8SrINLvVgisiFfWKw iRc7K8Q7Rqk7503ezMkGbAskIlbn4kPaaSrCYUFQOGooexgaAGuevht3vw0PkMxW+lO+z3eqh1e hKtEbNAhnjZA5t0fxtpBNZK5XJqjsYLeEpSizSVzVVuEcMvMry+oTTLbhGcPrgRWtnqoh29L8QD YcRbxMcnzpw2+buRGdOHPm+9CUTmz71/80mKyigU7RFsBLwYY3+YIMBxSOu+l7XCVNKgq6AQ2ev hxXxr6rTciajnOManNEKxiWuM90o5SjS5WjkGDvJp+2GlRuEP0Hbq1HYXPjvSzbg11HgjbEHwfl o3wfhk1v6eO4g7gbV9Q4Z6NtQC7PxdjPkPVdcJC9akSlAlM/jjzolxFItGYzjltOT6bmjh193f3 Dpt/CwXPkT8LQTA== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B From: Laurent Pinchart The ivtv driver has a structure named ivtv_open_id that models an open file handle for the device. It embeds a v4l2_fh instance for file handles that correspond to a V4L2 video device, and stores a pointer to that v4l2_fh in struct ivtv_stream to identify which open file handle owns a particular stream. In addition to video devices, streams can be owned by ALSA PCM devices. Those devices do not make use of the v4l2_fh instance for obvious reasons, but the snd_ivtv_pcm_capture_open() function still initializes a "fake" v4l2_fh for the sole purpose of using it as an open file handle identifier. The v4l2_fh is not properly destroyed when the ALSA PCM device is closed, leading to possible resource leaks. Fortunately, the v4l2_fh instance pointed to by ivtv_stream is not accessed, only the pointer value is used for comparison. Replace it with a pointer to the ivtv_open_id structure that embeds the v4l2_fh, and don't initialize the v4l2_fh for ALSA PCM devices. Signed-off-by: Laurent Pinchart Signed-off-by: Jacopo Mondi --- drivers/media/pci/ivtv/ivtv-alsa-pcm.c | 2 -- drivers/media/pci/ivtv/ivtv-driver.h | 3 ++- drivers/media/pci/ivtv/ivtv-fileops.c | 18 +++++++++--------- drivers/media/pci/ivtv/ivtv-irq.c | 4 ++-- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/drivers/media/pci/ivtv/ivtv-alsa-pcm.c b/drivers/media/pci/ivt= v/ivtv-alsa-pcm.c index 8f346d7da9c8defb12191c3addb12a118547b9a0..269a799ec046c67265484945acf= 89a5fbd40a3f4 100644 --- a/drivers/media/pci/ivtv/ivtv-alsa-pcm.c +++ b/drivers/media/pci/ivtv/ivtv-alsa-pcm.c @@ -148,14 +148,12 @@ static int snd_ivtv_pcm_capture_open(struct snd_pcm_s= ubstream *substream) =20 s =3D &itv->streams[IVTV_ENC_STREAM_TYPE_PCM]; =20 - v4l2_fh_init(&item.fh, &s->vdev); item.itv =3D itv; item.type =3D s->type; =20 /* See if the stream is available */ if (ivtv_claim_stream(&item, item.type)) { /* No, it's already in use */ - v4l2_fh_exit(&item.fh); snd_ivtv_unlock(itvsc); return -EBUSY; } diff --git a/drivers/media/pci/ivtv/ivtv-driver.h b/drivers/media/pci/ivtv/= ivtv-driver.h index cad548b28e360ecfe2bcb9fcb5d12cd8823c3727..38c4ceb04cf834906ed877b57c2= 0fcbdb390da13 100644 --- a/drivers/media/pci/ivtv/ivtv-driver.h +++ b/drivers/media/pci/ivtv/ivtv-driver.h @@ -322,6 +322,7 @@ struct ivtv_queue { }; =20 struct ivtv; /* forward reference */ +struct ivtv_open_id; =20 struct ivtv_stream { /* These first four fields are always set, even if the stream @@ -331,7 +332,7 @@ struct ivtv_stream { const char *name; /* name of the stream */ int type; /* stream type */ =20 - struct v4l2_fh *fh; /* pointer to the streaming filehandle */ + struct ivtv_open_id *id; /* pointer to the streaming ivtv_open_id */ spinlock_t qlock; /* locks access to the queues */ unsigned long s_flags; /* status flags, see above */ int dma; /* can be PCI_DMA_TODEVICE, PCI_DMA_FROMDEVICE or PCI_DMA_NONE= */ diff --git a/drivers/media/pci/ivtv/ivtv-fileops.c b/drivers/media/pci/ivtv= /ivtv-fileops.c index cc91695a5b7605dcd964bd2c68bb12f645dc302f..67964a3c382c6627a7b3ce6380a= 2da97dcc47c3d 100644 --- a/drivers/media/pci/ivtv/ivtv-fileops.c +++ b/drivers/media/pci/ivtv/ivtv-fileops.c @@ -39,16 +39,16 @@ int ivtv_claim_stream(struct ivtv_open_id *id, int type) =20 if (test_and_set_bit(IVTV_F_S_CLAIMED, &s->s_flags)) { /* someone already claimed this stream */ - if (s->fh =3D=3D &id->fh) { + if (s->id =3D=3D id) { /* yes, this file descriptor did. So that's OK. */ return 0; } - if (s->fh =3D=3D NULL && (type =3D=3D IVTV_DEC_STREAM_TYPE_VBI || + if (s->id =3D=3D NULL && (type =3D=3D IVTV_DEC_STREAM_TYPE_VBI || type =3D=3D IVTV_ENC_STREAM_TYPE_VBI)) { /* VBI is handled already internally, now also assign the file descriptor to this stream for external reading of the stream. */ - s->fh =3D &id->fh; + s->id =3D id; IVTV_DEBUG_INFO("Start Read VBI\n"); return 0; } @@ -56,7 +56,7 @@ int ivtv_claim_stream(struct ivtv_open_id *id, int type) IVTV_DEBUG_INFO("Stream %d is busy\n", type); return -EBUSY; } - s->fh =3D &id->fh; + s->id =3D id; if (type =3D=3D IVTV_DEC_STREAM_TYPE_VBI) { /* Enable reinsertion interrupt */ ivtv_clear_irq_mask(itv, IVTV_IRQ_DEC_VBI_RE_INSERT); @@ -94,7 +94,7 @@ void ivtv_release_stream(struct ivtv_stream *s) struct ivtv *itv =3D s->itv; struct ivtv_stream *s_vbi; =20 - s->fh =3D NULL; + s->id =3D NULL; if ((s->type =3D=3D IVTV_DEC_STREAM_TYPE_VBI || s->type =3D=3D IVTV_ENC_S= TREAM_TYPE_VBI) && test_bit(IVTV_F_S_INTERNAL_USE, &s->s_flags)) { /* this stream is still in use internally */ @@ -126,7 +126,7 @@ void ivtv_release_stream(struct ivtv_stream *s) /* was already cleared */ return; } - if (s_vbi->fh) { + if (s_vbi->id) { /* VBI stream still claimed by a file descriptor */ return; } @@ -359,7 +359,7 @@ static ssize_t ivtv_read(struct ivtv_stream *s, char __= user *ubuf, size_t tot_co size_t tot_written =3D 0; int single_frame =3D 0; =20 - if (atomic_read(&itv->capturing) =3D=3D 0 && s->fh =3D=3D NULL) { + if (atomic_read(&itv->capturing) =3D=3D 0 && s->id =3D=3D NULL) { /* shouldn't happen */ IVTV_DEBUG_WARN("Stream %s not initialized before read\n", s->name); return -EIO; @@ -831,7 +831,7 @@ void ivtv_stop_capture(struct ivtv_open_id *id, int gop= _end) id->type =3D=3D IVTV_ENC_STREAM_TYPE_VBI) && test_bit(IVTV_F_S_INTERNAL_USE, &s->s_flags)) { /* Also used internally, don't stop capturing */ - s->fh =3D NULL; + s->id =3D NULL; } else { ivtv_stop_v4l2_encode_stream(s, gop_end); @@ -915,7 +915,7 @@ int ivtv_v4l2_close(struct file *filp) v4l2_fh_exit(fh); =20 /* Easy case first: this stream was never claimed by us */ - if (s->fh !=3D &id->fh) + if (s->id !=3D id) goto close_done; =20 /* 'Unclaim' this stream */ diff --git a/drivers/media/pci/ivtv/ivtv-irq.c b/drivers/media/pci/ivtv/ivt= v-irq.c index 748c14e879632ae6f62c3cc1981a168b01ed060d..20ba5ae9c6d1d0e6e4d856d1f08= 3e30a0f9be321 100644 --- a/drivers/media/pci/ivtv/ivtv-irq.c +++ b/drivers/media/pci/ivtv/ivtv-irq.c @@ -305,7 +305,7 @@ static void dma_post(struct ivtv_stream *s) ivtv_process_vbi_data(itv, buf, 0, s->type); s->q_dma.bytesused +=3D buf->bytesused; } - if (s->fh =3D=3D NULL) { + if (s->id =3D=3D NULL) { ivtv_queue_move(s, &s->q_dma, NULL, &s->q_free, 0); return; } @@ -330,7 +330,7 @@ static void dma_post(struct ivtv_stream *s) set_bit(IVTV_F_I_HAVE_WORK, &itv->i_flags); } =20 - if (s->fh) + if (s->id) wake_up(&s->waitq); } =20 --=20 2.49.0