public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/2] staging: speakup: else is not useful after a return
@ 2015-06-25 12:56 Luis de Bethencourt
  2015-07-15  3:01 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 2+ messages in thread
From: Luis de Bethencourt @ 2015-06-25 12:56 UTC (permalink / raw)
  To: linux-kernel
  Cc: Dan Carpenter, Greg Kroah-Hartman, William Hubbs, Chris Brannon,
	Kirk Reiser, Samuel Thibault, Domagoj Trsan, speakup, devel

Correct a checkpatch.pl warning regarding
WARNING: else is not generally useful after a break or return
drivers/staging/speakup/keyhelp.c:185:

Changing the order of the if blocks, but not the logic, to avoid this
warning. The block after else will run if the blocks KT_CUR or KT_LATIN
set cur_item instead of returning.

Signed-off-by: Luis de Bethencourt <luis@debethencourt.com>
---
 drivers/staging/speakup/keyhelp.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/drivers/staging/speakup/keyhelp.c b/drivers/staging/speakup/keyhelp.c
index 02d5c70..8133b6e 100644
--- a/drivers/staging/speakup/keyhelp.c
+++ b/drivers/staging/speakup/keyhelp.c
@@ -151,22 +151,7 @@ int spk_handle_help(struct vc_data *vc, u_char type, u_char ch, u_short key)
 
 	if (letter_offsets[0] == -1)
 		help_init();
-	if (type == KT_LATIN) {
-		if (ch == SPACE) {
-			spk_special_handler = NULL;
-			synth_printf("%s\n", spk_msg_get(MSG_LEAVING_HELP));
-			return 1;
-		}
-		ch |= 32; /* lower case */
-		if (ch < 'a' || ch > 'z')
-			return -1;
-		if (letter_offsets[ch-'a'] == -1) {
-			synth_printf(spk_msg_get(MSG_NO_COMMAND), ch);
-			synth_printf("\n");
-			return 1;
-		}
-		cur_item = letter_offsets[ch-'a'];
-	} else if (type == KT_CUR) {
+	if (type == KT_CUR) {
 		if (ch == 0
 		    && (MSG_FUNCNAMES_START + cur_item + 1) <=
 		    MSG_FUNCNAMES_END)
@@ -182,6 +167,21 @@ int spk_handle_help(struct vc_data *vc, u_char type, u_char ch, u_short key)
 		synth_printf("%s\n", spk_msg_get(MSG_HELP_INFO));
 		build_key_data(); /* rebuild each time in case new mapping */
 		return 1;
+	} else if (type == KT_LATIN) {
+		if (ch == SPACE) {
+			spk_special_handler = NULL;
+			synth_printf("%s\n", spk_msg_get(MSG_LEAVING_HELP));
+			return 1;
+		}
+		ch |= 32; /* lower case */
+		if (ch < 'a' || ch > 'z')
+			return -1;
+		if (letter_offsets[ch-'a'] == -1) {
+			synth_printf(spk_msg_get(MSG_NO_COMMAND), ch);
+			synth_printf("\n");
+			return 1;
+		}
+		cur_item = letter_offsets[ch-'a'];
 	} else {
 		name = NULL;
 		if ((type != KT_SPKUP) && (key > 0) && (key <= num_key_names)) {
-- 
2.1.4


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

* Re: [PATCH 2/2] staging: speakup: else is not useful after a return
  2015-06-25 12:56 [PATCH 2/2] staging: speakup: else is not useful after a return Luis de Bethencourt
@ 2015-07-15  3:01 ` Greg Kroah-Hartman
  0 siblings, 0 replies; 2+ messages in thread
From: Greg Kroah-Hartman @ 2015-07-15  3:01 UTC (permalink / raw)
  To: Luis de Bethencourt
  Cc: linux-kernel, devel, Kirk Reiser, speakup, Domagoj Trsan,
	Samuel Thibault, Dan Carpenter, Chris Brannon

On Thu, Jun 25, 2015 at 02:56:52PM +0200, Luis de Bethencourt wrote:
> Correct a checkpatch.pl warning regarding
> WARNING: else is not generally useful after a break or return
> drivers/staging/speakup/keyhelp.c:185:
> 
> Changing the order of the if blocks, but not the logic, to avoid this
> warning. The block after else will run if the blocks KT_CUR or KT_LATIN
> set cur_item instead of returning.

Don't do things just because checkpatch tells you, especially when it
doesn't make much sense to do so.

For example, this patch :)

> 
> Signed-off-by: Luis de Bethencourt <luis@debethencourt.com>
> ---
>  drivers/staging/speakup/keyhelp.c | 32 ++++++++++++++++----------------
>  1 file changed, 16 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/staging/speakup/keyhelp.c b/drivers/staging/speakup/keyhelp.c
> index 02d5c70..8133b6e 100644
> --- a/drivers/staging/speakup/keyhelp.c
> +++ b/drivers/staging/speakup/keyhelp.c
> @@ -151,22 +151,7 @@ int spk_handle_help(struct vc_data *vc, u_char type, u_char ch, u_short key)
>  
>  	if (letter_offsets[0] == -1)
>  		help_init();
> -	if (type == KT_LATIN) {
> -		if (ch == SPACE) {
> -			spk_special_handler = NULL;
> -			synth_printf("%s\n", spk_msg_get(MSG_LEAVING_HELP));
> -			return 1;
> -		}
> -		ch |= 32; /* lower case */
> -		if (ch < 'a' || ch > 'z')
> -			return -1;
> -		if (letter_offsets[ch-'a'] == -1) {
> -			synth_printf(spk_msg_get(MSG_NO_COMMAND), ch);
> -			synth_printf("\n");
> -			return 1;
> -		}
> -		cur_item = letter_offsets[ch-'a'];
> -	} else if (type == KT_CUR) {
> +	if (type == KT_CUR) {
>  		if (ch == 0
>  		    && (MSG_FUNCNAMES_START + cur_item + 1) <=
>  		    MSG_FUNCNAMES_END)
> @@ -182,6 +167,21 @@ int spk_handle_help(struct vc_data *vc, u_char type, u_char ch, u_short key)
>  		synth_printf("%s\n", spk_msg_get(MSG_HELP_INFO));
>  		build_key_data(); /* rebuild each time in case new mapping */
>  		return 1;
> +	} else if (type == KT_LATIN) {

One thing, this else isn't needed.

Or switch this to a case statement instead?  That might make it more
obvious as to what is going on, try that and see if it looks better.

thanks,

greg k-h

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

end of thread, other threads:[~2015-07-15  3:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-25 12:56 [PATCH 2/2] staging: speakup: else is not useful after a return Luis de Bethencourt
2015-07-15  3:01 ` Greg Kroah-Hartman

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