linux-clk.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] clk: Warn and add workaround on misuse of .parent_data with .name only
@ 2022-11-08 20:49 Christian Marangi
  2022-11-25 23:06 ` Christian Marangi
  0 siblings, 1 reply; 2+ messages in thread
From: Christian Marangi @ 2022-11-08 20:49 UTC (permalink / raw)
  To: Michael Turquette, Stephen Boyd, linux-clk, linux-kernel,
	Robert Marko
  Cc: Christian Marangi

By a simple mistake in a .parent_names to .parent_data conversion it was
found that clk core assume fw_name is always provided with a parent_data
struct for each parent and never fallback to .name to get parent name even
if declared.

This is caused by clk_core_get that only checks for parent .fw_name and
doesn't handle .name.

While it's sane to request the dev to correctly do the conversion and
add both .fw_name and .name in a parent_data struct, it's not sane to
silently drop parents without a warning.

Fix this in 2 ways. Add a kernel warning when a wrong implementation is
used and copy .name in .fw_name in parent map populate function to
handle clk problems and malfunctions.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 drivers/clk/clk.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 57b83665e5c3..dccd4ea6f692 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -4015,10 +4015,21 @@ static int clk_core_populate_parent_map(struct clk_core *core,
 			ret = clk_cpy_name(&parent->name, parent_names[i],
 					   true);
 		} else if (parent_data) {
+			const char *parent_name;
+
 			parent->hw = parent_data[i].hw;
 			parent->index = parent_data[i].index;
+			parent_name = parent_data[i].fw_name;
+
+			if (!parent_name && parent_data[i].name) {
+				WARN(1, "Empty .fw_name with .name in %s's .parent_data. Using .name for .fw_name declaration.\n",
+				     core->name);
+				parent_name = parent_data[i].name;
+			}
+
 			ret = clk_cpy_name(&parent->fw_name,
-					   parent_data[i].fw_name, false);
+					   parent_name, false);
+
 			if (!ret)
 				ret = clk_cpy_name(&parent->name,
 						   parent_data[i].name,
-- 
2.37.2


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

* Re: [PATCH] clk: Warn and add workaround on misuse of .parent_data with .name only
  2022-11-08 20:49 [PATCH] clk: Warn and add workaround on misuse of .parent_data with .name only Christian Marangi
@ 2022-11-25 23:06 ` Christian Marangi
  0 siblings, 0 replies; 2+ messages in thread
From: Christian Marangi @ 2022-11-25 23:06 UTC (permalink / raw)
  To: Michael Turquette, Stephen Boyd, linux-clk, linux-kernel,
	Robert Marko

On Tue, Nov 08, 2022 at 09:49:18PM +0100, Christian Marangi wrote:
> By a simple mistake in a .parent_names to .parent_data conversion it was
> found that clk core assume fw_name is always provided with a parent_data
> struct for each parent and never fallback to .name to get parent name even
> if declared.
> 
> This is caused by clk_core_get that only checks for parent .fw_name and
> doesn't handle .name.
> 
> While it's sane to request the dev to correctly do the conversion and
> add both .fw_name and .name in a parent_data struct, it's not sane to
> silently drop parents without a warning.
> 
> Fix this in 2 ways. Add a kernel warning when a wrong implementation is
> used and copy .name in .fw_name in parent map populate function to
> handle clk problems and malfunctions.
> 
> Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>

Friendly bump for this?

> ---
>  drivers/clk/clk.c | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> index 57b83665e5c3..dccd4ea6f692 100644
> --- a/drivers/clk/clk.c
> +++ b/drivers/clk/clk.c
> @@ -4015,10 +4015,21 @@ static int clk_core_populate_parent_map(struct clk_core *core,
>  			ret = clk_cpy_name(&parent->name, parent_names[i],
>  					   true);
>  		} else if (parent_data) {
> +			const char *parent_name;
> +
>  			parent->hw = parent_data[i].hw;
>  			parent->index = parent_data[i].index;
> +			parent_name = parent_data[i].fw_name;
> +
> +			if (!parent_name && parent_data[i].name) {
> +				WARN(1, "Empty .fw_name with .name in %s's .parent_data. Using .name for .fw_name declaration.\n",
> +				     core->name);
> +				parent_name = parent_data[i].name;
> +			}
> +
>  			ret = clk_cpy_name(&parent->fw_name,
> -					   parent_data[i].fw_name, false);
> +					   parent_name, false);
> +
>  			if (!ret)
>  				ret = clk_cpy_name(&parent->name,
>  						   parent_data[i].name,
> -- 
> 2.37.2
> 

-- 
	Ansuel

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

end of thread, other threads:[~2022-11-25 23:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-08 20:49 [PATCH] clk: Warn and add workaround on misuse of .parent_data with .name only Christian Marangi
2022-11-25 23:06 ` Christian Marangi

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).