Skip to contentSkip to conversation

fbdev: fix various memory leaks

PATCH Applied Abdun Nihaal 3 participants 21 messages May 14 – May 19

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

cover fbdev: fix various memory leaks

This patchset fixes some memory leak issues present in fbdev drivers.

Since commit 56c134f7f1b5 ("fbdev: Track deferred-I/O pages in pageref struct") fb_deferred_io_init() allocated memory for pagerefs and returned an error code, but the existing drivers which call fb_deferred_io_init() were not updated to do cleanup. The first three commits address this.
- fbdev: hecubafb: fix potential memory leak in hecubafb_probe()
- fbdev: broadsheetfb: fix potential memory leak in broadsheetfb_probe()
- fbdev: metronomefb: fix potential memory leak in metronomefb_probe()

Probe functions that call fb_add_videomode() or fb_videomode_to_modelist() sometimes did not call fb_destry_modelist() to free the allocated memory. The following patches address this issue.
- fbdev: radeon: fix potential memory leak in radeonfb_pci_register()
- fbdev: carminefb: fix potential memory leak in alloc_carmine_fb()
- fbdev: i740fb: fix potential memory leak in i740fb_probe()
- fbdev: nvidia: fix potential memory leak in nvidiafb_probe()
- fbdev: s3fb: fix potential memory leak in s3_pci_probe()
- fbdev: tdfxfb: fix potential memory leak in tdfxfb_probe()
- fbdev: tridentfb: fix potential memory leak in trident_pci_probe()
- fbdev: uvesafb: fix potential memory leak in uvesafb_probe()

Since commit 73ce73c30ba9 ("fbdev: Transfer video= option strings to caller; clarify ownership") the fb_get_options() function transfers ownership of the memory
allocated for options, and so the caller is expected to free it. The
following two patches address this issue.
- fbdev: efifb: fix memory leak in efifb_probe()
- fbdev: vesafb: fix memory leak in vesafb_probe()

The following commit fixes a simple memory leak.
- fbdev: sm501fb: fix potential memory leak in sm501fb_probe()

All the patches were only compile tested.
The issues were found using static analysis.

---
Abdun Nihaal (14):
fbdev: hecubafb: fix potential memory leak in hecubafb_probe()
fbdev: broadsheetfb: fix potential memory leak in broadsheetfb_probe()
fbdev: metronomefb: fix potential memory leak in metronomefb_probe()
fbdev: radeon: fix potential memory leak in radeonfb_pci_register()
fbdev: carminefb: fix potential memory leak in alloc_carmine_fb()
fbdev: i740fb: fix potential memory leak in i740fb_probe()
fbdev: nvidia: fix potential memory leak in nvidiafb_probe()
fbdev: s3fb: fix potential memory leak in s3_pci_probe()
fbdev: tdfxfb: fix potential memory leak in tdfxfb_probe()
fbdev: tridentfb: fix potential memory leak in trident_pci_probe()
fbdev: uvesafb: fix potential memory leak in uvesafb_probe()
fbdev: efifb: fix memory leak in efifb_probe()
fbdev: vesafb: fix memory leak in vesafb_probe()
fbdev: sm501fb: fix potential memory leak in sm501fb_probe()

 drivers/video/fbdev/aty/radeon_base.c | 1 +
 drivers/video/fbdev/broadsheetfb.c    | 8 ++++++--
 drivers/video/fbdev/carminefb.c       | 1 +
 drivers/video/fbdev/efifb.c           | 1 +
 drivers/video/fbdev/hecubafb.c        | 6 +++++-
 drivers/video/fbdev/i740fb.c          | 1 +
 drivers/video/fbdev/metronomefb.c     | 8 ++++++--
 drivers/video/fbdev/nvidia/nvidia.c   | 1 +
 drivers/video/fbdev/s3fb.c            | 1 +
 drivers/video/fbdev/sm501fb.c         | 3 +++
 drivers/video/fbdev/tdfxfb.c          | 1 +
 drivers/video/fbdev/tridentfb.c       | 1 +
 drivers/video/fbdev/uvesafb.c         | 4 ++--
 drivers/video/fbdev/vesafb.c          | 1 +
 14 files changed, 31 insertions(+), 7 deletions(-)

---
base-commit: ba2e787b4814ebf9ab5f6a84181678b67eb3677b
change-id: 20260513-fbdev-99a53dc0754f

Best regards,

Signature · 1 line
Abdun Nihaal <[email protected]>
#1 lore raw

PATCH 1/14 fbdev: hecubafb: fix potential memory leak in hecubafb_probe()

The memory allocated for pagerefs in fb_deferred_io_init() is not freed on the error path. Fix it by calling fb_deferred_io_cleanup().

Fixes 56c134f7f1b5 ("fbdev: Track deferred-I/O pages in pageref struct")
---
 drivers/video/fbdev/hecubafb.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/video/fbdev/hecubafb.c +5 -1
index 3547d58a29cf..dd2af980f3d8 100644
@@ -192,7 +192,9 @@ static int hecubafb_probe(struct platform_device *dev)
 	info->flags = FBINFO_VIRTFB;
 
 	info->fbdefio = &hecubafb_defio;
-	fb_deferred_io_init(info);
+	retval = fb_deferred_io_init(info);
+	if (retval)
+		goto err_fbdefio;
 
 	retval = register_framebuffer(info);
 	if (retval < 0)
@@ -209,6 +211,8 @@ static int hecubafb_probe(struct platform_device *dev)
 
 	return 0;
 err_fbreg:
+	fb_deferred_io_cleanup(info);
+err_fbdefio:
 	framebuffer_release(info);
 err_fballoc:
 	vfree(videomemory);
Signature · 1 line
2.43.0
Reviewed-by on v1 1/14
#2 lore raw

Re: [PATCH 01/14] fbdev: hecubafb: fix potential memory leak in hecubafb_probe()

Am 14.05.26 um 10:24 schrieb Abdun Nihaal:

Quoted 6 lines

The memory allocated for pagerefs in fb_deferred_io_init() is not freed on the error path. Fix it by calling fb_deferred_io_cleanup().

Fixes 56c134f7f1b5 ("fbdev: Track deferred-I/O pages in pageref struct")
Quoted 29 lines
---
  drivers/video/fbdev/hecubafb.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
drivers/video/fbdev/hecubafb.c +5 -1
index 3547d58a29cf..dd2af980f3d8 100644
@@ -192,7 +192,9 @@ static int hecubafb_probe(struct platform_device *dev)
  	info->flags = FBINFO_VIRTFB;
 
  	info->fbdefio = &hecubafb_defio;
-	fb_deferred_io_init(info);
+	retval = fb_deferred_io_init(info);
+	if (retval)
+		goto err_fbdefio;
 
  	retval = register_framebuffer(info);
  	if (retval < 0)
@@ -209,6 +211,8 @@ static int hecubafb_probe(struct platform_device *dev)
 
  	return 0;
  err_fbreg:
+	fb_deferred_io_cleanup(info);
+err_fbdefio:
  	framebuffer_release(info);
  err_fballoc:
  	vfree(videomemory);
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
#3 lore raw

PATCH 2/14 fbdev: broadsheetfb: fix potential memory leak in broadsheetfb_probe()

In reply to Abdun Nihaal

The memory allocated for pagerefs in fb_deferred_io_init() is not freed on the error path. Fix it by calling fb_deferred_io_cleanup().

Fixes 56c134f7f1b5 ("fbdev: Track deferred-I/O pages in pageref struct")
---
 drivers/video/fbdev/broadsheetfb.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/video/fbdev/broadsheetfb.c +6 -2
index c8ba098a8c42..582f1ee4c9b6 100644
@@ -1072,12 +1072,14 @@ static int broadsheetfb_probe(struct platform_device *dev)
 	info->flags = FBINFO_VIRTFB;
 
 	info->fbdefio = &broadsheetfb_defio;
-	fb_deferred_io_init(info);
+	retval = fb_deferred_io_init(info);
+	if (retval)
+		goto err_vfree;
 
 	retval = fb_alloc_cmap(&info->cmap, 16, 0);
 	if (retval < 0) {
 		dev_err(&dev->dev, "Failed to allocate colormap\n");
-		goto err_vfree;
+		goto err_fbdefio;
 	}
 
 	/* set cmap */
@@ -1121,6 +1123,8 @@ static int broadsheetfb_probe(struct platform_device *dev)
 	board->cleanup(par);
 err_cmap:
 	fb_dealloc_cmap(&info->cmap);
+err_fbdefio:
+	fb_deferred_io_cleanup(info);
 err_vfree:
 	vfree(videomemory);
 err_fb_rel:
Signature · 1 line
2.43.0
Reviewed-by on v1 2/14
#4 lore raw

Re: [PATCH 02/14] fbdev: broadsheetfb: fix potential memory leak in broadsheetfb_probe()

Am 14.05.26 um 10:24 schrieb Abdun Nihaal:

Quoted 6 lines

The memory allocated for pagerefs in fb_deferred_io_init() is not freed on the error path. Fix it by calling fb_deferred_io_cleanup().

Fixes 56c134f7f1b5 ("fbdev: Track deferred-I/O pages in pageref struct")
Quoted 35 lines
---
  drivers/video/fbdev/broadsheetfb.c | 8 ++++++--
  1 file changed, 6 insertions(+), 2 deletions(-)
drivers/video/fbdev/broadsheetfb.c +6 -2
index c8ba098a8c42..582f1ee4c9b6 100644
@@ -1072,12 +1072,14 @@ static int broadsheetfb_probe(struct platform_device *dev)
  	info->flags = FBINFO_VIRTFB;
 
  	info->fbdefio = &broadsheetfb_defio;
-	fb_deferred_io_init(info);
+	retval = fb_deferred_io_init(info);
+	if (retval)
+		goto err_vfree;
 
  	retval = fb_alloc_cmap(&info->cmap, 16, 0);
  	if (retval < 0) {
  		dev_err(&dev->dev, "Failed to allocate colormap\n");
-		goto err_vfree;
+		goto err_fbdefio;
  	}
 
  	/* set cmap */
@@ -1121,6 +1123,8 @@ static int broadsheetfb_probe(struct platform_device *dev)
  	board->cleanup(par);
  err_cmap:
  	fb_dealloc_cmap(&info->cmap);
+err_fbdefio:
+	fb_deferred_io_cleanup(info);
  err_vfree:
  	vfree(videomemory);
  err_fb_rel:
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
#5 lore raw

PATCH 3/14 fbdev: metronomefb: fix potential memory leak in metronomefb_probe()

In reply to Abdun Nihaal

The memory allocated for pagerefs in fb_deferred_io_init() is not freed on the error path. Fix it by calling fb_deferred_io_cleanup().

Fixes 56c134f7f1b5 ("fbdev: Track deferred-I/O pages in pageref struct")
---
 drivers/video/fbdev/metronomefb.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/video/fbdev/metronomefb.c +6 -2
index 6f0942c6e5f1..83c614963a0a 100644
@@ -645,12 +645,14 @@ static int metronomefb_probe(struct platform_device *dev)
 	info->flags = FBINFO_VIRTFB;
 
 	info->fbdefio = &metronomefb_defio;
-	fb_deferred_io_init(info);
+	retval = fb_deferred_io_init(info);
+	if (retval)
+		goto err_free_irq;
 
 	retval = fb_alloc_cmap(&info->cmap, 8, 0);
 	if (retval < 0) {
 		dev_err(&dev->dev, "Failed to allocate colormap\n");
-		goto err_free_irq;
+		goto err_fbdefio;
 	}
 
 	/* set cmap */
@@ -673,6 +675,8 @@ static int metronomefb_probe(struct platform_device *dev)
 
 err_cmap:
 	fb_dealloc_cmap(&info->cmap);
+err_fbdefio:
+	fb_deferred_io_cleanup(info);
 err_free_irq:
 	board->cleanup(par);
 err_csum_table:
Signature · 1 line
2.43.0
Reviewed-by on v1 3/14
#6 lore raw

Re: [PATCH 03/14] fbdev: metronomefb: fix potential memory leak in metronomefb_probe()

Am 14.05.26 um 10:24 schrieb Abdun Nihaal:

Quoted 6 lines

The memory allocated for pagerefs in fb_deferred_io_init() is not freed on the error path. Fix it by calling fb_deferred_io_cleanup().

Fixes 56c134f7f1b5 ("fbdev: Track deferred-I/O pages in pageref struct")
Quoted 35 lines
---
  drivers/video/fbdev/metronomefb.c | 8 ++++++--
  1 file changed, 6 insertions(+), 2 deletions(-)
drivers/video/fbdev/metronomefb.c +6 -2
index 6f0942c6e5f1..83c614963a0a 100644
@@ -645,12 +645,14 @@ static int metronomefb_probe(struct platform_device *dev)
  	info->flags = FBINFO_VIRTFB;
 
  	info->fbdefio = &metronomefb_defio;
-	fb_deferred_io_init(info);
+	retval = fb_deferred_io_init(info);
+	if (retval)
+		goto err_free_irq;
 
  	retval = fb_alloc_cmap(&info->cmap, 8, 0);
  	if (retval < 0) {
  		dev_err(&dev->dev, "Failed to allocate colormap\n");
-		goto err_free_irq;
+		goto err_fbdefio;
  	}
 
  	/* set cmap */
@@ -673,6 +675,8 @@ static int metronomefb_probe(struct platform_device *dev)
 
  err_cmap:
  	fb_dealloc_cmap(&info->cmap);
+err_fbdefio:
+	fb_deferred_io_cleanup(info);
  err_free_irq:
  	board->cleanup(par);
  err_csum_table:
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
#7 lore raw

PATCH 4/14 fbdev: radeon: fix potential memory leak in radeonfb_pci_register()

In reply to Abdun Nihaal

The function radeonfb_pci_register() allocates memory for modelist (by calling radeon_check_modes() which calls fb_add_videomode()). The memory is appended to info->modelist, but is not freed in subsequent error paths. Fix this by calling fb_destroy_modelist().

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 drivers/video/fbdev/aty/radeon_base.c | 1 +
 1 file changed, 1 insertion(+)
drivers/video/fbdev/aty/radeon_base.c +1 -0
index adb03489bedf..b6b058cee751 100644
@@ -2476,6 +2476,7 @@ static int radeonfb_pci_register(struct pci_dev *pdev,
 	return 0;
 err_unmap_fb:
 	iounmap(rinfo->fb_base);
+	fb_destroy_modelist(&info->modelist);
 err_unmap_rom:
 	kfree(rinfo->mon1_EDID);
 	kfree(rinfo->mon2_EDID);
Signature · 1 line
2.43.0
#8 lore raw

PATCH 5/14 fbdev: carminefb: fix potential memory leak in alloc_carmine_fb()

In reply to Abdun Nihaal

The memory allocated for modelist in fb_videomode_to_modelist() is not freed in the subsequent error path.
Fix that by calling fb_destroy_modelist()

Fixes 2ece5f43b041 ("fbdev: add the carmine FB driver")
---
 drivers/video/fbdev/carminefb.c | 1 +
 1 file changed, 1 insertion(+)
drivers/video/fbdev/carminefb.c +1 -0
index 5f13f1cc79d3..fca50b7961eb 100644
@@ -589,6 +589,7 @@ static int alloc_carmine_fb(void __iomem *regs, void __iomem *smem_base,
 	return 0;
 
 err_dealloc_cmap:
+	fb_destroy_modelist(&info->modelist);
 	fb_dealloc_cmap(&info->cmap);
 err_free_fb:
 	framebuffer_release(info);
Signature · 1 line
2.43.0
#9 lore raw

PATCH 6/14 fbdev: i740fb: fix potential memory leak in i740fb_probe()

In reply to Abdun Nihaal

In i740fb_probe(), the memory allocated in fb_videomode_to_modelist() for modelist is not freed in the error paths. Fix that by calling fb_destroy_modelist().

Fixes 5350c65f4f15 ("Resurrect Intel740 driver: i740fb")
---
 drivers/video/fbdev/i740fb.c | 1 +
 1 file changed, 1 insertion(+)
drivers/video/fbdev/i740fb.c +1 -0
index 9b74dae71472..c14a19382769 100644
@@ -1152,6 +1152,7 @@ static int i740fb_probe(struct pci_dev *dev, const struct pci_device_id *ent)
 	fb_dealloc_cmap(&info->cmap);
 err_alloc_cmap:
 err_find_mode:
+	fb_destroy_modelist(&info->modelist);
 	if (par->ddc_registered)
 		i2c_del_adapter(&par->ddc_adapter);
 	pci_iounmap(dev, par->regs);
Signature · 1 line
2.43.0
#10 lore raw

PATCH 7/14 fbdev: nvidia: fix potential memory leak in nvidiafb_probe()

In reply to Abdun Nihaal

In nvidiafb_probe(), the memory allocated for modelist in nvidia_set_fbinfo() is not freed in the subsequent error paths. Fix that by calling fb_destroy_modelist().

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 drivers/video/fbdev/nvidia/nvidia.c | 1 +
 1 file changed, 1 insertion(+)
drivers/video/fbdev/nvidia/nvidia.c +1 -0
index da2d486022e8..7d20c4087aeb 100644
@@ -1424,6 +1424,7 @@ static int nvidiafb_probe(struct pci_dev *pd, const struct pci_device_id *ent)
 
 err_out_iounmap_fb:
 	iounmap(info->screen_base);
+	fb_destroy_modelist(&info->modelist);
 err_out_free_base1:
 	fb_destroy_modedb(info->monspecs.modedb);
 	nvidia_delete_i2c_busses(par);
Signature · 1 line
2.43.0
#11 lore raw

PATCH 8/14 fbdev: s3fb: fix potential memory leak in s3_pci_probe()

In reply to Abdun Nihaal

In s3_pci_probe(), the memory allocated for modelist using fb_videomode_to_modelist() is not freed in subsequent error paths. Fix that by calling fb_destroy_modelist()

Fixes 86c0f043a737 ("s3fb: add DDC support")
---
 drivers/video/fbdev/s3fb.c | 1 +
 1 file changed, 1 insertion(+)
drivers/video/fbdev/s3fb.c +1 -0
index 831e9e6861b1..dc1f9b627185 100644
@@ -1446,6 +1446,7 @@ static int s3_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
 err_alloc_cmap:
 err_find_mode:
 #ifdef CONFIG_FB_S3_DDC
+	fb_destroy_modelist(&info->modelist);
 	if (par->ddc_registered)
 		i2c_del_adapter(&par->ddc_adapter);
 	if (par->mmio)
Signature · 1 line
2.43.0
#12 lore raw

PATCH 9/14 fbdev: tdfxfb: fix potential memory leak in tdfxfb_probe()

In reply to Abdun Nihaal

In tdfxfb_probe(), the memory allocated for modelist using fb_videomode_to_modelist() when CONFIG_FB_3DFX_I2C is defined, is not freed in the subsequent error paths.
Fix that by calling fb_destroy_modelist().

Fixes 215059d2421f ("tdfxfb: make use of DDC information about connected monitor")
---
 drivers/video/fbdev/tdfxfb.c | 1 +
 1 file changed, 1 insertion(+)
drivers/video/fbdev/tdfxfb.c +1 -0
index a6b63c09b48f..cc6a074f3165 100644
@@ -1552,6 +1552,7 @@ static int tdfxfb_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 
 out_err_iobase:
 #ifdef CONFIG_FB_3DFX_I2C
+	fb_destroy_modelist(&info->modelist);
 	tdfxfb_delete_i2c_busses(default_par);
 #endif
 	arch_phys_wc_del(default_par->wc_cookie);
Signature · 1 line
2.43.0
#13 lore raw

PATCH 10/14 fbdev: tridentfb: fix potential memory leak in trident_pci_probe()

In reply to Abdun Nihaal

In trident_pci_probe(), the memory allocated for modelist using fb_videomode_to_modelist() is not freed in subsequent error paths. Fix that by calling fb_destroy_modelist().

Fixes 6a5e3bd0c8bc ("tridentfb: Add DDC support")
---
 drivers/video/fbdev/tridentfb.c | 1 +
 1 file changed, 1 insertion(+)
drivers/video/fbdev/tridentfb.c +1 -0
index a8fdbae83a80..9f055ba776c8 100644
@@ -1706,6 +1706,7 @@ static int trident_pci_probe(struct pci_dev *dev,
 	return 0;
 
 out_unmap2:
+	fb_destroy_modelist(&info->modelist);
 	if (default_par->ddc_registered)
 		i2c_del_adapter(&default_par->ddc_adapter);
 	kfree(info->pixmap.addr);
Signature · 1 line
2.43.0
#14 lore raw

PATCH 11/14 fbdev: uvesafb: fix potential memory leak in uvesafb_probe()

In reply to Abdun Nihaal

Due to an incorrect goto label, memory allocated for modedb and modelist in uvesafb_vbe_init() is not freed in some error paths. Fix this by updating the goto label.

Fixes 8bdb3a2d7df4 ("uvesafb: the driver core")
---
 drivers/video/fbdev/uvesafb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/video/fbdev/uvesafb.c +2 -2
index 88667fccc27b..9d82326c744f 100644
@@ -1694,14 +1694,14 @@ static int uvesafb_probe(struct platform_device *dev)
 	i = uvesafb_vbe_init_mode(info);
 	if (i < 0) {
 		err = -EINVAL;
-		goto out;
+		goto out_mode;
 	} else {
 		mode = &par->vbe_modes[i];
 	}
 
 	if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
 		err = -ENXIO;
-		goto out;
+		goto out_mode;
 	}
 
 	uvesafb_init_info(info, mode);
Signature · 1 line
2.43.0
#15 lore raw

PATCH 12/14 fbdev: efifb: fix memory leak in efifb_probe()

In reply to Abdun Nihaal

Since commit 73ce73c30ba9 ("fbdev: Transfer video= option strings to caller; clarify ownership") the string returned from fb_get_options() is expected to be freed by the caller, but the string is not freed in efifb_probe(). Fix that by freeing the option string after setup.

Fixes 73ce73c30ba9 ("fbdev: Transfer video= option strings to caller; clarify ownership")
---
 drivers/video/fbdev/efifb.c | 1 +
 1 file changed, 1 insertion(+)
drivers/video/fbdev/efifb.c +1 -0
index 47ebc0107209..ad8dec7807c3 100644
@@ -377,6 +377,7 @@ static int efifb_probe(struct platform_device *dev)
 	if (fb_get_options("efifb", &option))
 		return -ENODEV;
 	efifb_setup(si, option);
+	kfree(option);
 
 	/* We don't get linelength from UGA Draw Protocol, only from
 	 * EFI Graphics Protocol.  So if it's not in DMI, and it's not
Signature · 1 line
2.43.0
Reviewed-by on v1 12/14
#16 lore raw

Re: [PATCH 12/14] fbdev: efifb: fix memory leak in efifb_probe()

Hi

Am 14.05.26 um 10:24 schrieb Abdun Nihaal:

Quoted 6 lines

Since commit 73ce73c30ba9 ("fbdev: Transfer video= option strings to caller; clarify ownership") the string returned from fb_get_options() is expected to be freed by the caller, but the string is not freed in efifb_probe(). Fix that by freeing the option string after setup.

Fixes 73ce73c30ba9 ("fbdev: Transfer video= option strings to caller; clarify ownership")

Right, the commit message even mentions the (pre-existing) leak. There might be other drivers with a similar issue.

Quoted 2 lines
Quoted 17 lines
---
  drivers/video/fbdev/efifb.c | 1 +
  1 file changed, 1 insertion(+)
drivers/video/fbdev/efifb.c +1 -0
index 47ebc0107209..ad8dec7807c3 100644
@@ -377,6 +377,7 @@ static int efifb_probe(struct platform_device *dev)
  	if (fb_get_options("efifb", &option))
  		return -ENODEV;
  	efifb_setup(si, option);
+	kfree(option);
 
  	/* We don't get linelength from UGA Draw Protocol, only from
  	 * EFI Graphics Protocol.  So if it's not in DMI, and it's not
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
#17 lore raw

PATCH 13/14 fbdev: vesafb: fix memory leak in vesafb_probe()

In reply to Abdun Nihaal

Since commit 73ce73c30ba9 ("fbdev: Transfer video= option strings to caller; clarify ownership") the string returned from fb_get_options() is expected to be freed by the caller. But the string is not freed in vesafb_probe(). Fix that by freeing the option string after setup.

Fixes 73ce73c30ba9 ("fbdev: Transfer video= option strings to caller; clarify ownership")
---
 drivers/video/fbdev/vesafb.c | 1 +
 1 file changed, 1 insertion(+)
drivers/video/fbdev/vesafb.c +1 -0
index f84f4db244bf..f1902056bd73 100644
@@ -269,6 +269,7 @@ static int vesafb_probe(struct platform_device *dev)
 	/* ignore error return of fb_get_options */
 	fb_get_options("vesafb", &option);
 	vesafb_setup(option);
+	kfree(option);
 
 	if (si->orig_video_isVGA != VIDEO_TYPE_VLFB)
 		return -ENODEV;
Signature · 1 line
2.43.0
Reviewed-by on v1 13/14
#18 lore raw

Re: [PATCH 13/14] fbdev: vesafb: fix memory leak in vesafb_probe()

Am 14.05.26 um 10:24 schrieb Abdun Nihaal:

Quoted 8 lines

Since commit 73ce73c30ba9 ("fbdev: Transfer video= option strings to caller; clarify ownership") the string returned from fb_get_options() is expected to be freed by the caller. But the string is not freed in vesafb_probe(). Fix that by freeing the option string after setup.

Fixes 73ce73c30ba9 ("fbdev: Transfer video= option strings to caller; clarify ownership")
Quoted 17 lines
---
  drivers/video/fbdev/vesafb.c | 1 +
  1 file changed, 1 insertion(+)
drivers/video/fbdev/vesafb.c +1 -0
index f84f4db244bf..f1902056bd73 100644
@@ -269,6 +269,7 @@ static int vesafb_probe(struct platform_device *dev)
  	/* ignore error return of fb_get_options */
  	fb_get_options("vesafb", &option);
  	vesafb_setup(option);
+	kfree(option);
 
  	if (si->orig_video_isVGA != VIDEO_TYPE_VLFB)
  		return -ENODEV;
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
#19 lore raw

PATCH 14/14 fbdev: sm501fb: fix potential memory leak in sm501fb_probe()

In reply to Abdun Nihaal

The memory allocated for info->edid_data in sm501fb_probe() when CONFIG_OF is defined is not freed in the subsequent error paths. Fix that by freeing it in the error path if CONFIG_OF is defined.

Fixes 4295f9bf74a8 ("video, sm501: add OF binding to support SM501")
---
 drivers/video/fbdev/sm501fb.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/video/fbdev/sm501fb.c +3 -0
index fee4b9f84592..1ee7842517b8 100644
@@ -2048,6 +2048,9 @@ static int sm501fb_probe(struct platform_device *pdev)
 	framebuffer_release(info->fb[HEAD_CRT]);
 
 err_alloc:
+#if defined(CONFIG_OF)
+	kfree(info->edid_data);
+#endif
 	kfree(info);
 
 	return ret;
Signature · 1 line
2.43.0
maintainer Applied
#20 lore raw
In reply to Abdun Nihaal
Quoted 53 lines · Abdun Nihaal

This patchset fixes some memory leak issues present in fbdev drivers.

Since commit 56c134f7f1b5 ("fbdev: Track deferred-I/O pages in pageref struct") fb_deferred_io_init() allocated memory for pagerefs and returned an error code, but the existing drivers which call fb_deferred_io_init() were not updated to do cleanup. The first three commits address this.
- fbdev: hecubafb: fix potential memory leak in hecubafb_probe()
- fbdev: broadsheetfb: fix potential memory leak in broadsheetfb_probe()
- fbdev: metronomefb: fix potential memory leak in metronomefb_probe()

Probe functions that call fb_add_videomode() or fb_videomode_to_modelist() sometimes did not call fb_destry_modelist() to free the allocated memory. The following patches address this issue.
- fbdev: radeon: fix potential memory leak in radeonfb_pci_register()
- fbdev: carminefb: fix potential memory leak in alloc_carmine_fb()
- fbdev: i740fb: fix potential memory leak in i740fb_probe()
- fbdev: nvidia: fix potential memory leak in nvidiafb_probe()
- fbdev: s3fb: fix potential memory leak in s3_pci_probe()
- fbdev: tdfxfb: fix potential memory leak in tdfxfb_probe()
- fbdev: tridentfb: fix potential memory leak in trident_pci_probe()
- fbdev: uvesafb: fix potential memory leak in uvesafb_probe()

Since commit 73ce73c30ba9 ("fbdev: Transfer video= option strings to caller; clarify ownership") the fb_get_options() function transfers ownership of the memory
allocated for options, and so the caller is expected to free it. The
following two patches address this issue.
- fbdev: efifb: fix memory leak in efifb_probe()
- fbdev: vesafb: fix memory leak in vesafb_probe()

The following commit fixes a simple memory leak.
- fbdev: sm501fb: fix potential memory leak in sm501fb_probe()

All the patches were only compile tested.
The issues were found using static analysis.

---
Abdun Nihaal (14):
fbdev: hecubafb: fix potential memory leak in hecubafb_probe()
fbdev: broadsheetfb: fix potential memory leak in broadsheetfb_probe()
fbdev: metronomefb: fix potential memory leak in metronomefb_probe()
fbdev: radeon: fix potential memory leak in radeonfb_pci_register()
fbdev: carminefb: fix potential memory leak in alloc_carmine_fb()
fbdev: i740fb: fix potential memory leak in i740fb_probe()
fbdev: nvidia: fix potential memory leak in nvidiafb_probe()
fbdev: s3fb: fix potential memory leak in s3_pci_probe()
fbdev: tdfxfb: fix potential memory leak in tdfxfb_probe()
fbdev: tridentfb: fix potential memory leak in trident_pci_probe()
fbdev: uvesafb: fix potential memory leak in uvesafb_probe()
fbdev: efifb: fix memory leak in efifb_probe()
fbdev: vesafb: fix memory leak in vesafb_probe()
fbdev: sm501fb: fix potential memory leak in sm501fb_probe()

Quoted 15 lines
  drivers/video/fbdev/aty/radeon_base.c | 1 +
  drivers/video/fbdev/broadsheetfb.c    | 8 ++++++--
  drivers/video/fbdev/carminefb.c       | 1 +
  drivers/video/fbdev/efifb.c           | 1 +
  drivers/video/fbdev/hecubafb.c        | 6 +++++-
  drivers/video/fbdev/i740fb.c          | 1 +
  drivers/video/fbdev/metronomefb.c     | 8 ++++++--
  drivers/video/fbdev/nvidia/nvidia.c   | 1 +
  drivers/video/fbdev/s3fb.c            | 1 +
  drivers/video/fbdev/sm501fb.c         | 3 +++
  drivers/video/fbdev/tdfxfb.c          | 1 +
  drivers/video/fbdev/tridentfb.c       | 1 +
  drivers/video/fbdev/uvesafb.c         | 4 ++--
  drivers/video/fbdev/vesafb.c          | 1 +
  14 files changed, 31 insertions(+), 7 deletions(-)

I applied the whole series to the fbdev git tree.
Thanks a lot !

Helge