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

[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
Subsystem: staging - silicon motion sm750 frame buffer driver, staging subsystem, the rest · Maintainers: Sudip Mukherjee, Teddy Wang, Greg Kroah-Hartman, Linus Torvalds

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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help