From: Alessandro Carminati <alessandro.carminati@gmail.com>
To: unlisted-recipients:; (no To-header on input)
Cc: Alessandro Carminati <alessandro.carminati@gmail.com>,
Philip Daly <pdaly@redhat.com>,
Michael Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>,
linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] Sanitize possible_parent_show to Handle Return Value of of_clk_get_parent_name
Date: Tue, 22 Aug 2023 13:48:49 +0000 [thread overview]
Message-ID: <20230822134849.3352329-1-alessandro.carminati@gmail.com> (raw)
In the possible_parent_show function, ensure proper handling of the return
value from of_clk_get_parent_name to prevent potential issues arising from
a NULL return.
The current implementation invokes seq_puts directly on the result of
of_clk_get_parent_name without verifying the return value, which can lead
to kernel panic if the function returns NULL.
This patch addresses the concern by introducing a check on the return
value of of_clk_get_parent_name. If the return value is not NULL, the
function proceeds to call seq_puts, providing the returned value as
argument.
However, if of_clk_get_parent_name returns NULL, the function provides a
static string as argument, avoiding the panic.
Reported-by: Philip Daly <pdaly@redhat.com>
Signed-off-by: Alessandro Carminati (Red Hat) <alessandro.carminati@gmail.com>
---
drivers/clk/clk.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index c249f9791ae8..ab999644e185 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -3416,6 +3416,7 @@ static void possible_parent_show(struct seq_file *s, struct clk_core *core,
unsigned int i, char terminator)
{
struct clk_core *parent;
+ const char *tmp;
/*
* Go through the following options to fetch a parent's name.
@@ -3436,12 +3437,12 @@ static void possible_parent_show(struct seq_file *s, struct clk_core *core,
seq_puts(s, core->parents[i].name);
else if (core->parents[i].fw_name)
seq_printf(s, "<%s>(fw)", core->parents[i].fw_name);
- else if (core->parents[i].index >= 0)
- seq_puts(s,
- of_clk_get_parent_name(core->of_node,
- core->parents[i].index));
- else
+ else if (core->parents[i].index >= 0) {
+ tmp = of_clk_get_parent_name(core->of_node, core->parents[i].index);
+ seq_puts(s, tmp ? tmp : "(none)");
+ } else {
seq_puts(s, "(missing)");
+ }
seq_putc(s, terminator);
}
--
2.34.1
next reply other threads:[~2023-08-22 13:49 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-22 13:48 Alessandro Carminati [this message]
2023-09-07 14:15 ` Alessandro Carminati
2023-09-07 22:33 ` Stephen Boyd
2023-09-08 8:36 ` Alessandro Carminati
2023-09-08 21:25 ` Stephen Boyd
2023-09-12 17:05 ` Alessandro Carminati
2023-09-12 17:59 ` Stephen Boyd
2023-09-14 13:25 ` Alessandro Carminati
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230822134849.3352329-1-alessandro.carminati@gmail.com \
--to=alessandro.carminati@gmail.com \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mturquette@baylibre.com \
--cc=pdaly@redhat.com \
--cc=sboyd@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®