Thread (112 messages) 112 messages, 4 authors, 2023-03-21
STALE1167d
Revisions (2)
  1. v1 [diff vs current]
  2. v2 current

[PATCH v2 022/101] fbdev/fsl-diu-fb: Duplicate video-mode option string

From: Thomas Zimmermann <tzimmermann@suse.de>
Date: 2023-03-09 16:05:26
Also in: dri-devel, lkml
Subsystem: framebuffer layer, freescale diu framebuffer driver, the rest · Maintainers: Helge Deller, Timur Tabi, Linus Torvalds

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, Timur)

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/fsl-diu-fb.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/video/fbdev/fsl-diu-fb.c b/drivers/video/fbdev/fsl-diu-fb.c
index e332017c6af6..033bbf0c40b7 100644
--- a/drivers/video/fbdev/fsl-diu-fb.c
+++ b/drivers/video/fbdev/fsl-diu-fb.c
@@ -307,6 +307,7 @@ static struct fb_videomode fsl_diu_mode_db[] = {
 	},
 };
 
+static char *fb_mode_buf;
 static char *fb_mode;
 static unsigned long default_bpp = 32;
 static enum fsl_diu_monitor_port monitor_port;
@@ -1858,8 +1859,11 @@ static int __init fsl_diu_setup(char *options)
 		} else if (!strncmp(opt, "bpp=", 4)) {
 			if (!kstrtoul(opt + 4, 10, &val))
 				default_bpp = val;
-		} else
-			fb_mode = opt;
+		} else {
+			kfree(fb_mode_buf);
+			fb_mode_buf = kstrdup(opt, GFP_KERNEL); // ignore errors
+			fb_mode = fb_mode_buf;
+		}
 	}
 
 	return 0;
@@ -1978,6 +1982,7 @@ static void __exit fsl_diu_exit(void)
 #if defined(CONFIG_NOT_COHERENT_CACHE)
 	vfree(coherence_data);
 #endif
+	kfree(fb_mode_buf);
 }
 
 module_init(fsl_diu_init);
-- 
2.39.2
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help