[PATCH 1/1] clk: scmi: fix scmi_clk_get_attibute()

Sean Anderson seanga2 at gmail.com
Sat Apr 30 16:17:18 CEST 2022


On 4/26/22 5:26 PM, Heinrich Schuchardt wrote:
> Local variable out.name lives on the stack and therefore cannot
> be returned directly. Move the strdup() call into the function.
> (Coverity 352460)
> 
> Fixes: 7c33f78983c3 ("clk: scmi: register scmi clocks with CCF")
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
> ---
>   drivers/clk/clk_scmi.c | 8 +++-----
>   1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/clk/clk_scmi.c b/drivers/clk/clk_scmi.c
> index 57022685e2..5aaabcf0b4 100644
> --- a/drivers/clk/clk_scmi.c
> +++ b/drivers/clk/clk_scmi.c
> @@ -53,7 +53,7 @@ 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);
>   
>   	return 0;
>   }
> @@ -152,11 +152,9 @@ static int scmi_clk_probe(struct udevice *dev)
>   		return ret;
>   
>   	for (i = 0; i < num_clocks; i++) {
> -		char *name;
> -
> -		if (!scmi_clk_get_attibute(dev, i, &name)) {
> -			char *clock_name = strdup(name);
> +		char *clock_name;
>   
> +		if (!scmi_clk_get_attibute(dev, i, &clock_name)) {
>   			clk = kzalloc(sizeof(*clk), GFP_KERNEL);
>   			if (!clk || !clock_name)
>   				ret = -ENOMEM;
> 

Addressing the same issue as [1]. Either will work, though your patch looks cleaner.

[1] https://lore.kernel.org/u-boot/20220426094938.21320-1-etienne.carriere@linaro.org/

Reviewed-by: Sean Anderson <seanga2 at gmail.com>


More information about the U-Boot mailing list