[PATCH v2 046/101] fbdev/mx3fb: Duplicate video-mode option string

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxx>
---
 drivers/video/fbdev/mx3fb.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/mx3fb.c b/drivers/video/fbdev/mx3fb.c
index 76771e126d0a..e33ad125318f 100644
--- a/drivers/video/fbdev/mx3fb.c
+++ b/drivers/video/fbdev/mx3fb.c
@@ -332,6 +332,7 @@ static void mx3fb_exit_backlight(struct mx3fb_data *fbd)
 static void mx3fb_dma_done(void *);
 
 /* Used fb-mode and bpp. Can be set on kernel command line, therefore file-static. */
+static const char *fb_mode_buf;
 static const char *fb_mode;
 static unsigned long default_bpp = 16;
 
@@ -1666,8 +1667,11 @@ static int __init mx3fb_setup(void)
 			continue;
 		if (!strncmp(opt, "bpp=", 4))
 			default_bpp = simple_strtoul(opt + 4, NULL, 0);
-		else
-			fb_mode = opt;
+		else {
+			kfree(fb_mode_buf);
+			fb_mode_buf = kstrdup(opt, GFP_KERNEL); // ignore errors
+			fb_mode = fb_mode_buf;
+		}
 	}
 #endif
 
@@ -1688,6 +1692,7 @@ static int __init mx3fb_init(void)
 static void __exit mx3fb_exit(void)
 {
 	platform_driver_unregister(&mx3fb_driver);
+	kfree(fb_mode_buf);
 }
 
 module_init(mx3fb_init);
-- 
2.39.2




[Index of Archives]     [Video for Linux]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Tourism]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux