linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] staging: r8188eu: remove else after return and break statements
@ 2022-04-13  5:27 Mahak Gupta
  2022-04-13  8:52 ` Pavel Skripkin
  2022-04-13 16:51 ` Larry Finger
  0 siblings, 2 replies; 5+ messages in thread
From: Mahak Gupta @ 2022-04-13  5:27 UTC (permalink / raw)
  To: Larry.Finger, phil, gregkh, linux-staging, linux-kernel, outreachy
  Cc: Mahak Gupta

Else is not necessary after return and break statements, hence remove
it.

Reported by checkpatch:

WARNING: else is not generally useful after a break or return

Signed-off-by: Mahak Gupta <mahak_g@cs.iitr.ac.in>
---
 drivers/staging/r8188eu/core/rtw_ieee80211.c | 41 ++++++++------------
 1 file changed, 17 insertions(+), 24 deletions(-)

diff --git a/drivers/staging/r8188eu/core/rtw_ieee80211.c b/drivers/staging/r8188eu/core/rtw_ieee80211.c
index 5a0e42ed4a47..bb4c9bc864da 100644
--- a/drivers/staging/r8188eu/core/rtw_ieee80211.c
+++ b/drivers/staging/r8188eu/core/rtw_ieee80211.c
@@ -97,16 +97,15 @@ bool	rtw_is_cckratesonly_included(u8 *rate)
 
 int rtw_check_network_type(unsigned char *rate, int ratelen, int channel)
 {
-	if (channel > 14) {
+	if (channel > 14)
 		return WIRELESS_INVALID;
-	} else {  /*  could be pure B, pure G, or B/G */
-		if (rtw_is_cckratesonly_included(rate))
-			return WIRELESS_11B;
-		else if (rtw_is_cckrates_included(rate))
-			return	WIRELESS_11BG;
-		else
-			return WIRELESS_11G;
-	}
+	/*  could be pure B, pure G, or B/G */
+	if (rtw_is_cckratesonly_included(rate))
+		return WIRELESS_11B;
+	else if (rtw_is_cckrates_included(rate))
+		return	WIRELESS_11BG;
+	else
+		return WIRELESS_11G;
 }
 
 u8 *rtw_set_fixed_ie(unsigned char *pbuf, unsigned int len, unsigned char *source,
@@ -160,11 +159,10 @@ u8 *rtw_get_ie(u8 *pbuf, int index, int *len, int limit)
 		if (*p == index) {
 			*len = *(p + 1);
 			return p;
-		} else {
-			tmp = *(p + 1);
-			p += (tmp + 2);
-			i += (tmp + 2);
 		}
+		tmp = *(p + 1);
+		p += (tmp + 2);
+		i += (tmp + 2);
 		if (i >= limit)
 			break;
 	}
@@ -295,10 +293,9 @@ unsigned char *rtw_get_wpa_ie(unsigned char *pie, int *wpa_ie_len, int limit)
 				goto check_next_ie;
 			*wpa_ie_len = *(pbuf + 1);
 			return pbuf;
-		} else {
-			*wpa_ie_len = 0;
-			return NULL;
 		}
+		*wpa_ie_len = 0;
+		return NULL;
 
 check_next_ie:
 		limit_new = limit - (pbuf - pie) - 2 - len;
@@ -558,9 +555,8 @@ u8 *rtw_get_wps_ie(u8 *in_ie, uint in_len, u8 *wps_ie, uint *wps_ielen)
 			cnt += in_ie[cnt + 1] + 2;
 
 			break;
-		} else {
-			cnt += in_ie[cnt + 1] + 2; /* goto next */
 		}
+		cnt += in_ie[cnt + 1] + 2; /* goto next */
 	}
 	return wpsie_ptr;
 }
@@ -604,9 +600,8 @@ u8 *rtw_get_wps_attr(u8 *wps_ie, uint wps_ielen, u16 target_attr_id, u8 *buf_att
 			if (len_attr)
 				*len_attr = attr_len;
 			break;
-		} else {
-			attr_ptr += attr_len; /* goto next */
 		}
+		attr_ptr += attr_len; /* goto next */
 	}
 	return target_attr_ptr;
 }
@@ -901,9 +896,8 @@ u8 *rtw_get_p2p_ie(u8 *in_ie, int in_len, u8 *p2p_ie, uint *p2p_ielen)
 			if (p2p_ielen)
 				*p2p_ielen = in_ie[cnt + 1] + 2;
 			return p2p_ie_ptr;
-		} else {
-			cnt += in_ie[cnt + 1] + 2; /* goto next */
 		}
+		cnt += in_ie[cnt + 1] + 2; /* goto next */
 	}
 	return NULL;
 }
@@ -948,9 +942,8 @@ u8 *rtw_get_p2p_attr(u8 *p2p_ie, uint p2p_ielen, u8 target_attr_id, u8 *buf_attr
 			if (len_attr)
 				*len_attr = attr_len;
 			break;
-		} else {
-			attr_ptr += attr_len; /* goto next */
 		}
+		attr_ptr += attr_len; /* goto next */
 	}
 	return target_attr_ptr;
 }
-- 
2.17.1


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

* Re: [PATCH] staging: r8188eu: remove else after return and break statements
  2022-04-13  5:27 [PATCH] staging: r8188eu: remove else after return and break statements Mahak Gupta
@ 2022-04-13  8:52 ` Pavel Skripkin
  2022-04-13  9:02   ` Julia Lawall
  2022-04-13 16:51 ` Larry Finger
  1 sibling, 1 reply; 5+ messages in thread
From: Pavel Skripkin @ 2022-04-13  8:52 UTC (permalink / raw)
  To: Mahak Gupta, Larry.Finger, phil, gregkh, linux-staging,
	linux-kernel, outreachy

Hi Mahak,

On 4/13/22 08:27, Mahak Gupta wrote:
> Else is not necessary after return and break statements, hence remove
> it.
> 
> Reported by checkpatch:
> 
> WARNING: else is not generally useful after a break or return
> 
> Signed-off-by: Mahak Gupta <mahak_g@cs.iitr.ac.in>

[snip]

> -	}
> +	/*  could be pure B, pure G, or B/G */
> +	if (rtw_is_cckratesonly_included(rate))
> +		return WIRELESS_11B;
> +	else if (rtw_is_cckrates_included(rate))
> +		return	WIRELESS_11BG;
> +	else
> +		return WIRELESS_11G;

This 'else' is after 'return' as well, isn't it? Just wondering what's 
the difference between this one and others in this patch




With regards,
Pavel Skripkin

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

* Re: [PATCH] staging: r8188eu: remove else after return and break statements
  2022-04-13  8:52 ` Pavel Skripkin
@ 2022-04-13  9:02   ` Julia Lawall
  0 siblings, 0 replies; 5+ messages in thread
From: Julia Lawall @ 2022-04-13  9:02 UTC (permalink / raw)
  To: Pavel Skripkin
  Cc: Mahak Gupta, Larry.Finger, phil, gregkh, linux-staging,
	linux-kernel, outreachy



On Wed, 13 Apr 2022, Pavel Skripkin wrote:

> Hi Mahak,
>
> On 4/13/22 08:27, Mahak Gupta wrote:
> > Else is not necessary after return and break statements, hence remove
> > it.
> >
> > Reported by checkpatch:
> >
> > WARNING: else is not generally useful after a break or return
> >
> > Signed-off-by: Mahak Gupta <mahak_g@cs.iitr.ac.in>
>
> [snip]
>
> > -	}
> > +	/*  could be pure B, pure G, or B/G */
> > +	if (rtw_is_cckratesonly_included(rate))
> > +		return WIRELESS_11B;
> > +	else if (rtw_is_cckrates_included(rate))
> > +		return	WIRELESS_11BG;
> > +	else
> > +		return WIRELESS_11G;
>
> This 'else' is after 'return' as well, isn't it? Just wondering what's the
> difference between this one and others in this patch

Maybe it's nice to have the three options lined up?

julia

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

* Re: [PATCH] staging: r8188eu: remove else after return and break statements
  2022-04-13  5:27 [PATCH] staging: r8188eu: remove else after return and break statements Mahak Gupta
  2022-04-13  8:52 ` Pavel Skripkin
@ 2022-04-13 16:51 ` Larry Finger
  2022-04-14 22:01   ` MAHAK GUPTA
  1 sibling, 1 reply; 5+ messages in thread
From: Larry Finger @ 2022-04-13 16:51 UTC (permalink / raw)
  To: Mahak Gupta, phil, gregkh, linux-staging, linux-kernel, outreachy

On 4/13/22 00:27, Mahak Gupta wrote:
> Else is not necessary after return and break statements, hence remove
> it.
> 
> Reported by checkpatch:
> 
> WARNING: else is not generally useful after a break or return
> 
> Signed-off-by: Mahak Gupta <mahak_g@cs.iitr.ac.in>

The commit message is redundant. I would suggest the following:

checkpatch reports the following:

WARNING: else is not generally useful after a break or return

Remove those cases.


> ---
>   drivers/staging/r8188eu/core/rtw_ieee80211.c | 41 ++++++++------------
>   1 file changed, 17 insertions(+), 24 deletions(-)
> 
> diff --git a/drivers/staging/r8188eu/core/rtw_ieee80211.c b/drivers/staging/r8188eu/core/rtw_ieee80211.c
> index 5a0e42ed4a47..bb4c9bc864da 100644
> --- a/drivers/staging/r8188eu/core/rtw_ieee80211.c
> +++ b/drivers/staging/r8188eu/core/rtw_ieee80211.c
> @@ -97,16 +97,15 @@ bool	rtw_is_cckratesonly_included(u8 *rate)
>   
>   int rtw_check_network_type(unsigned char *rate, int ratelen, int channel)
>   {
> -	if (channel > 14) {
> +	if (channel > 14)
>   		return WIRELESS_INVALID;
> -	} else {  /*  could be pure B, pure G, or B/G */
> -		if (rtw_is_cckratesonly_included(rate))
> -			return WIRELESS_11B;
> -		else if (rtw_is_cckrates_included(rate))
> -			return	WIRELESS_11BG;
> -		else
> -			return WIRELESS_11G;
> -	}
> +	/*  could be pure B, pure G, or B/G */
> +	if (rtw_is_cckratesonly_included(rate))
> +		return WIRELESS_11B;
> +	else if (rtw_is_cckrates_included(rate))
> +		return	WIRELESS_11BG;
> +	else
> +		return WIRELESS_11G;

Is this 'else' necessary?


Larry

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

* Re: [PATCH] staging: r8188eu: remove else after return and break statements
  2022-04-13 16:51 ` Larry Finger
@ 2022-04-14 22:01   ` MAHAK GUPTA
  0 siblings, 0 replies; 5+ messages in thread
From: MAHAK GUPTA @ 2022-04-14 22:01 UTC (permalink / raw)
  To: Larry Finger
  Cc: Phillip Potter, gregkh, linux-staging, linux-kernel, outreachy

Hi Larry and Pavel,
On Wed, Apr 13, 2022 at 10:21 PM Larry Finger <Larry.Finger@lwfinger.net> wrote:
>
> On 4/13/22 00:27, Mahak Gupta wrote:
> > Else is not necessary after return and break statements, hence remove
> > it.
> >
> > Reported by checkpatch:
> >
> > WARNING: else is not generally useful after a break or return
> >
> > Signed-off-by: Mahak Gupta <mahak_g@cs.iitr.ac.in>
>
> The commit message is redundant. I would suggest the following:
>
> checkpatch reports the following:
>
> WARNING: else is not generally useful after a break or return
>
> Remove those cases.
This patch is merged by Greg now but I'll keep this in mind for next
patches. Thanks

>
>
> > ---
> >   drivers/staging/r8188eu/core/rtw_ieee80211.c | 41 ++++++++------------
> >   1 file changed, 17 insertions(+), 24 deletions(-)
> >
> > diff --git a/drivers/staging/r8188eu/core/rtw_ieee80211.c b/drivers/staging/r8188eu/core/rtw_ieee80211.c
> > index 5a0e42ed4a47..bb4c9bc864da 100644
> > --- a/drivers/staging/r8188eu/core/rtw_ieee80211.c
> > +++ b/drivers/staging/r8188eu/core/rtw_ieee80211.c
> > @@ -97,16 +97,15 @@ bool      rtw_is_cckratesonly_included(u8 *rate)
> >
> >   int rtw_check_network_type(unsigned char *rate, int ratelen, int channel)
> >   {
> > -     if (channel > 14) {
> > +     if (channel > 14)
> >               return WIRELESS_INVALID;
> > -     } else {  /*  could be pure B, pure G, or B/G */
> > -             if (rtw_is_cckratesonly_included(rate))
> > -                     return WIRELESS_11B;
> > -             else if (rtw_is_cckrates_included(rate))
> > -                     return  WIRELESS_11BG;
> > -             else
> > -                     return WIRELESS_11G;
> > -     }
> > +     /*  could be pure B, pure G, or B/G */
> > +     if (rtw_is_cckratesonly_included(rate))
> > +             return WIRELESS_11B;
> > +     else if (rtw_is_cckrates_included(rate))
> > +             return  WIRELESS_11BG;
> > +     else
> > +             return WIRELESS_11G;
>
> Is this 'else' necessary?
Yeah, we can remove this else too, sorry didn't notice it. Should I
submit another patch removing this?

>
>
> Larry

Mahak

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

end of thread, other threads:[~2022-04-14 22:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-13  5:27 [PATCH] staging: r8188eu: remove else after return and break statements Mahak Gupta
2022-04-13  8:52 ` Pavel Skripkin
2022-04-13  9:02   ` Julia Lawall
2022-04-13 16:51 ` Larry Finger
2022-04-14 22:01   ` MAHAK GUPTA

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