[PATCH v2 030/101] fbdev/gxt4500: Duplicate video-mode option string

From: Thomas Zimmermann
Date: Thu Mar 09 2023 - 11:05:29 EST


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 constifying the option string.

v2:
* replace static memory with kstrdup()/kfree() (Geert)

Signed-off-by: Thomas Zimmermann <tzimmermann@xxxxxxx>
---
drivers/video/fbdev/gxt4500.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/gxt4500.c b/drivers/video/fbdev/gxt4500.c
index 5f42d3d9d6ce..65cb44c281c1 100644
--- a/drivers/video/fbdev/gxt4500.c
+++ b/drivers/video/fbdev/gxt4500.c
@@ -158,6 +158,7 @@ struct gxt4500_par {
};

/* mode requested by user */
+static char *mode_option_buf;
static char *mode_option;

/* default mode: 1280x1024 @ 60 Hz, 8 bpp */
@@ -779,12 +780,21 @@ static struct pci_driver gxt4500_driver = {

static int gxt4500_init(void)
{
+#ifndef MODULE
+ char *options;
+#endif
+
if (fb_modesetting_disabled("gxt4500"))
return -ENODEV;

#ifndef MODULE
- if (fb_get_options("gxt4500", &mode_option))
+ if (fb_get_options("gxt4500", &options))
return -ENODEV;
+
+ if (options && *options) {
+ mode_option_buf = kstrdup(options, GFP_KERNEL); // ignore errors
+ mode_option = mode_option_buf;
+ }
#endif

return pci_register_driver(&gxt4500_driver);
@@ -794,6 +804,7 @@ module_init(gxt4500_init);
static void __exit gxt4500_exit(void)
{
pci_unregister_driver(&gxt4500_driver);
+ kfree(mode_option_buf);
}
module_exit(gxt4500_exit);

--
2.39.2