linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] powerpc/powermac: fix a loop in core99_usb_enable
@ 2025-02-02 12:46 Denis Kirjanov
  2025-02-02 17:05 ` Christophe Leroy
  0 siblings, 1 reply; 2+ messages in thread
From: Denis Kirjanov @ 2025-02-02 12:46 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: maddy, mpe, benh, Denis Kirjanov

Looks like we have a typo in the do-while loop
while checking the loop condition. Fix it with the boolean OR

Signed-off-by: Denis Kirjanov <kirjanov@gmail.com>
---
 arch/powerpc/platforms/powermac/feature.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/platforms/powermac/feature.c b/arch/powerpc/platforms/powermac/feature.c
index d3bcfe590384..9d929fbfc46b 100644
--- a/arch/powerpc/platforms/powermac/feature.c
+++ b/arch/powerpc/platforms/powermac/feature.c
@@ -1174,7 +1174,7 @@ core99_usb_enable(struct device_node *node, long param, long value)
 				mdelay(1);
 				status0 = UN_IN(UNI_N_CLOCK_STOP_STATUS0);
 				status1 = UN_IN(UNI_N_CLOCK_STOP_STATUS1);
-			} while ((status0 & test0) | (status1 & test1));
+			} while ((status0 & test0) || (status1 & test1));
 			LOCK(flags);
 		}
 	} else {
-- 
2.47.2



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

* Re: [PATCH] powerpc/powermac: fix a loop in core99_usb_enable
  2025-02-02 12:46 [PATCH] powerpc/powermac: fix a loop in core99_usb_enable Denis Kirjanov
@ 2025-02-02 17:05 ` Christophe Leroy
  0 siblings, 0 replies; 2+ messages in thread
From: Christophe Leroy @ 2025-02-02 17:05 UTC (permalink / raw)
  To: Denis Kirjanov, linuxppc-dev; +Cc: maddy, mpe, benh



Le 02/02/2025 à 13:46, Denis Kirjanov a écrit :
> Looks like we have a typo in the do-while loop
> while checking the loop condition. Fix it with the boolean OR

Are you sure it is a typo, not a feature ?

At the moment the generated code is:

      6f4:       7f 89 48 38     and     r9,r28,r9
      6f8:       7f aa 50 38     and     r10,r29,r10
      6fc:       7d 29 53 79     or.     r9,r9,r10
      700:       40 82 ff bc     bne     6bc <core99_usb_enable+0x1c0>

With your patch it now is:

      6f8:       7f 89 48 38     and     r9,r28,r9
      6fc:       7f aa 50 38     and     r10,r29,r10
      700:       7d 29 53 78     or      r9,r9,r10
...
      708:       2f 89 00 00     cmpwi   cr7,r9,0
      70c:       40 9e ff b8     bne     cr7,6c4 <core99_usb_enable+0x1c8>

So with your patch the code is doing exactly the same but is less optimal.

0 || 0 ==> 0
0 || !0 ==> 1
!0 || 0 ==> 1
!0 || !0 ==> 1

0 | 0 ==> 0
!0 | 0 ==> !0
0 | !0 ==> !0
!0 | !0 ==> !0

In both case it is only false when the two sides are 0 otherwise it is true.

Usually a logic OR does the same as a boolean OR but is more optimal.

Christophe



> 
> Signed-off-by: Denis Kirjanov <kirjanov@gmail.com>
> ---
>   arch/powerpc/platforms/powermac/feature.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/powerpc/platforms/powermac/feature.c b/arch/powerpc/platforms/powermac/feature.c
> index d3bcfe590384..9d929fbfc46b 100644
> --- a/arch/powerpc/platforms/powermac/feature.c
> +++ b/arch/powerpc/platforms/powermac/feature.c
> @@ -1174,7 +1174,7 @@ core99_usb_enable(struct device_node *node, long param, long value)
>   				mdelay(1);
>   				status0 = UN_IN(UNI_N_CLOCK_STOP_STATUS0);
>   				status1 = UN_IN(UNI_N_CLOCK_STOP_STATUS1);
> -			} while ((status0 & test0) | (status1 & test1));
> +			} while ((status0 & test0) || (status1 & test1));
>   			LOCK(flags);
>   		}
>   	} else {



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

end of thread, other threads:[~2025-02-02 17:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-02 12:46 [PATCH] powerpc/powermac: fix a loop in core99_usb_enable Denis Kirjanov
2025-02-02 17:05 ` Christophe Leroy

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