[PATCH v2 099/101] staging/sm750fb: Duplicate video-mode option string

From
Thomas Zimmermann <tzimmermann@suse.de>
Date
2023-03-09 16:11:30
Also in
dri-devel, lkml
Reply to
Thomas Zimmermann, 2023-03-09
Assume that the driver does not own the option string or its substrings
and hence duplicate the option stringis for the video mode. Allocate each
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.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/staging/sm750fb/sm750.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/sm750fb/sm750.c b/drivers/staging/sm750fb/sm750.c
index fa8ae20bb688..f0dbf7535ca8 100644
--- a/drivers/staging/sm750fb/sm750.c
+++ b/drivers/staging/sm750fb/sm750.c
@@ -911,11 +911,11 @@ static void sm750fb_setup(struct sm750_dev *sm750_dev, char *src)
 			g_hwcursor = 0;
 		} else {
 			if (!g_fbmode[0]) {
-				g_fbmode[0] = opt;
+				g_fbmode[0] = kstrdup(opt, GFP_KERNEL); // ignore errors
 				dev_info(&sm750_dev->pdev->dev,
 					 "find fbmode0 : %s\n", g_fbmode[0]);
 			} else if (!g_fbmode[1]) {
-				g_fbmode[1] = opt;
+				g_fbmode[1] = kstrdup(opt, GFP_KERNEL); // ignore errors
 				dev_info(&sm750_dev->pdev->dev,
 					 "find fbmode1 : %s\n", g_fbmode[1]);
 			} else {
@@ -1182,7 +1182,14 @@ module_init(lynxfb_init);
 
 static void __exit lynxfb_exit(void)
 {
+	size_t i = ARRAY_SIZE(g_fbmode);
+
 	pci_unregister_driver(&lynxfb_driver);
+
+	while (i) {
+		--i;
+		kfree(g_fbmode[i]);
+	}
 	kfree(g_settings);
 }
 module_exit(lynxfb_exit);
-- 
2.39.2
Thread (112 messages) 112 messages, 4 authors, last reply 2023-03-21
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help