diff mbox series

[v2,006/101] fbdev/amifb: Duplicate video-mode option string

Message ID 20230309160201.5163-7-tzimmermann@suse.de
State New
Headers show
Series fbdev: Fix memory leak in option parsing | expand

Commit Message

Thomas Zimmermann March 9, 2023, 4 p.m. UTC
Assume that the driver does not own the option string or its substrings
and hence duplicate the option string for the video mode. Allocate the
copy's memory with devm_kstrdup(), as the driver parses the option string
once per probed device. Linux will automatically free the memory upon
releasing the device.

Done in preparation of switching the driver to struct option_iter and
constifying the option string.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/amifb.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/drivers/video/fbdev/amifb.c b/drivers/video/fbdev/amifb.c
index d88265dbebf4..9517aa5bd2c0 100644
--- a/drivers/video/fbdev/amifb.c
+++ b/drivers/video/fbdev/amifb.c
@@ -2345,7 +2345,7 @@  static void __init amifb_setup_mcap(char *spec)
 	amifb_vfmax = vmax;
 }
 
-static int __init amifb_setup(char *options)
+static int __init amifb_setup(char *options, struct platform_device *pdev)
 {
 	char *this_opt;
 
@@ -2363,8 +2363,10 @@  static int __init amifb_setup(char *options)
 			amifb_setup_mcap(this_opt + 11);
 		else if (!strncmp(this_opt, "fstart:", 7))
 			min_fstrt = simple_strtoul(this_opt + 7, NULL, 0);
-		else
-			mode_option = this_opt;
+		else {
+			// ignore errors
+			mode_option = devm_kstrdup(&pdev->dev, this_opt, GFP_KERNEL);
+		}
 	}
 
 	if (min_fstrt < 48)
@@ -3542,7 +3544,7 @@  static int __init amifb_probe(struct platform_device *pdev)
 		amifb_video_off();
 		return -ENODEV;
 	}
-	amifb_setup(option);
+	amifb_setup(option, pdev);
 #endif
 	custom.dmacon = DMAF_ALL | DMAF_MASTER;