[v2,024/101] fbdev/gbefb: Duplicate video-mode option string

Message ID 20230309160201.5163-25-tzimmermann@suse.de
State New
Headers
Series fbdev: Fix memory leak in option parsing |

Commit Message

Thomas Zimmermann March 9, 2023, 4 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 devm_kstrdup(), as the driver parses the option string
once per probed device. Linux will automatically free the memory upon
releasing the device.

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/video/fbdev/gbefb.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
  

Patch

diff --git a/drivers/video/fbdev/gbefb.c b/drivers/video/fbdev/gbefb.c
index 000b4aa44241..6afccd4ef0a8 100644
--- a/drivers/video/fbdev/gbefb.c
+++ b/drivers/video/fbdev/gbefb.c
@@ -1083,7 +1083,7 @@  ATTRIBUTE_GROUPS(gbefb);
  * Initialization
  */
 
-static int gbefb_setup(char *options)
+static int gbefb_setup(char *options, struct device *dev)
 {
 	char *this_opt;
 
@@ -1108,8 +1108,9 @@  static int gbefb_setup(char *options)
 				gbe_mem_size = CONFIG_FB_GBE_MEM * 1024 * 1024;
 			if (gbe_mem_size < TILE_SIZE)
 				gbe_mem_size = TILE_SIZE;
-		} else
-			mode_option = this_opt;
+		} else {
+			mode_option = devm_kstrdup(dev, this_opt, GFP_KERNEL); // ignore errors
+		}
 	}
 	return 0;
 }
@@ -1132,7 +1133,7 @@  static int gbefb_probe(struct platform_device *p_dev)
 		ret = -ENODEV;
 		goto out_release_framebuffer;
 	}
-	gbefb_setup(options);
+	gbefb_setup(options, &p_dev->dev);
 #endif
 
 	if (!request_mem_region(GBE_BASE, sizeof(struct sgi_gbe), "GBE")) {