All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] clk: scmi: fix invalid clock name references
@ 2022-04-26  7:52 Etienne Carriere
  2022-04-26  8:55 ` Etienne Carriere
  0 siblings, 1 reply; 2+ messages in thread
From: Etienne Carriere @ 2022-04-26  7:52 UTC (permalink / raw)
  To: u-boot
  Cc: Lukasz Majewski, Sean Anderson, Patrick Delaunay,
	Gabriel Fernandez, Etienne Carriere

Fixes clock name references in scmi_clk driver. SCMI clock names are
retrieved from the SCMI firmware by invoking SCMI commands using the
stack for SCMI response message hence clocks names located in the
stack must be duplicated before being registered in the clock framework.

Fixes: 7c33f78983c3 ("clk: scmi: register scmi clocks with CCF")
Reported-by: scan-admin@coverity.com
Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
---
Changes since v1:
- Fix buggy test on strdup() return value
---
 drivers/clk/clk_scmi.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/clk_scmi.c b/drivers/clk/clk_scmi.c
index 57022685e2..c8e10c4aea 100644
--- a/drivers/clk/clk_scmi.c
+++ b/drivers/clk/clk_scmi.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * Copyright (C) 2019-2020 Linaro Limited
+ * Copyright (C) 2019-2022 Linaro Limited
  */
 
 #define LOG_CATEGORY UCLASS_CLK
@@ -12,6 +12,7 @@
 #include <scmi_protocols.h>
 #include <asm/types.h>
 #include <linux/clk-provider.h>
+#include <linux/string.h>
 
 static int scmi_clk_get_num_clock(struct udevice *dev, size_t *num_clocks)
 {
@@ -53,7 +54,9 @@ static int scmi_clk_get_attibute(struct udevice *dev, int clkid, char **name)
 	if (ret)
 		return ret;
 
-	*name = out.clock_name;
+	*name = strdup(out.clock_name);
+	if (!*name)
+		return -ENOMEM;
 
 	return 0;
 }
-- 
2.17.1


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

* Re: [PATCH v2] clk: scmi: fix invalid clock name references
  2022-04-26  7:52 [PATCH v2] clk: scmi: fix invalid clock name references Etienne Carriere
@ 2022-04-26  8:55 ` Etienne Carriere
  0 siblings, 0 replies; 2+ messages in thread
From: Etienne Carriere @ 2022-04-26  8:55 UTC (permalink / raw)
  To: u-boot
  Cc: Lukasz Majewski, Sean Anderson, Patrick Delaunay, Gabriel Fernandez

Dear all,

On Tue, 26 Apr 2022 at 09:52, Etienne Carriere
<etienne.carriere@linaro.org> wrote:
>
> Fixes clock name references in scmi_clk driver. SCMI clock names are
> retrieved from the SCMI firmware by invoking SCMI commands using the
> stack for SCMI response message hence clocks names located in the
> stack must be duplicated before being registered in the clock framework.
>
> Fixes: 7c33f78983c3 ("clk: scmi: register scmi clocks with CCF")
> Reported-by: scan-admin@coverity.com
> Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
> ---
> Changes since v1:
> - Fix buggy test on strdup() return value
> ---
>  drivers/clk/clk_scmi.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/clk/clk_scmi.c b/drivers/clk/clk_scmi.c
> index 57022685e2..c8e10c4aea 100644
> --- a/drivers/clk/clk_scmi.c
> +++ b/drivers/clk/clk_scmi.c
> @@ -1,6 +1,6 @@
>  // SPDX-License-Identifier: GPL-2.0+
>  /*
> - * Copyright (C) 2019-2020 Linaro Limited
> + * Copyright (C) 2019-2022 Linaro Limited
>   */
>
>  #define LOG_CATEGORY UCLASS_CLK
> @@ -12,6 +12,7 @@
>  #include <scmi_protocols.h>
>  #include <asm/types.h>
>  #include <linux/clk-provider.h>
> +#include <linux/string.h>
>
>  static int scmi_clk_get_num_clock(struct udevice *dev, size_t *num_clocks)
>  {
> @@ -53,7 +54,9 @@ static int scmi_clk_get_attibute(struct udevice *dev, int clkid, char **name)
>         if (ret)
>                 return ret;
>
> -       *name = out.clock_name;
> +       *name = strdup(out.clock_name);
> +       if (!*name)
> +               return -ENOMEM;
>
>         return 0;
>  }
> --
> 2.17.1
>

I posted this change too quickly and missed something.
With this change, the clock name is duplicated twice since it's already
duplicated in caller function scmi_clk_probe().

Please discard this change. I'll send a v3 proposal to address the issue
in a more consistent way.

My apologies,
Etienne

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

end of thread, other threads:[~2022-04-26  8:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-26  7:52 [PATCH v2] clk: scmi: fix invalid clock name references Etienne Carriere
2022-04-26  8:55 ` Etienne Carriere

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.