mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* sibyte: pointless if tests
@ 2024-02-24 22:28 Joe Perches
  2024-02-28 11:52 ` Philippe Mathieu-Daudé
  2024-05-14 23:49 ` Maciej W. Rozycki
  0 siblings, 2 replies; 3+ messages in thread
From: Joe Perches @ 2024-02-24 22:28 UTC (permalink / raw)
  To: Thomas Bogendoerfer; +Cc: linux-mips, LKML

A checkpatch modification was suggested privately about
braces around an if test like

	if (foo)
		;

so I thought I'd see how many of these possibly pointless
if tests exist.  There aren't many.

Here are a couple in sibyte:

Maybe this should be documented as:

	"well, don't know what to do here"

$ cat if_semi.cocci
@@
expression e;
@@

*	if (e) ;

$ spatch --very-quiet -sp-file if_semi.cocci .
diff -u -p ./arch/mips/sibyte/common/cfe_console.c /tmp/nothing/arch/mips/sibyte/common/cfe_console.c
--- ./arch/mips/sibyte/common/cfe_console.c
+++ /tmp/nothing/arch/mips/sibyte/common/cfe_console.c
@@ -22,8 +22,6 @@ static void cfe_console_write(struct con
 		if (str[i] == '\n') {
 			do {
 				written = cfe_write(cfe_cons_handle, &str[last], i-last);
-				if (written < 0)
-					;
 				last += written;
 			} while (last < i);
 			while (cfe_write(cfe_cons_handle, "\r", 1) <= 0)
@@ -33,8 +31,6 @@ static void cfe_console_write(struct con
 	if (last != count) {
 		do {
 			written = cfe_write(cfe_cons_handle, &str[last], count-last);
-			if (written < 0)
-				;
 			last += written;
 		} while (last < count);
 	}


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

* Re: sibyte: pointless if tests
  2024-02-24 22:28 sibyte: pointless if tests Joe Perches
@ 2024-02-28 11:52 ` Philippe Mathieu-Daudé
  2024-05-14 23:49 ` Maciej W. Rozycki
  1 sibling, 0 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-02-28 11:52 UTC (permalink / raw)
  To: Joe Perches, Thomas Bogendoerfer; +Cc: linux-mips, LKML

On 24/2/24 23:28, Joe Perches wrote:
> A checkpatch modification was suggested privately about
> braces around an if test like
> 
> 	if (foo)
> 		;
> 
> so I thought I'd see how many of these possibly pointless
> if tests exist.  There aren't many.
> 
> Here are a couple in sibyte:
> 
> Maybe this should be documented as:
> 
> 	"well, don't know what to do here"

Or pr_devel() / pr_warn() if you want someone to notice it :)

> 
> $ cat if_semi.cocci
> @@
> expression e;
> @@
> 
> *	if (e) ;
> 
> $ spatch --very-quiet -sp-file if_semi.cocci .
> diff -u -p ./arch/mips/sibyte/common/cfe_console.c /tmp/nothing/arch/mips/sibyte/common/cfe_console.c
> --- ./arch/mips/sibyte/common/cfe_console.c
> +++ /tmp/nothing/arch/mips/sibyte/common/cfe_console.c
> @@ -22,8 +22,6 @@ static void cfe_console_write(struct con
>   		if (str[i] == '\n') {
>   			do {
>   				written = cfe_write(cfe_cons_handle, &str[last], i-last);
> -				if (written < 0)
> -					;
>   				last += written;
>   			} while (last < i);
>   			while (cfe_write(cfe_cons_handle, "\r", 1) <= 0)
> @@ -33,8 +31,6 @@ static void cfe_console_write(struct con
>   	if (last != count) {
>   		do {
>   			written = cfe_write(cfe_cons_handle, &str[last], count-last);
> -			if (written < 0)
> -				;
>   			last += written;
>   		} while (last < count);
>   	}
> 


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

* Re: sibyte: pointless if tests
  2024-02-24 22:28 sibyte: pointless if tests Joe Perches
  2024-02-28 11:52 ` Philippe Mathieu-Daudé
@ 2024-05-14 23:49 ` Maciej W. Rozycki
  1 sibling, 0 replies; 3+ messages in thread
From: Maciej W. Rozycki @ 2024-05-14 23:49 UTC (permalink / raw)
  To: Joe Perches; +Cc: Thomas Bogendoerfer, linux-mips, LKML

On Sat, 24 Feb 2024, Joe Perches wrote:

> Here are a couple in sibyte:
> 
> Maybe this should be documented as:
> 
> 	"well, don't know what to do here"

 Of course just removing these useless conditionals isn't going to help 
here because if a console write does fail for some reason, then the index 
will move backwards regardless.  At least we now have some kind of a 
placeholder to bring someone's attention (such as yours).

> $ spatch --very-quiet -sp-file if_semi.cocci .
> diff -u -p ./arch/mips/sibyte/common/cfe_console.c /tmp/nothing/arch/mips/sibyte/common/cfe_console.c
> --- ./arch/mips/sibyte/common/cfe_console.c
> +++ /tmp/nothing/arch/mips/sibyte/common/cfe_console.c
> @@ -22,8 +22,6 @@ static void cfe_console_write(struct con
>  		if (str[i] == '\n') {
>  			do {
>  				written = cfe_write(cfe_cons_handle, &str[last], i-last);
> -				if (written < 0)
> -					;
>  				last += written;
>  			} while (last < i);
>  			while (cfe_write(cfe_cons_handle, "\r", 1) <= 0)

 The author indeed clearly was undecided as to what to do as the full last 
statement here is actually:

			while (cfe_write(cfe_cons_handle, "\r", 1) <= 0)
				;

potentially looping indefinitely.

 The CFE API clearly says:

Error codes:
      Code              Description
      CFE_ERR_INV_PARAM File handle is invalid
      others            Device may return device-specific error codes

and maybe CFE never actually fails for a console device write (I'd have to 
check the sources if there are any "others" for the console device and I'd 
assume the console file handle is always valid), but IMO the safe approach 
would be just to chicken out and silently return on a failure from any of 
these calls.  Also this code has been oddly written IMO and would benefit 
from some refactoring.  I'll see if I can queue a patch.

  Maciej

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

end of thread, other threads:[~2024-05-14 23:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-24 22:28 sibyte: pointless if tests Joe Perches
2024-02-28 11:52 ` Philippe Mathieu-Daudé
2024-05-14 23:49 ` Maciej W. Rozycki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®