Skip to contentSkip to conversation

media: ttpci: fix two memleaks in budget_av_attach

PATCH Superseded Zhipeng Lu 2 participants 3 messages Feb 6, 2024 – Feb 21, 2024 Media (V4L/DVB)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Zhipeng Lu

author
#0 lore raw

PATCH 1/1 media: ttpci: fix two memleaks in budget_av_attach

When saa7146_register_device and saa7146_vv_init fails, budget_av_attach should free the resources it allocates, like the error-handling of ttpci_budget_init does. Besides, there are two fixme comment refers to such deallocations.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 drivers/media/pci/ttpci/budget-av.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/media/pci/ttpci/budget-av.c +4 -2
index 230b104a7cdf..4f897f848581 100644
@@ -1463,7 +1463,8 @@ static int budget_av_attach(struct saa7146_dev *dev, struct saa7146_pci_extensio
 		budget_av->has_saa7113 = 1;
 		err = saa7146_vv_init(dev, &vv_data);
 		if (err != 0) {
-			/* fixme: proper cleanup here */
+			ttpci_budget_deinit(&budget_av->budget);
+			kfree(budget_av);
 			ERR("cannot init vv subsystem\n");
 			return err;
 		}
@@ -1472,7 +1473,8 @@ static int budget_av_attach(struct saa7146_dev *dev, struct saa7146_pci_extensio
 		vv_data.vid_ops.vidioc_s_input = vidioc_s_input;
 
 		if ((err = saa7146_register_device(&budget_av->vd, dev, "knc1", VFL_TYPE_VIDEO))) {
-			/* fixme: proper cleanup here */
+			ttpci_budget_deinit(&budget_av->budget);
+			kfree(budget_av);
 			ERR("cannot register capture v4l2 device\n");
 			saa7146_vv_release(dev);
 			return err;
Signature · 1 line
2.34.1
#1 lore raw
Quoted 26 lines · Zhipeng Lu

When saa7146_register_device and saa7146_vv_init fails, budget_av_attach should free the resources it allocates, like the error-handling of ttpci_budget_init does. Besides, there are two fixme comment refers to such deallocations.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 drivers/media/pci/ttpci/budget-av.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/media/pci/ttpci/budget-av.c +2 -1
index 230b104a7cdf..4f897f848581 100644
@@ -1463,7 +1463,8 @@ static int budget_av_attach(struct saa7146_dev *dev, struct saa7146_pci_extensio
 		budget_av->has_saa7113 = 1;
 		err = saa7146_vv_init(dev, &vv_data);
 		if (err != 0) {
-			/* fixme: proper cleanup here */
+			ttpci_budget_deinit(&budget_av->budget);
+			kfree(budget_av);
 			ERR("cannot init vv subsystem\n");
 			return err;
 		}

drivers/media/pci/ttpci/budget-av.c static int budget_av_attach(struct saa7146_dev *dev, struct saa7146_pci_extensio · line 1477

Quoted 6 lines
drivers/media/pci/ttpci/budget-av.c +2 -1
@@ -1472,7 +1473,8 @@ static int budget_av_attach(struct saa7146_dev *dev, struct saa7146_pci_extensio
 		vv_data.vid_ops.vidioc_s_input = vidioc_s_input;
 
 		if ((err = saa7146_register_device(&budget_av->vd, dev, "knc1", VFL_TYPE_VIDEO))) {
-			/* fixme: proper cleanup here */
+			ttpci_budget_deinit(&budget_av->budget);
+			kfree(budget_av);

I think this should go after the saa7146_vv_release() release below. Just in case saa7146_vv_release() relies on budget_av somewhere. And besides, it is good practice to release resources in the reverse order they were allocated.

Regards,

Hans

Quoted 3 lines
drivers/media/pci/ttpci/budget-av.c +0 -0
 			ERR("cannot register capture v4l2 device\n");
 			saa7146_vv_release(dev);
 			return err;
#2 lore raw
Quoted 29 lines · Zhipeng Lu
Quoted 28 lines

When saa7146_register_device and saa7146_vv_init fails, budget_av_attach should free the resources it allocates, like the error-handling of ttpci_budget_init does. Besides, there are two fixme comment refers to such deallocations.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 drivers/media/pci/ttpci/budget-av.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/media/pci/ttpci/budget-av.c +2 -1
index 230b104a7cdf..4f897f848581 100644
@@ -1463,7 +1463,8 @@ static int budget_av_attach(struct saa7146_dev *dev, struct saa7146_pci_extensio
 		budget_av->has_saa7113 = 1;
 		err = saa7146_vv_init(dev, &vv_data);
 		if (err != 0) {
-			/* fixme: proper cleanup here */
+			ttpci_budget_deinit(&budget_av->budget);
+			kfree(budget_av);
 			ERR("cannot init vv subsystem\n");
 			return err;
 		}
@@ -1472,7 +1473,8 @@ static int budget_av_attach(struct saa7146_dev *dev, struct saa7146_pci_extensio
 		vv_data.vid_ops.vidioc_s_input = vidioc_s_input;
 
Quoted 8 lines

drivers/media/pci/ttpci/budget-av.c static int budget_av_attach(struct saa7146_dev *dev, struct saa7146_pci_extensio · line 1477

Quoted 4 lines
drivers/media/pci/ttpci/budget-av.c +2 -1
 		if ((err = saa7146_register_device(&budget_av->vd, dev, "knc1", VFL_TYPE_VIDEO))) {
-			/* fixme: proper cleanup here */
+			ttpci_budget_deinit(&budget_av->budget);
+			kfree(budget_av);

I think this should go after the saa7146_vv_release() release below. Just in case saa7146_vv_release() relies on budget_av somewhere. And besides, it is good practice to release resources in the reverse order they were allocated.

Yes, I noticed the order of kfree(budget_av) and ttpci_budget_deinit, but did forgot the saa7146_vv_release. I'll send a v2 version of this patch soon.

Regards,
Zhipeng

Quoted 4 lines
Quoted 4 lines
drivers/media/pci/ttpci/budget-av.c +0 -0
 			ERR("cannot register capture v4l2 device\n");
 			saa7146_vv_release(dev);
 			return err;