linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH AUTOSEL 5.16 01/59] media: staging: media: zoran: move videodev alloc
@ 2022-03-30 11:47 Sasha Levin
  2022-03-30 11:47 ` [PATCH AUTOSEL 5.16 02/59] media: staging: media: zoran: calculate the right buffer number for zoran_reap_stat_com Sasha Levin
                   ` (57 more replies)
  0 siblings, 58 replies; 60+ messages in thread
From: Sasha Levin @ 2022-03-30 11:47 UTC (permalink / raw)
  To: linux-kernel, stable
  Cc: Corentin Labbe, Hans Verkuil, Mauro Carvalho Chehab, Sasha Levin,
	gregkh, linux-media, devel

From: Corentin Labbe <clabbe@baylibre.com>

[ Upstream commit 82e3a496eb56da0b9f29fdc5b63cedb3289e91de ]

Move some code out of zr36057_init() and create new functions for handling
zr->video_dev. This permit to ease code reading and fix a zr->video_dev
memory leak.

Signed-off-by: Corentin Labbe <clabbe@baylibre.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/staging/media/zoran/zoran.h        |  2 +-
 drivers/staging/media/zoran/zoran_card.c   | 80 ++++++++++++++--------
 drivers/staging/media/zoran/zoran_driver.c |  5 +-
 3 files changed, 54 insertions(+), 33 deletions(-)

diff --git a/drivers/staging/media/zoran/zoran.h b/drivers/staging/media/zoran/zoran.h
index b1ad2a2b914c..50d5a7acfab6 100644
--- a/drivers/staging/media/zoran/zoran.h
+++ b/drivers/staging/media/zoran/zoran.h
@@ -313,6 +313,6 @@ static inline struct zoran *to_zoran(struct v4l2_device *v4l2_dev)
 
 #endif
 
-int zoran_queue_init(struct zoran *zr, struct vb2_queue *vq);
+int zoran_queue_init(struct zoran *zr, struct vb2_queue *vq, int dir);
 void zoran_queue_exit(struct zoran *zr);
 int zr_set_buf(struct zoran *zr);
diff --git a/drivers/staging/media/zoran/zoran_card.c b/drivers/staging/media/zoran/zoran_card.c
index f259585b0689..677d3a26cef4 100644
--- a/drivers/staging/media/zoran/zoran_card.c
+++ b/drivers/staging/media/zoran/zoran_card.c
@@ -803,6 +803,52 @@ int zoran_check_jpg_settings(struct zoran *zr,
 	return 0;
 }
 
+static int zoran_init_video_device(struct zoran *zr, struct video_device *video_dev, int dir)
+{
+	int err;
+
+	/* Now add the template and register the device unit. */
+	*video_dev = zoran_template;
+	video_dev->v4l2_dev = &zr->v4l2_dev;
+	video_dev->lock = &zr->lock;
+	video_dev->device_caps = V4L2_CAP_STREAMING | dir;
+
+	strscpy(video_dev->name, ZR_DEVNAME(zr), sizeof(video_dev->name));
+	/*
+	 * It's not a mem2mem device, but you can both capture and output from one and the same
+	 * device. This should really be split up into two device nodes, but that's a job for
+	 * another day.
+	 */
+	video_dev->vfl_dir = VFL_DIR_M2M;
+	zoran_queue_init(zr, &zr->vq, V4L2_BUF_TYPE_VIDEO_CAPTURE);
+
+	err = video_register_device(video_dev, VFL_TYPE_VIDEO, video_nr[zr->id]);
+	if (err < 0)
+		return err;
+	video_set_drvdata(video_dev, zr);
+	return 0;
+}
+
+static void zoran_exit_video_devices(struct zoran *zr)
+{
+	video_unregister_device(zr->video_dev);
+	kfree(zr->video_dev);
+}
+
+static int zoran_init_video_devices(struct zoran *zr)
+{
+	int err;
+
+	zr->video_dev = video_device_alloc();
+	if (!zr->video_dev)
+		return -ENOMEM;
+
+	err = zoran_init_video_device(zr, zr->video_dev, V4L2_CAP_VIDEO_CAPTURE);
+	if (err)
+		kfree(zr->video_dev);
+	return err;
+}
+
 void zoran_open_init_params(struct zoran *zr)
 {
 	int i;
@@ -874,17 +920,11 @@ static int zr36057_init(struct zoran *zr)
 	zoran_open_init_params(zr);
 
 	/* allocate memory *before* doing anything to the hardware in case allocation fails */
-	zr->video_dev = video_device_alloc();
-	if (!zr->video_dev) {
-		err = -ENOMEM;
-		goto exit;
-	}
 	zr->stat_com = dma_alloc_coherent(&zr->pci_dev->dev,
 					  BUZ_NUM_STAT_COM * sizeof(u32),
 					  &zr->p_sc, GFP_KERNEL);
 	if (!zr->stat_com) {
-		err = -ENOMEM;
-		goto exit_video;
+		return -ENOMEM;
 	}
 	for (j = 0; j < BUZ_NUM_STAT_COM; j++)
 		zr->stat_com[j] = cpu_to_le32(1); /* mark as unavailable to zr36057 */
@@ -897,26 +937,9 @@ static int zr36057_init(struct zoran *zr)
 		goto exit_statcom;
 	}
 
-	/* Now add the template and register the device unit. */
-	*zr->video_dev = zoran_template;
-	zr->video_dev->v4l2_dev = &zr->v4l2_dev;
-	zr->video_dev->lock = &zr->lock;
-	zr->video_dev->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_CAPTURE;
-
-	strscpy(zr->video_dev->name, ZR_DEVNAME(zr), sizeof(zr->video_dev->name));
-	/*
-	 * It's not a mem2mem device, but you can both capture and output from one and the same
-	 * device. This should really be split up into two device nodes, but that's a job for
-	 * another day.
-	 */
-	zr->video_dev->vfl_dir = VFL_DIR_M2M;
-
-	zoran_queue_init(zr, &zr->vq);
-
-	err = video_register_device(zr->video_dev, VFL_TYPE_VIDEO, video_nr[zr->id]);
-	if (err < 0)
+	err = zoran_init_video_devices(zr);
+	if (err)
 		goto exit_statcomb;
-	video_set_drvdata(zr->video_dev, zr);
 
 	zoran_init_hardware(zr);
 	if (!pass_through) {
@@ -931,9 +954,6 @@ static int zr36057_init(struct zoran *zr)
 	dma_free_coherent(&zr->pci_dev->dev, BUZ_NUM_STAT_COM * sizeof(u32) * 2, zr->stat_comb, zr->p_scb);
 exit_statcom:
 	dma_free_coherent(&zr->pci_dev->dev, BUZ_NUM_STAT_COM * sizeof(u32), zr->stat_com, zr->p_sc);
-exit_video:
-	kfree(zr->video_dev);
-exit:
 	return err;
 }
 
@@ -965,7 +985,7 @@ static void zoran_remove(struct pci_dev *pdev)
 	dma_free_coherent(&zr->pci_dev->dev, BUZ_NUM_STAT_COM * sizeof(u32) * 2, zr->stat_comb, zr->p_scb);
 	pci_release_regions(pdev);
 	pci_disable_device(zr->pci_dev);
-	video_unregister_device(zr->video_dev);
+	zoran_exit_video_devices(zr);
 exit_free:
 	v4l2_ctrl_handler_free(&zr->hdl);
 	v4l2_device_unregister(&zr->v4l2_dev);
diff --git a/drivers/staging/media/zoran/zoran_driver.c b/drivers/staging/media/zoran/zoran_driver.c
index 46382e43f1bf..551db338c7f7 100644
--- a/drivers/staging/media/zoran/zoran_driver.c
+++ b/drivers/staging/media/zoran/zoran_driver.c
@@ -1008,7 +1008,7 @@ static const struct vb2_ops zr_video_qops = {
 	.wait_finish            = vb2_ops_wait_finish,
 };
 
-int zoran_queue_init(struct zoran *zr, struct vb2_queue *vq)
+int zoran_queue_init(struct zoran *zr, struct vb2_queue *vq, int dir)
 {
 	int err;
 
@@ -1016,7 +1016,8 @@ int zoran_queue_init(struct zoran *zr, struct vb2_queue *vq)
 	INIT_LIST_HEAD(&zr->queued_bufs);
 
 	vq->dev = &zr->pci_dev->dev;
-	vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+	vq->type = dir;
+
 	vq->io_modes = VB2_USERPTR | VB2_DMABUF | VB2_MMAP | VB2_READ | VB2_WRITE;
 	vq->drv_priv = zr;
 	vq->buf_struct_size = sizeof(struct zr_buffer);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 60+ messages in thread

end of thread, other threads:[~2022-04-02 16:35 UTC | newest]

Thread overview: 60+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-30 11:47 [PATCH AUTOSEL 5.16 01/59] media: staging: media: zoran: move videodev alloc Sasha Levin
2022-03-30 11:47 ` [PATCH AUTOSEL 5.16 02/59] media: staging: media: zoran: calculate the right buffer number for zoran_reap_stat_com Sasha Levin
2022-03-30 11:47 ` [PATCH AUTOSEL 5.16 03/59] media: staging: media: zoran: fix various V4L2 compliance errors Sasha Levin
2022-03-30 11:47 ` [PATCH AUTOSEL 5.16 04/59] media: atmel: atmel-isc-base: report frame sizes as full supported range Sasha Levin
2022-03-30 11:47 ` [PATCH AUTOSEL 5.16 05/59] media: ir_toy: free before error exiting Sasha Levin
2022-03-30 11:47 ` [PATCH AUTOSEL 5.16 06/59] ASoC: sh: rz-ssi: Make the data structures available before registering the handlers Sasha Levin
2022-03-30 11:47 ` [PATCH AUTOSEL 5.16 07/59] ASoC: cs42l42: Report full jack status when plug is detected Sasha Levin
2022-03-30 11:47 ` [PATCH AUTOSEL 5.16 08/59] ASoC: SOF: Intel: match sdw version on link_slaves_found Sasha Levin
2022-03-30 11:47 ` [PATCH AUTOSEL 5.16 09/59] media: imx-jpeg: Prevent decoding NV12M jpegs into single-planar buffers Sasha Levin
2022-03-30 11:47 ` [PATCH AUTOSEL 5.16 10/59] ASoC: SOF: Intel: hda: Remove link assignment limitation Sasha Levin
2022-03-30 11:47 ` [PATCH AUTOSEL 5.16 11/59] media: iommu/mediatek-v1: Free the existed fwspec if the master dev already has Sasha Levin
2022-03-30 11:47 ` [PATCH AUTOSEL 5.16 12/59] media: iommu/mediatek: Return ENODEV if the device is NULL Sasha Levin
2022-03-30 11:47 ` [PATCH AUTOSEL 5.16 13/59] media: iommu/mediatek: Add device_link between the consumer and the larb devices Sasha Levin
2022-03-30 11:47 ` [PATCH AUTOSEL 5.16 14/59] video: fbdev: nvidiafb: Use strscpy() to prevent buffer overflow Sasha Levin
2022-03-30 11:47 ` [PATCH AUTOSEL 5.16 15/59] video: fbdev: w100fb: Reset global state Sasha Levin
2022-03-30 11:47 ` [PATCH AUTOSEL 5.16 16/59] video: fbdev: cirrusfb: check pixclock to avoid divide by zero Sasha Levin
2022-03-30 11:47 ` [PATCH AUTOSEL 5.16 17/59] video: fbdev: omapfb: acx565akm: replace snprintf with sysfs_emit Sasha Levin
2022-03-30 11:47 ` [PATCH AUTOSEL 5.16 18/59] ARM: dts: qcom: fix gic_irq_domain_translate warnings for msm8960 Sasha Levin
2022-03-30 11:47 ` [PATCH AUTOSEL 5.16 19/59] ARM: dts: bcm2837: Add the missing L1/L2 cache information Sasha Levin
2022-03-30 11:47 ` [PATCH AUTOSEL 5.16 20/59] ASoC: madera: Add dependencies on MFD Sasha Levin
2022-03-30 11:47 ` [PATCH AUTOSEL 5.16 21/59] media: atomisp_gmin_platform: Add DMI quirk to not turn AXP ELDO2 regulator off on some boards Sasha Levin
2022-03-30 11:47 ` [PATCH AUTOSEL 5.16 22/59] media: atomisp: fix dummy_ptr check to avoid duplicate active_bo Sasha Levin
2022-03-30 11:47 ` [PATCH AUTOSEL 5.16 23/59] ARM: ftrace: avoid redundant loads or clobbering IP Sasha Levin
2022-03-30 11:47 ` [PATCH AUTOSEL 5.16 24/59] ALSA: hda: Fix driver index handling at re-binding Sasha Levin
2022-03-30 11:47 ` [PATCH AUTOSEL 5.16 25/59] ARM: dts: imx7: Use audio_mclk_post_div instead audio_mclk_root_clk Sasha Levin
2022-03-30 11:47 ` [PATCH AUTOSEL 5.16 26/59] arm64: defconfig: build imx-sdma as a module Sasha Levin
2022-03-30 11:47 ` [PATCH AUTOSEL 5.16 27/59] video: fbdev: omapfb: panel-dsi-cm: Use sysfs_emit() instead of snprintf() Sasha Levin
2022-03-30 11:48 ` [PATCH AUTOSEL 5.16 28/59] video: fbdev: omapfb: panel-tpo-td043mtea1: " Sasha Levin
2022-03-30 11:48 ` [PATCH AUTOSEL 5.16 29/59] video: fbdev: udlfb: replace snprintf in show functions with sysfs_emit Sasha Levin
2022-03-30 11:48 ` [PATCH AUTOSEL 5.16 30/59] ARM: dts: bcm2711: Add the missing L1/L2 cache information Sasha Levin
2022-03-30 11:48 ` [PATCH AUTOSEL 5.16 31/59] printk: Add panic_in_progress helper Sasha Levin
2022-03-30 11:48 ` [PATCH AUTOSEL 5.16 32/59] printk: Avoid livelock with heavy printk during panic Sasha Levin
2022-03-30 11:48 ` [PATCH AUTOSEL 5.16 33/59] printk: Drop console_sem " Sasha Levin
2022-03-30 11:48 ` [PATCH AUTOSEL 5.16 34/59] ASoC: soc-core: skip zero num_dai component in searching dai name Sasha Levin
2022-03-30 11:48 ` [PATCH AUTOSEL 5.16 35/59] printk: use atomic updates for klogd work Sasha Levin
2022-03-30 11:48 ` [PATCH AUTOSEL 5.16 36/59] ASoC: Intel: sof_es8336: add quirk for Huawei D15 2021 Sasha Levin
2022-03-30 11:48 ` [PATCH AUTOSEL 5.16 37/59] media: imx-jpeg: fix a bug of accessing array out of bounds Sasha Levin
2022-03-30 11:48 ` [PATCH AUTOSEL 5.16 38/59] media: cx88-mpeg: clear interrupt status register before streaming video Sasha Levin
2022-03-30 11:48 ` [PATCH AUTOSEL 5.16 39/59] ASoC: rt5682s: Fix the wrong jack type detected Sasha Levin
2022-03-30 11:48 ` [PATCH AUTOSEL 5.16 40/59] uaccess: fix type mismatch warnings from access_ok() Sasha Levin
2022-03-30 11:48 ` [PATCH AUTOSEL 5.16 41/59] lib/test_lockup: fix kernel pointer check for separate address spaces Sasha Levin
2022-03-30 11:48 ` [PATCH AUTOSEL 5.16 42/59] ARM: tegra: tamonten: Fix I2C3 pad setting Sasha Levin
2022-03-30 11:48 ` [PATCH AUTOSEL 5.16 43/59] ARM: mmp: Fix failure to remove sram device Sasha Levin
2022-03-30 11:48 ` [PATCH AUTOSEL 5.16 44/59] ASoC: amd: vg: fix for pm resume callback sequence Sasha Levin
2022-03-30 11:48 ` [PATCH AUTOSEL 5.16 45/59] ASoC: amd: vangogh: fix uninitialized symbol warning in machine driver Sasha Levin
2022-03-30 11:48 ` [PATCH AUTOSEL 5.16 46/59] video: fbdev: sm712fb: Fix crash in smtcfb_write() Sasha Levin
2022-03-30 11:48 ` [PATCH AUTOSEL 5.16 47/59] media: i2c: ov5648: Fix lockdep error Sasha Levin
2022-03-30 11:48 ` [PATCH AUTOSEL 5.16 48/59] media: Revert "media: em28xx: add missing em28xx_close_extension" Sasha Levin
2022-03-30 11:48 ` [PATCH AUTOSEL 5.16 49/59] media: hdpvr: initialize dev->worker at hdpvr_register_videodev Sasha Levin
2022-03-30 11:48 ` [PATCH AUTOSEL 5.16 50/59] ASoC: Intel: sof_sdw: fix quirks for 2022 HP Spectre x360 13" Sasha Levin
2022-03-30 11:48 ` [PATCH AUTOSEL 5.16 51/59] ASoC: Intel: soc-acpi: add more ACPI HIDs for ES83x6 devices Sasha Levin
2022-03-30 11:48 ` [PATCH AUTOSEL 5.16 52/59] ASoC: Intel: Revert "ASoC: Intel: sof_es8336: add quirk for Huawei D15 2021" Sasha Levin
2022-03-30 11:48 ` [PATCH AUTOSEL 5.16 53/59] ASoC: Intel: sof_es8336: use NHLT information to set dmic and SSP Sasha Levin
2022-03-30 11:48 ` [PATCH AUTOSEL 5.16 54/59] ASoC: Intel: sof_es8336: log all quirks Sasha Levin
2022-04-02 16:35   ` Mauro Carvalho Chehab
2022-03-30 11:48 ` [PATCH AUTOSEL 5.16 55/59] tracing: Have TRACE_DEFINE_ENUM affect trace event types as well Sasha Levin
2022-03-30 11:48 ` [PATCH AUTOSEL 5.16 56/59] mmc: host: Return an error when ->enable_sdio_irq() ops is missing Sasha Levin
2022-03-30 11:48 ` [PATCH AUTOSEL 5.16 57/59] ASoC: ak4642: Use of_device_get_match_data() Sasha Levin
2022-03-30 11:48 ` [PATCH AUTOSEL 5.16 58/59] media: atomisp: fix bad usage at error handling logic Sasha Levin
2022-03-30 11:48 ` [PATCH AUTOSEL 5.16 59/59] ALSA: hda/realtek: Add alc256-samsung-headphone fixup Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).