diff mbox series

[v2,075/101] fbdev/sm712fb: Duplicate video-mode option string

Message ID 20230309160201.5163-76-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/sm712fb.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/video/fbdev/sm712fb.c b/drivers/video/fbdev/sm712fb.c
index b528776c7612..a83f48fce5b1 100644
--- a/drivers/video/fbdev/sm712fb.c
+++ b/drivers/video/fbdev/sm712fb.c
@@ -831,6 +831,7 @@  static const struct modeinit vgamode[] = {
 
 static struct screen_info smtc_scr_info;
 
+static char *mode_option_buf;
 static char *mode_option;
 
 /* process command line options, get vga parameter */
@@ -1761,8 +1762,12 @@  static int __init sm712fb_init(void)
 
 	if (fb_get_options("sm712fb", &option))
 		return -ENODEV;
-	if (option && *option)
-		mode_option = option;
+
+	if (option && *option) {
+		mode_option_buf = kstrdup(option, GFP_KERNEL); // ignore errors
+		mode_option = mode_option_buf;
+	}
+
 	sm7xx_vga_setup(mode_option);
 
 	return pci_register_driver(&smtcfb_driver);
@@ -1773,6 +1778,7 @@  module_init(sm712fb_init);
 static void __exit sm712fb_exit(void)
 {
 	pci_unregister_driver(&smtcfb_driver);
+	kfree(mode_option_buf);
 }
 
 module_exit(sm712fb_exit);