[PATCH v2 037/101] fbdev/intelfb: Duplicate video-mode option string

From: Thomas Zimmermann
Date: Thu Mar 09 2023 - 11:05:59 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 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/intelfb/intelfbdrv.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/intelfb/intelfbdrv.c b/drivers/video/fbdev/intelfb/intelfbdrv.c
index 0a9e5067b201..8368c3601cdb 100644
--- a/drivers/video/fbdev/intelfb/intelfbdrv.c
+++ b/drivers/video/fbdev/intelfb/intelfbdrv.c
@@ -238,6 +238,7 @@ static bool probeonly = 0;
static bool idonly = 0;
static int bailearly = 0;
static int voffset = 48;
+static char *mode_buf;
static char *mode = NULL;

module_param(accel, bool, S_IRUGO);
@@ -365,8 +366,11 @@ static int __init intelfb_setup(char *options)
noinit = !noinit;
else if (OPT_EQUAL(this_opt, "mode="))
mode = get_opt_string(this_opt, "mode=");
- else
- mode = this_opt;
+ else {
+ kfree(mode_buf);
+ mode_buf = kstrdup(this_opt, GFP_KERNEL); // ignore errors
+ mode = mode_buf;
+ }
}

return 0;
@@ -405,6 +409,7 @@ static void __exit intelfb_exit(void)
{
DBG_MSG("intelfb_exit\n");
pci_unregister_driver(&intelfb_driver);
+ kfree(mode_buf);
}

module_init(intelfb_init);
--
2.39.2