Skip to contentSkip to conversation

fixing warning "else is not generally useful after a break or return"

DISCUSSION Dafna Hirschfeld 3 participants 3 messages Feb 17, 2018

lore
Share & tools
lore
#0 lore raw

Hi,
I see this warning "else is not generally useful after a break or return":

#532: FILE: drivers/staging/vt6655/rxtx.c:532:
+ return buf->duration_a;
+ } else {

So the standard is to remove the "else" line when it is not necessary ?

In the function s_uFillDataHead
<https://elixir.bootlin.com/linux/v3.4/source/drivers/staging/vt6655/rxtx.c#L712> there are more "else" statements that are redundant, for example this
<https://elixir.bootlin.com/linux/v3.4/source/drivers/staging/vt6655/rxtx.c#L786> one since the "if" it relates to always returns.

So all redundant "else / else if" should be removed ?

Thanks,
Dafna

#1 lore raw
Quoted 7 lines · Dafna Hirschfeld

Hi,
I see this warning "else is not generally useful after a break or return":

#532: FILE: drivers/staging/vt6655/rxtx.c:532:
+                       return buf->duration_a;
+               } else {

Quoted 7 lines

So the standard is to remove the "else" line when it is not necessary ?

In the function s_uFillDataHead there are more "else" statements that are redundant, for example this one since the "if" it relates to always returns.

So all redundant "else / else if" should be removed ?

Not sure. Because in these cases the branches are declaring local variables. And the then and else branches seem kind of parallel. So it is probably better to leave them as they are.

julia

Quoted 15 lines

Thanks,
Dafna

--
You received this message because you are subscribed to the Google Groups
"outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visithttps://groups.google.com/d/msgid/outreachy-kernel/f8e55043-fbe6-4046-baee- c3ca4e8d3c8e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

#2 lore raw
In reply to Dafna Hirschfeld
Quoted 7 lines · Dafna Hirschfeld

Hi,
I see this warning "else is not generally useful after a break or return":

#532: FILE: drivers/staging/vt6655/rxtx.c:532:

(quoted diff) +2 -0
+                       return buf->duration_a;
+               } else {
Quoted 5 lines

So the standard is to remove the "else" line when it is not necessary ?

In the function s_uFillDataHead
<https://elixir.bootlin.com/linux/v3.4/source/drivers/staging/vt6655/rxtx.c#L712> there are more "else" statements that are redundant, for example this

Note, the v3.4 kernel is _very_ old (it was released back in May of 2012). Please look at the most recent kernel source tree.

That being said, yes, removing the else line after a return statement is a good thing to do.

thanks,

greg k-h