2024-06-16 10:01:19

by Youwan Wang

[permalink] [raw]
Subject: [PATCH v1] ACPI /amba: Fix meaningless code for amba_register_dummy_clk()

Defining `amba_dummy_clk` as static is meaningless.

The conditional check `if (amba_dummy_clk)` is intended to
determine whether the clock has already been registered.
However,in this function, the variable `amba_dummy_clk`
will always be NULL.

Signed-off-by: Youwan Wang <[email protected]>
---
drivers/acpi/arm64/amba.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/acpi/arm64/amba.c b/drivers/acpi/arm64/amba.c
index 60be8ee1dbdc..ef438417cc80 100644
--- a/drivers/acpi/arm64/amba.c
+++ b/drivers/acpi/arm64/amba.c
@@ -35,11 +35,7 @@ static const struct acpi_device_id amba_id_list[] = {

static void amba_register_dummy_clk(void)
{
- static struct clk *amba_dummy_clk;
-
- /* If clock already registered */
- if (amba_dummy_clk)
- return;
+ struct clk *amba_dummy_clk;

amba_dummy_clk = clk_register_fixed_rate(NULL, "apb_pclk", NULL, 0, 0);
clk_register_clkdev(amba_dummy_clk, "apb_pclk", NULL);
--
2.25.1



2024-06-16 13:07:29

by Christophe JAILLET

[permalink] [raw]
Subject: Re: [PATCH v1] ACPI /amba: Fix meaningless code for amba_register_dummy_clk()

Le 16/06/2024 à 12:00, Youwan Wang a écrit :
> Defining `amba_dummy_clk` as static is meaningless.
>
> The conditional check `if (amba_dummy_clk)` is intended to
> determine whether the clock has already been registered.
> However,in this function, the variable `amba_dummy_clk`
> will always be NULL.

Hi,

can you elaborate on this "will always be NULL"?

I think that it is NULL on the first call of amba_register_dummy_clk(),
but if it is called again, it will have the value of
clk_register_fixed_rate() just a few lines after, doing exactly what the
comment says.

CJ

>
> Signed-off-by: Youwan Wang <[email protected]>
> ---
> drivers/acpi/arm64/amba.c | 6 +-----
> 1 file changed, 1 insertion(+), 5 deletions(-)
>
> diff --git a/drivers/acpi/arm64/amba.c b/drivers/acpi/arm64/amba.c
> index 60be8ee1dbdc..ef438417cc80 100644
> --- a/drivers/acpi/arm64/amba.c
> +++ b/drivers/acpi/arm64/amba.c
> @@ -35,11 +35,7 @@ static const struct acpi_device_id amba_id_list[] = {
>
> static void amba_register_dummy_clk(void)
> {
> - static struct clk *amba_dummy_clk;
> -
> - /* If clock already registered */
> - if (amba_dummy_clk)
> - return;
> + struct clk *amba_dummy_clk;
>
> amba_dummy_clk = clk_register_fixed_rate(NULL, "apb_pclk", NULL, 0, 0);
> clk_register_clkdev(amba_dummy_clk, "apb_pclk", NULL);