linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Daniel Niv <danielniv3@gmail.com>,
	Hans Verkuil <hverkuil-cisco@xs4all.nl>,
	Mauro Carvalho Chehab <mchehab+huawei@kernel.org>,
	Sasha Levin <sashal@kernel.org>,
	linux-media@vger.kernel.org
Subject: [PATCH AUTOSEL 4.19 08/35] media: media/saa7164: fix saa7164_encoder_register() memory leak bugs
Date: Mon,  3 May 2021 12:40:42 -0400	[thread overview]
Message-ID: <20210503164109.2853838-8-sashal@kernel.org> (raw)
In-Reply-To: <20210503164109.2853838-1-sashal@kernel.org>

From: Daniel Niv <danielniv3@gmail.com>

[ Upstream commit c759b2970c561e3b56aa030deb13db104262adfe ]

Add a fix for the memory leak bugs that can occur when the
saa7164_encoder_register() function fails.
The function allocates memory without explicitly freeing
it when errors occur.
Add a better error handling that deallocate the unused buffers before the
function exits during a fail.

Signed-off-by: Daniel Niv <danielniv3@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/media/pci/saa7164/saa7164-encoder.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/drivers/media/pci/saa7164/saa7164-encoder.c b/drivers/media/pci/saa7164/saa7164-encoder.c
index 32136ebe4f61..962f8eb73b05 100644
--- a/drivers/media/pci/saa7164/saa7164-encoder.c
+++ b/drivers/media/pci/saa7164/saa7164-encoder.c
@@ -1024,7 +1024,7 @@ int saa7164_encoder_register(struct saa7164_port *port)
 		printk(KERN_ERR "%s() failed (errno = %d), NO PCI configuration\n",
 			__func__, result);
 		result = -ENOMEM;
-		goto failed;
+		goto fail_pci;
 	}
 
 	/* Establish encoder defaults here */
@@ -1078,7 +1078,7 @@ int saa7164_encoder_register(struct saa7164_port *port)
 			  100000, ENCODER_DEF_BITRATE);
 	if (hdl->error) {
 		result = hdl->error;
-		goto failed;
+		goto fail_hdl;
 	}
 
 	port->std = V4L2_STD_NTSC_M;
@@ -1096,7 +1096,7 @@ int saa7164_encoder_register(struct saa7164_port *port)
 		printk(KERN_INFO "%s: can't allocate mpeg device\n",
 			dev->name);
 		result = -ENOMEM;
-		goto failed;
+		goto fail_hdl;
 	}
 
 	port->v4l_device->ctrl_handler = hdl;
@@ -1107,10 +1107,7 @@ int saa7164_encoder_register(struct saa7164_port *port)
 	if (result < 0) {
 		printk(KERN_INFO "%s: can't register mpeg device\n",
 			dev->name);
-		/* TODO: We're going to leak here if we don't dealloc
-		 The buffers above. The unreg function can't deal wit it.
-		*/
-		goto failed;
+		goto fail_reg;
 	}
 
 	printk(KERN_INFO "%s: registered device video%d [mpeg]\n",
@@ -1132,9 +1129,14 @@ int saa7164_encoder_register(struct saa7164_port *port)
 
 	saa7164_api_set_encoder(port);
 	saa7164_api_get_encoder(port);
+	return 0;
 
-	result = 0;
-failed:
+fail_reg:
+	video_device_release(port->v4l_device);
+	port->v4l_device = NULL;
+fail_hdl:
+	v4l2_ctrl_handler_free(hdl);
+fail_pci:
 	return result;
 }
 
-- 
2.30.2


  parent reply	other threads:[~2021-05-03 17:00 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-03 16:40 [PATCH AUTOSEL 4.19 01/35] scsi: lpfc: Fix incorrect dbde assignment when building target abts wqe Sasha Levin
2021-05-03 16:40 ` [PATCH AUTOSEL 4.19 02/35] scsi: lpfc: Fix pt2pt connection does not recover after LOGO Sasha Levin
2021-05-03 16:40 ` [PATCH AUTOSEL 4.19 03/35] scsi: target: pscsi: Fix warning in pscsi_complete_cmd() Sasha Levin
2021-05-03 16:40 ` [PATCH AUTOSEL 4.19 04/35] media: ite-cir: check for receive overflow Sasha Levin
2021-05-03 16:40 ` [PATCH AUTOSEL 4.19 05/35] media: drivers: media: pci: sta2x11: fix Kconfig dependency on GPIOLIB Sasha Levin
2021-05-03 16:40 ` [PATCH AUTOSEL 4.19 06/35] power: supply: bq27xxx: fix power_avg for newer ICs Sasha Levin
2021-05-03 16:40 ` [PATCH AUTOSEL 4.19 07/35] extcon: arizona: Fix some issues when HPDET IRQ fires after the jack has been unplugged Sasha Levin
2021-05-03 16:40 ` Sasha Levin [this message]
2021-05-03 16:40 ` [PATCH AUTOSEL 4.19 09/35] media: gspca/sq905.c: fix uninitialized variable Sasha Levin
2021-05-03 16:40 ` [PATCH AUTOSEL 4.19 10/35] media: pci: saa7164: Rudimentary spelling fixes in the file saa7164-types.h Sasha Levin
2021-05-03 16:40 ` [PATCH AUTOSEL 4.19 11/35] power: supply: Use IRQF_ONESHOT Sasha Levin
2021-05-03 16:40 ` [PATCH AUTOSEL 4.19 12/35] drm/bridge/analogix/anx78xx: Setup encoder before registering connector Sasha Levin
2021-05-03 16:40 ` [PATCH AUTOSEL 4.19 13/35] drm/bridge/analogix/anx78xx: Cleanup on error in anx78xx_bridge_attach() Sasha Levin
2021-05-03 16:40 ` [PATCH AUTOSEL 4.19 14/35] drm/amdgpu : Fix asic reset regression issue introduce by 8f211fe8ac7c4f Sasha Levin
2021-05-03 16:40 ` [PATCH AUTOSEL 4.19 15/35] scsi: qla2xxx: Always check the return value of qla24xx_get_isp_stats() Sasha Levin
2021-05-03 16:40 ` [PATCH AUTOSEL 4.19 16/35] scsi: qla2xxx: Fix use after free in bsg Sasha Levin
2021-05-03 16:40 ` [PATCH AUTOSEL 4.19 17/35] scsi: scsi_dh_alua: Remove check for ASC 24h in alua_rtpg() Sasha Levin
2021-05-03 16:40 ` [PATCH AUTOSEL 4.19 18/35] media: em28xx: fix memory leak Sasha Levin
2021-05-03 16:40 ` [PATCH AUTOSEL 4.19 19/35] media: vivid: update EDID Sasha Levin
2021-05-03 16:40 ` [PATCH AUTOSEL 4.19 20/35] clk: socfpga: arria10: Fix memory leak of socfpga_clk on error return Sasha Levin
2021-05-03 16:40 ` [PATCH AUTOSEL 4.19 21/35] power: supply: generic-adc-battery: fix possible use-after-free in gab_remove() Sasha Levin
2021-05-03 16:40 ` [PATCH AUTOSEL 4.19 22/35] power: supply: s3c_adc_battery: fix possible use-after-free in s3c_adc_bat_remove() Sasha Levin
2021-05-03 16:40 ` [PATCH AUTOSEL 4.19 23/35] media: tc358743: fix possible use-after-free in tc358743_remove() Sasha Levin
2021-05-03 16:40 ` [PATCH AUTOSEL 4.19 24/35] media: adv7604: fix possible use-after-free in adv76xx_remove() Sasha Levin
2021-05-03 16:40 ` [PATCH AUTOSEL 4.19 25/35] media: i2c: adv7511-v4l2: fix possible use-after-free in adv7511_remove() Sasha Levin
2021-05-03 16:41 ` [PATCH AUTOSEL 4.19 26/35] media: i2c: adv7842: fix possible use-after-free in adv7842_remove() Sasha Levin
2021-05-03 16:41 ` [PATCH AUTOSEL 4.19 27/35] media: dvb-usb: fix memory leak in dvb_usb_adapter_init Sasha Levin
2021-05-03 16:41 ` [PATCH AUTOSEL 4.19 28/35] media: gscpa/stv06xx: fix memory leak Sasha Levin
2021-05-03 16:41 ` [PATCH AUTOSEL 4.19 29/35] drm/msm/mdp5: Configure PP_SYNC_HEIGHT to double the vtotal Sasha Levin
2021-05-03 16:41 ` [PATCH AUTOSEL 4.19 30/35] amdgpu: avoid incorrect %hu format string Sasha Levin
2021-05-03 16:41 ` [PATCH AUTOSEL 4.19 31/35] drm/amdgpu: fix NULL pointer dereference Sasha Levin
2021-05-03 16:41 ` [PATCH AUTOSEL 4.19 32/35] scsi: lpfc: Fix crash when a REG_RPI mailbox fails triggering a LOGO response Sasha Levin
2021-05-03 16:41 ` [PATCH AUTOSEL 4.19 33/35] scsi: lpfc: Remove unsupported mbox PORT_CAPABILITIES logic Sasha Levin
2021-05-03 16:41 ` [PATCH AUTOSEL 4.19 34/35] scsi: libfc: Fix a format specifier Sasha Levin
2021-05-03 16:41 ` [PATCH AUTOSEL 4.19 35/35] s390/archrandom: add parameter check for s390_arch_random_generate Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210503164109.2853838-8-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=danielniv3@gmail.com \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab+huawei@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).