linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] soc: xilinx: vcu: remove deadcode on null divider check
@ 2021-02-10 18:49 Colin King
  2021-02-11  3:28 ` Stephen Boyd
  2021-02-11  7:31 ` Michael Tretter
  0 siblings, 2 replies; 8+ messages in thread
From: Colin King @ 2021-02-10 18:49 UTC (permalink / raw)
  To: Michael Turquette, Stephen Boyd, Michal Simek, Michael Tretter,
	linux-clk, linux-arm-kernel
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

The pointer 'divider' has previously been null checked followed by
a return, hence the subsequent null check is redundant deadcode
that can be removed.  Clean up the code and remove it.

Fixes: 9c789deea206 ("soc: xilinx: vcu: implement clock provider for output clocks")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/clk/xilinx/xlnx_vcu.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/clk/xilinx/xlnx_vcu.c b/drivers/clk/xilinx/xlnx_vcu.c
index d66b1315114e..607936d7a413 100644
--- a/drivers/clk/xilinx/xlnx_vcu.c
+++ b/drivers/clk/xilinx/xlnx_vcu.c
@@ -512,9 +512,6 @@ static void xvcu_clk_hw_unregister_leaf(struct clk_hw *hw)
 
 	mux = clk_hw_get_parent(divider);
 	clk_hw_unregister_mux(mux);
-	if (!divider)
-		return;
-
 	clk_hw_unregister_divider(divider);
 }
 
-- 
2.30.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH][next] soc: xilinx: vcu: remove deadcode on null divider check
  2021-02-10 18:49 [PATCH][next] soc: xilinx: vcu: remove deadcode on null divider check Colin King
@ 2021-02-11  3:28 ` Stephen Boyd
  2021-02-11  7:39   ` Michael Tretter
  2021-02-11  7:31 ` Michael Tretter
  1 sibling, 1 reply; 8+ messages in thread
From: Stephen Boyd @ 2021-02-11  3:28 UTC (permalink / raw)
  To: Colin King, Michael Tretter, Michael Turquette, Michal Simek,
	linux-arm-kernel, linux-clk
  Cc: kernel-janitors, linux-kernel

Quoting Colin King (2021-02-10 10:49:38)
> From: Colin Ian King <colin.king@canonical.com>
> 
> The pointer 'divider' has previously been null checked followed by
> a return, hence the subsequent null check is redundant deadcode
> that can be removed.  Clean up the code and remove it.
> 
> Fixes: 9c789deea206 ("soc: xilinx: vcu: implement clock provider for output clocks")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/clk/xilinx/xlnx_vcu.c | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/drivers/clk/xilinx/xlnx_vcu.c b/drivers/clk/xilinx/xlnx_vcu.c
> index d66b1315114e..607936d7a413 100644
> --- a/drivers/clk/xilinx/xlnx_vcu.c
> +++ b/drivers/clk/xilinx/xlnx_vcu.c
> @@ -512,9 +512,6 @@ static void xvcu_clk_hw_unregister_leaf(struct clk_hw *hw)
>  
>         mux = clk_hw_get_parent(divider);
>         clk_hw_unregister_mux(mux);
> -       if (!divider)
> -               return;
> -

This code is pretty confusing. Waiting for m.tretter@pengutronix.de to
reply

>         clk_hw_unregister_divider(divider);
>  }
>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH][next] soc: xilinx: vcu: remove deadcode on null divider check
  2021-02-10 18:49 [PATCH][next] soc: xilinx: vcu: remove deadcode on null divider check Colin King
  2021-02-11  3:28 ` Stephen Boyd
@ 2021-02-11  7:31 ` Michael Tretter
  2021-02-11  9:41   ` Colin Ian King
  1 sibling, 1 reply; 8+ messages in thread
From: Michael Tretter @ 2021-02-11  7:31 UTC (permalink / raw)
  To: Colin King
  Cc: Stephen Boyd, Michael Turquette, kernel-janitors, Michal Simek,
	linux-kernel, linux-clk, linux-arm-kernel

On Wed, 10 Feb 2021 18:49:38 +0000, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The pointer 'divider' has previously been null checked followed by
> a return, hence the subsequent null check is redundant deadcode
> that can be removed.  Clean up the code and remove it.
> 
> Fixes: 9c789deea206 ("soc: xilinx: vcu: implement clock provider for output clocks")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/clk/xilinx/xlnx_vcu.c | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/drivers/clk/xilinx/xlnx_vcu.c b/drivers/clk/xilinx/xlnx_vcu.c
> index d66b1315114e..607936d7a413 100644
> --- a/drivers/clk/xilinx/xlnx_vcu.c
> +++ b/drivers/clk/xilinx/xlnx_vcu.c
> @@ -512,9 +512,6 @@ static void xvcu_clk_hw_unregister_leaf(struct clk_hw *hw)
>  
>  	mux = clk_hw_get_parent(divider);
>  	clk_hw_unregister_mux(mux);
> -	if (!divider)
> -		return;
> -
>  	clk_hw_unregister_divider(divider);

Thanks for pointing this out. There is actually a different bug there.

There should have been a check for !mux before unregistering the mux:

	mux = clk_hw_get_parent(divider);
	clk_hw_unregister_divider(divider);
	if (!mux)
		return;

	clk_hw_unregister_mux(mux);

Michael

>  }
>  
> -- 
> 2.30.0
> 
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH][next] soc: xilinx: vcu: remove deadcode on null divider check
  2021-02-11  3:28 ` Stephen Boyd
@ 2021-02-11  7:39   ` Michael Tretter
  2021-02-11 19:05     ` Stephen Boyd
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Tretter @ 2021-02-11  7:39 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: Michael Turquette, kernel-janitors, Michal Simek, linux-kernel,
	Colin King, linux-clk, linux-arm-kernel

On Wed, 10 Feb 2021 19:28:18 -0800, Stephen Boyd wrote:
> Quoting Colin King (2021-02-10 10:49:38)
> > From: Colin Ian King <colin.king@canonical.com>
> > 
> > The pointer 'divider' has previously been null checked followed by
> > a return, hence the subsequent null check is redundant deadcode
> > that can be removed.  Clean up the code and remove it.
> > 
> > Fixes: 9c789deea206 ("soc: xilinx: vcu: implement clock provider for output clocks")
> > Signed-off-by: Colin Ian King <colin.king@canonical.com>
> > ---
> >  drivers/clk/xilinx/xlnx_vcu.c | 3 ---
> >  1 file changed, 3 deletions(-)
> > 
> > diff --git a/drivers/clk/xilinx/xlnx_vcu.c b/drivers/clk/xilinx/xlnx_vcu.c
> > index d66b1315114e..607936d7a413 100644
> > --- a/drivers/clk/xilinx/xlnx_vcu.c
> > +++ b/drivers/clk/xilinx/xlnx_vcu.c
> > @@ -512,9 +512,6 @@ static void xvcu_clk_hw_unregister_leaf(struct clk_hw *hw)
> >  
> >         mux = clk_hw_get_parent(divider);
> >         clk_hw_unregister_mux(mux);
> > -       if (!divider)
> > -               return;
> > -
> 
> This code is pretty confusing. Waiting for m.tretter@pengutronix.de to
> reply

Can you elaborate what you find confusing about this code. I would gladly try
to clarify and improve the code.

What happens here is that the driver registers a mux -> divider -> gate chain
for each output clock, but only stores the gate clock. When unregistering the
clocks, the driver starts at the gate and walks up to the mux while
unregistering the clocks.

Michael

> 
> >         clk_hw_unregister_divider(divider);
> >  }
> >
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH][next] soc: xilinx: vcu: remove deadcode on null divider check
  2021-02-11  7:31 ` Michael Tretter
@ 2021-02-11  9:41   ` Colin Ian King
  0 siblings, 0 replies; 8+ messages in thread
From: Colin Ian King @ 2021-02-11  9:41 UTC (permalink / raw)
  To: Michael Tretter
  Cc: Stephen Boyd, Michael Turquette, kernel-janitors, Michal Simek,
	linux-kernel, linux-clk, linux-arm-kernel

On 11/02/2021 07:31, Michael Tretter wrote:
> On Wed, 10 Feb 2021 18:49:38 +0000, Colin King wrote:
>> From: Colin Ian King <colin.king@canonical.com>
>>
>> The pointer 'divider' has previously been null checked followed by
>> a return, hence the subsequent null check is redundant deadcode
>> that can be removed.  Clean up the code and remove it.
>>
>> Fixes: 9c789deea206 ("soc: xilinx: vcu: implement clock provider for output clocks")
>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
>> ---
>>  drivers/clk/xilinx/xlnx_vcu.c | 3 ---
>>  1 file changed, 3 deletions(-)
>>
>> diff --git a/drivers/clk/xilinx/xlnx_vcu.c b/drivers/clk/xilinx/xlnx_vcu.c
>> index d66b1315114e..607936d7a413 100644
>> --- a/drivers/clk/xilinx/xlnx_vcu.c
>> +++ b/drivers/clk/xilinx/xlnx_vcu.c
>> @@ -512,9 +512,6 @@ static void xvcu_clk_hw_unregister_leaf(struct clk_hw *hw)
>>  
>>  	mux = clk_hw_get_parent(divider);
>>  	clk_hw_unregister_mux(mux);
>> -	if (!divider)
>> -		return;
>> -
>>  	clk_hw_unregister_divider(divider);
> 
> Thanks for pointing this out. There is actually a different bug there.
> 
> There should have been a check for !mux before unregistering the mux:
> 
> 	mux = clk_hw_get_parent(divider);
> 	clk_hw_unregister_divider(divider);
> 	if (!mux)
> 		return;

Ah, that makes sense, I'll send a V2.

> 
> 	clk_hw_unregister_mux(mux);
> 
> Michael
> 
>>  }
>>  
>> -- 
>> 2.30.0
>>
>>


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH][next] soc: xilinx: vcu: remove deadcode on null divider check
  2021-02-11  7:39   ` Michael Tretter
@ 2021-02-11 19:05     ` Stephen Boyd
  2021-03-18 12:48       ` Colin Ian King
  0 siblings, 1 reply; 8+ messages in thread
From: Stephen Boyd @ 2021-02-11 19:05 UTC (permalink / raw)
  To: Michael Tretter
  Cc: Michael Turquette, kernel-janitors, Michal Simek, linux-kernel,
	Colin King, linux-clk, linux-arm-kernel

Quoting Michael Tretter (2021-02-10 23:39:06)
> On Wed, 10 Feb 2021 19:28:18 -0800, Stephen Boyd wrote:
> > Quoting Colin King (2021-02-10 10:49:38)
> > > From: Colin Ian King <colin.king@canonical.com>
> > > 
> > > The pointer 'divider' has previously been null checked followed by
> > > a return, hence the subsequent null check is redundant deadcode
> > > that can be removed.  Clean up the code and remove it.
> > > 
> > > Fixes: 9c789deea206 ("soc: xilinx: vcu: implement clock provider for output clocks")
> > > Signed-off-by: Colin Ian King <colin.king@canonical.com>
> > > ---
> > >  drivers/clk/xilinx/xlnx_vcu.c | 3 ---
> > >  1 file changed, 3 deletions(-)
> > > 
> > > diff --git a/drivers/clk/xilinx/xlnx_vcu.c b/drivers/clk/xilinx/xlnx_vcu.c
> > > index d66b1315114e..607936d7a413 100644
> > > --- a/drivers/clk/xilinx/xlnx_vcu.c
> > > +++ b/drivers/clk/xilinx/xlnx_vcu.c
> > > @@ -512,9 +512,6 @@ static void xvcu_clk_hw_unregister_leaf(struct clk_hw *hw)
> > >  
> > >         mux = clk_hw_get_parent(divider);
> > >         clk_hw_unregister_mux(mux);
> > > -       if (!divider)
> > > -               return;
> > > -
> > 
> > This code is pretty confusing. Waiting for m.tretter@pengutronix.de to
> > reply
> 
> Can you elaborate what you find confusing about this code. I would gladly try
> to clarify and improve the code.

The fact that pointers are being checked and then bailing out of the
function early, vs. doing something if the pointer is non-NULL.

> 
> What happens here is that the driver registers a mux -> divider -> gate chain
> for each output clock, but only stores the gate clock. When unregistering the
> clocks, the driver starts at the gate and walks up to the mux while
> unregistering the clocks.
>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH][next] soc: xilinx: vcu: remove deadcode on null divider check
  2021-02-11 19:05     ` Stephen Boyd
@ 2021-03-18 12:48       ` Colin Ian King
  2021-03-18 14:44         ` Michael Tretter
  0 siblings, 1 reply; 8+ messages in thread
From: Colin Ian King @ 2021-03-18 12:48 UTC (permalink / raw)
  To: Stephen Boyd, Michael Tretter
  Cc: Michael Turquette, Michal Simek, linux-arm-kernel, linux-clk,
	kernel-janitors, linux-kernel

On 11/02/2021 19:05, Stephen Boyd wrote:
> Quoting Michael Tretter (2021-02-10 23:39:06)
>> On Wed, 10 Feb 2021 19:28:18 -0800, Stephen Boyd wrote:
>>> Quoting Colin King (2021-02-10 10:49:38)
>>>> From: Colin Ian King <colin.king@canonical.com>
>>>>
>>>> The pointer 'divider' has previously been null checked followed by
>>>> a return, hence the subsequent null check is redundant deadcode
>>>> that can be removed.  Clean up the code and remove it.
>>>>
>>>> Fixes: 9c789deea206 ("soc: xilinx: vcu: implement clock provider for output clocks")
>>>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
>>>> ---
>>>>  drivers/clk/xilinx/xlnx_vcu.c | 3 ---
>>>>  1 file changed, 3 deletions(-)
>>>>
>>>> diff --git a/drivers/clk/xilinx/xlnx_vcu.c b/drivers/clk/xilinx/xlnx_vcu.c
>>>> index d66b1315114e..607936d7a413 100644
>>>> --- a/drivers/clk/xilinx/xlnx_vcu.c
>>>> +++ b/drivers/clk/xilinx/xlnx_vcu.c
>>>> @@ -512,9 +512,6 @@ static void xvcu_clk_hw_unregister_leaf(struct clk_hw *hw)
>>>>  
>>>>         mux = clk_hw_get_parent(divider);
>>>>         clk_hw_unregister_mux(mux);
>>>> -       if (!divider)
>>>> -               return;
>>>> -
>>>
>>> This code is pretty confusing. Waiting for m.tretter@pengutronix.de to
>>> reply
>>
>> Can you elaborate what you find confusing about this code. I would gladly try
>> to clarify and improve the code.
> 
> The fact that pointers are being checked and then bailing out of the
> function early, vs. doing something if the pointer is non-NULL.
> 
>>
>> What happens here is that the driver registers a mux -> divider -> gate chain
>> for each output clock, but only stores the gate clock. When unregistering the
>> clocks, the driver starts at the gate and walks up to the mux while
>> unregistering the clocks.
>>

OK, so I think I understand this better, should the order of
unregisteration be as follows:

diff --git a/drivers/clk/xilinx/xlnx_vcu.c b/drivers/clk/xilinx/xlnx_vcu.c
index d66b1315114e..66bac8421460 100644
--- a/drivers/clk/xilinx/xlnx_vcu.c
+++ b/drivers/clk/xilinx/xlnx_vcu.c
@@ -511,11 +511,11 @@ static void xvcu_clk_hw_unregister_leaf(struct
clk_hw *hw)
                return;

        mux = clk_hw_get_parent(divider);
-       clk_hw_unregister_mux(mux);
-       if (!divider)
+       clk_hw_unregister_mux(divider);
+       if (!mux)
                return;

-       clk_hw_unregister_divider(divider);
+       clk_hw_unregister_divider(mux);

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH][next] soc: xilinx: vcu: remove deadcode on null divider check
  2021-03-18 12:48       ` Colin Ian King
@ 2021-03-18 14:44         ` Michael Tretter
  0 siblings, 0 replies; 8+ messages in thread
From: Michael Tretter @ 2021-03-18 14:44 UTC (permalink / raw)
  To: Colin Ian King
  Cc: Stephen Boyd, Michael Turquette, Michal Simek, linux-arm-kernel,
	linux-clk, kernel-janitors, linux-kernel

On Thu, 18 Mar 2021 12:48:06 +0000, Colin Ian King wrote:
> On 11/02/2021 19:05, Stephen Boyd wrote:
> > Quoting Michael Tretter (2021-02-10 23:39:06)
> >> On Wed, 10 Feb 2021 19:28:18 -0800, Stephen Boyd wrote:
> >>> Quoting Colin King (2021-02-10 10:49:38)
> >>>> From: Colin Ian King <colin.king@canonical.com>
> >>>>
> >>>> The pointer 'divider' has previously been null checked followed by
> >>>> a return, hence the subsequent null check is redundant deadcode
> >>>> that can be removed.  Clean up the code and remove it.
> >>>>
> >>>> Fixes: 9c789deea206 ("soc: xilinx: vcu: implement clock provider for output clocks")
> >>>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> >>>> ---
> >>>>  drivers/clk/xilinx/xlnx_vcu.c | 3 ---
> >>>>  1 file changed, 3 deletions(-)
> >>>>
> >>>> diff --git a/drivers/clk/xilinx/xlnx_vcu.c b/drivers/clk/xilinx/xlnx_vcu.c
> >>>> index d66b1315114e..607936d7a413 100644
> >>>> --- a/drivers/clk/xilinx/xlnx_vcu.c
> >>>> +++ b/drivers/clk/xilinx/xlnx_vcu.c
> >>>> @@ -512,9 +512,6 @@ static void xvcu_clk_hw_unregister_leaf(struct clk_hw *hw)
> >>>>  
> >>>>         mux = clk_hw_get_parent(divider);
> >>>>         clk_hw_unregister_mux(mux);
> >>>> -       if (!divider)
> >>>> -               return;
> >>>> -
> >>>
> >>> This code is pretty confusing. Waiting for m.tretter@pengutronix.de to
> >>> reply
> >>
> >> Can you elaborate what you find confusing about this code. I would gladly try
> >> to clarify and improve the code.
> > 
> > The fact that pointers are being checked and then bailing out of the
> > function early, vs. doing something if the pointer is non-NULL.
> > 
> >>
> >> What happens here is that the driver registers a mux -> divider -> gate chain
> >> for each output clock, but only stores the gate clock. When unregistering the
> >> clocks, the driver starts at the gate and walks up to the mux while
> >> unregistering the clocks.
> >>
> 
> OK, so I think I understand this better, should the order of
> unregisteration be as follows:
> 
> diff --git a/drivers/clk/xilinx/xlnx_vcu.c b/drivers/clk/xilinx/xlnx_vcu.c
> index d66b1315114e..66bac8421460 100644
> --- a/drivers/clk/xilinx/xlnx_vcu.c
> +++ b/drivers/clk/xilinx/xlnx_vcu.c
> @@ -511,11 +511,11 @@ static void xvcu_clk_hw_unregister_leaf(struct
> clk_hw *hw)
>                 return;
> 
>         mux = clk_hw_get_parent(divider);
> -       clk_hw_unregister_mux(mux);
> -       if (!divider)
> +       clk_hw_unregister_mux(divider);

The order is correct, but this must be:

	clk_hw_unregister_divider(divider);

> +       if (!mux)
>                 return;
> 
> -       clk_hw_unregister_divider(divider);
> +       clk_hw_unregister_divider(mux);
> 

	clk_hw_unregister_mux(mux);

Taking the confusion expressed by Stephen into account, I rewrote the entire
function to clarify what is happening in this function. Please take a look
that patch [0] and tell me, if it is now easier to understand.

[0] 20210318144230.3438009-1-m.tretter@pengutronix.de

Michael

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2021-03-18 14:45 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-10 18:49 [PATCH][next] soc: xilinx: vcu: remove deadcode on null divider check Colin King
2021-02-11  3:28 ` Stephen Boyd
2021-02-11  7:39   ` Michael Tretter
2021-02-11 19:05     ` Stephen Boyd
2021-03-18 12:48       ` Colin Ian King
2021-03-18 14:44         ` Michael Tretter
2021-02-11  7:31 ` Michael Tretter
2021-02-11  9:41   ` Colin Ian King

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