diff mbox series

[v2,082/101] fbdev/tgafb: Duplicate video-mode option string

Message ID 20230309160201.5163-83-tzimmermann@suse.de (mailing list archive)
State Awaiting Upstream
Headers show
Series fbdev: Fix memory leak in option parsing | expand

Commit Message

Thomas Zimmermann March 9, 2023, 4:01 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 kstrdup() and free it in the module's exit function.

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

v2:
	* replace static memory with kstrdup()/kfree() (Geert)

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

Patch

diff --git a/drivers/video/fbdev/tgafb.c b/drivers/video/fbdev/tgafb.c
index 14d37c49633c..cf00b8a91bfb 100644
--- a/drivers/video/fbdev/tgafb.c
+++ b/drivers/video/fbdev/tgafb.c
@@ -59,6 +59,7 @@  static int tgafb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info
 static int tgafb_register(struct device *dev);
 static void tgafb_unregister(struct device *dev);
 
+static const char *mode_option_buf;
 static const char *mode_option;
 static const char *mode_option_pci = "640x480@60";
 static const char *mode_option_tc = "1280x1024@72";
@@ -1568,6 +1569,7 @@  static void tgafb_exit(void)
 {
 	tc_unregister_driver(&tgafb_tc_driver);
 	pci_unregister_driver(&tgafb_pci_driver);
+	kfree(mode_option_buf);
 }
 
 #ifndef MODULE
@@ -1579,9 +1581,11 @@  static int tgafb_setup(char *arg)
 		while ((this_opt = strsep(&arg, ","))) {
 			if (!*this_opt)
 				continue;
-			if (!strncmp(this_opt, "mode:", 5))
-				mode_option = this_opt+5;
-			else
+			if (!strncmp(this_opt, "mode:", 5)) {
+				kfree(mode_option_buf);
+				mode_option_buf = kstrdup(this_opt, GFP_KERNEL); // ignore errors
+				mode_option = mode_option_buf;
+			} else
 				printk(KERN_ERR
 				       "tgafb: unknown parameter %s\n",
 				       this_opt);