devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] of: do not leak console options
@ 2017-09-26  6:25 Sergey Senozhatsky
  2017-10-03  7:20 ` Petr Mladek
  2017-10-12 17:24 ` Rob Herring
  0 siblings, 2 replies; 14+ messages in thread
From: Sergey Senozhatsky @ 2017-09-26  6:25 UTC (permalink / raw)
  To: Rob Herring
  Cc: Petr Mladek, Steven Rostedt, devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, Sergey Senozhatsky

Do not strdup() console options. It seems that the only reason for
it to be strdup()-ed was a compilation warning: printk, UART and
console drivers, for some reason, expect char pointer instead of
const char pointer. So we can just pass `of_stdout_options', but
need to cast it to char pointer. A better fix would be to change
printk, console drivers and UART to accept const char `options';
but that will take time - there are lots of drivers to update.

The patch also fixes a possible memory leak: add_preferred_console()
can fail, but we don't kfree() options.

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
 drivers/of/base.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 260d33c0f26c..63897531cd75 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1781,8 +1781,12 @@ bool of_console_check(struct device_node *dn, char *name, int index)
 {
 	if (!dn || dn != of_stdout || console_set_on_cmdline)
 		return false;
-	return !add_preferred_console(name, index,
-				      kstrdup(of_stdout_options, GFP_KERNEL));
+
+	/*
+	 * XXX: cast `options' to char pointer to suppress complication
+	 * warnings: printk, UART and console drivers expect char pointer.
+	 */
+	return !add_preferred_console(name, index, (char *)of_stdout_options);
 }
 EXPORT_SYMBOL_GPL(of_console_check);
 
-- 
2.14.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 14+ messages in thread
* [PATCH] of: do not leak console options
@ 2017-08-25 17:36 Sergey Senozhatsky
       [not found] ` <20170825173647.1004-1-sergey.senozhatsky-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 14+ messages in thread
From: Sergey Senozhatsky @ 2017-08-25 17:36 UTC (permalink / raw)
  To: Rob Herring
  Cc: Petr Mladek, Steven Rostedt, devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, Sergey Senozhatsky

If add_preferred_console() returns error then we must free a
copy of `of_stdout_options' that we create right before the
console registration.

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
 drivers/of/base.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 260d33c0f26c..9fcf7011d206 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1779,10 +1779,17 @@ EXPORT_SYMBOL_GPL(of_alias_get_highest_id);
  */
 bool of_console_check(struct device_node *dn, char *name, int index)
 {
+	bool ret;
+	char *options;
+
 	if (!dn || dn != of_stdout || console_set_on_cmdline)
 		return false;
-	return !add_preferred_console(name, index,
-				      kstrdup(of_stdout_options, GFP_KERNEL));
+
+	options = kstrdup(of_stdout_options, GFP_KERNEL);
+	ret = add_preferred_console(name, index, options);
+	if (ret)
+		kfree(options);
+	return !ret;
 }
 EXPORT_SYMBOL_GPL(of_console_check);
 
-- 
2.14.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2017-10-13 20:44 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-26  6:25 [PATCH] of: do not leak console options Sergey Senozhatsky
2017-10-03  7:20 ` Petr Mladek
     [not found]   ` <20171003072007.GB9706-KsEp0d+Q8qECVLCxKZUutA@public.gmane.org>
2017-10-13 19:48     ` Geert Uytterhoeven
     [not found]       ` <CAMuHMdXL1v20PvP2=jv_YdNgk0afkrgfZf1b21LrTWXGoPDMhg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-10-13 20:44         ` Rob Herring
2017-10-12 17:24 ` Rob Herring
  -- strict thread matches above, loose matches on Subject: below --
2017-08-25 17:36 Sergey Senozhatsky
     [not found] ` <20170825173647.1004-1-sergey.senozhatsky-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-08-25 22:37   ` Rob Herring
2017-08-27  7:19     ` Sergey Senozhatsky
2017-08-27  8:01       ` Sergey Senozhatsky
2017-09-06 12:40       ` Petr Mladek
2017-09-06 13:29         ` Sergey Senozhatsky
2017-09-06 15:27           ` Rob Herring
2017-09-07  9:57             ` Sergey Senozhatsky
     [not found]             ` <CAL_JsqKRPGFUzLVbyU_=GZzsy87Mc6x43DtmUQ758-nrZZF_jA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-09-26  6:31               ` Sergey Senozhatsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).