All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Dan Carpenter <dan.carpenter@oracle.com>,
	Sohom Datta <sohom.datta@learner.manipal.edu>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org,
	Larry Finger <Larry.Finger@lwfinger.net>
Subject: Re: [RESEND PATCH] staging: rtl8188eu: Fix else after return WARNING (checkpatch)
Date: Mon, 14 Sep 2020 09:42:49 -0700	[thread overview]
Message-ID: <8c95d3d02dbdd36a048280cb8d9e8f171c3b4959.camel@perches.com> (raw)
In-Reply-To: <20200914145755.GD4282@kadam>

On Mon, 2020-09-14 at 17:57 +0300, Dan Carpenter wrote:
> On Sun, Sep 13, 2020 at 12:19:50PM +0530, Sohom Datta wrote:
> > > From 4c8c8f3ff7f4d711daea4ac3bb987fcecc7ef1ed Mon Sep 17 00:00:00 2001
> > From: Sohom <sohom.datta@learner.manipal.edu>
> > Date: Sat, 12 Sep 2020 18:04:56 +0530
> > Subject: [RESEND PATCH] staging: rtl8188eu: Fix else after return WARNING
> >  (checkpatch)
> > 
> > Fixed:
> > WARNING: else is not generally useful after a break or return
> > 1636: FILE: ./rtw_recv.c:1636:
> > +           return false;
> > +       else
> > 
> > Separated the return statement into a separate block since
> > it doesn't seem to depend on the SN_LESS explicity being false.
> > 
> > Signed-off-by: Sohom <sohom.datta@learner.manipal.edu>
> > ---
> >  drivers/staging/rtl8188eu/core/rtw_recv.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/staging/rtl8188eu/core/rtw_recv.c b/drivers/staging/rtl8188eu/core/rtw_recv.c
> > index 5fe7a0458dd2..5e81134ffb6d 100644
> > --- a/drivers/staging/rtl8188eu/core/rtw_recv.c
> > +++ b/drivers/staging/rtl8188eu/core/rtw_recv.c
> > @@ -1629,10 +1629,11 @@ static int enqueue_reorder_recvframe(struct recv_reorder_ctrl *preorder_ctrl,
> >  		hdr = list_entry(plist, struct recv_frame, list);
> >  		pnextattrib = &hdr->attrib;
> >  
> > +		if (SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num))
> > +			return false;
> > +
> >  		if (SN_LESS(pnextattrib->seq_num, pattrib->seq_num))
> >  			plist = plist->next;
> > -		else if (SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num))
> > -			return false;
> >  		else
> >  			break;
> >  	}
> 
> Checkpatch is just wrong here.  Ignore it when it's wrong.

It's not "wrong" here.  It's making a suggestion.

Perhaps read the SN_EQUAL and SN_LESS macros.

a and b are both u16's here.

drivers/staging/rtl8188eu/include/rtw_recv.h:#define SN_LESS(a, b)              (((a - b) & 0x800) != 0)
drivers/staging/rtl8188eu/include/rtw_recv.h:#define SN_EQUAL(a, b)     (a == b)

Reordering works, perhaps it's just a question of
whether it's the most likely result of the test.

This is in a while loop.

If the expected test is really the most likely that
SN_LESS is true, then perhaps this loop could be
something like:

		if (SN_LESS(pnextattrib->seq_num, pattrib->seq_num)) {
			plist = plist->next;
			continue;
		}
		if (SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num))
			return false;
		break;
	}

The real question is whether or not that's more readable.



WARNING: multiple messages have this Message-ID (diff)
From: Joe Perches <joe@perches.com>
To: Dan Carpenter <dan.carpenter@oracle.com>,
	Sohom Datta <sohom.datta@learner.manipal.edu>
Cc: devel@driverdev.osuosl.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-kernel@vger.kernel.org,
	Larry Finger <Larry.Finger@lwfinger.net>
Subject: Re: [RESEND PATCH] staging: rtl8188eu: Fix else after return WARNING (checkpatch)
Date: Mon, 14 Sep 2020 09:42:49 -0700	[thread overview]
Message-ID: <8c95d3d02dbdd36a048280cb8d9e8f171c3b4959.camel@perches.com> (raw)
In-Reply-To: <20200914145755.GD4282@kadam>

On Mon, 2020-09-14 at 17:57 +0300, Dan Carpenter wrote:
> On Sun, Sep 13, 2020 at 12:19:50PM +0530, Sohom Datta wrote:
> > > From 4c8c8f3ff7f4d711daea4ac3bb987fcecc7ef1ed Mon Sep 17 00:00:00 2001
> > From: Sohom <sohom.datta@learner.manipal.edu>
> > Date: Sat, 12 Sep 2020 18:04:56 +0530
> > Subject: [RESEND PATCH] staging: rtl8188eu: Fix else after return WARNING
> >  (checkpatch)
> > 
> > Fixed:
> > WARNING: else is not generally useful after a break or return
> > 1636: FILE: ./rtw_recv.c:1636:
> > +           return false;
> > +       else
> > 
> > Separated the return statement into a separate block since
> > it doesn't seem to depend on the SN_LESS explicity being false.
> > 
> > Signed-off-by: Sohom <sohom.datta@learner.manipal.edu>
> > ---
> >  drivers/staging/rtl8188eu/core/rtw_recv.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/staging/rtl8188eu/core/rtw_recv.c b/drivers/staging/rtl8188eu/core/rtw_recv.c
> > index 5fe7a0458dd2..5e81134ffb6d 100644
> > --- a/drivers/staging/rtl8188eu/core/rtw_recv.c
> > +++ b/drivers/staging/rtl8188eu/core/rtw_recv.c
> > @@ -1629,10 +1629,11 @@ static int enqueue_reorder_recvframe(struct recv_reorder_ctrl *preorder_ctrl,
> >  		hdr = list_entry(plist, struct recv_frame, list);
> >  		pnextattrib = &hdr->attrib;
> >  
> > +		if (SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num))
> > +			return false;
> > +
> >  		if (SN_LESS(pnextattrib->seq_num, pattrib->seq_num))
> >  			plist = plist->next;
> > -		else if (SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num))
> > -			return false;
> >  		else
> >  			break;
> >  	}
> 
> Checkpatch is just wrong here.  Ignore it when it's wrong.

It's not "wrong" here.  It's making a suggestion.

Perhaps read the SN_EQUAL and SN_LESS macros.

a and b are both u16's here.

drivers/staging/rtl8188eu/include/rtw_recv.h:#define SN_LESS(a, b)              (((a - b) & 0x800) != 0)
drivers/staging/rtl8188eu/include/rtw_recv.h:#define SN_EQUAL(a, b)     (a == b)

Reordering works, perhaps it's just a question of
whether it's the most likely result of the test.

This is in a while loop.

If the expected test is really the most likely that
SN_LESS is true, then perhaps this loop could be
something like:

		if (SN_LESS(pnextattrib->seq_num, pattrib->seq_num)) {
			plist = plist->next;
			continue;
		}
		if (SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num))
			return false;
		break;
	}

The real question is whether or not that's more readable.


_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

  reply	other threads:[~2020-09-14 16:43 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-13  6:49 [RESEND PATCH] staging: rtl8188eu: Fix else after return WARNING (checkpatch) Sohom Datta
2020-09-13  6:49 ` Sohom Datta
2020-09-13  6:52 ` Greg Kroah-Hartman
2020-09-13  6:52   ` Greg Kroah-Hartman
2020-09-14 14:57 ` Dan Carpenter
2020-09-14 14:57   ` Dan Carpenter
2020-09-14 16:42   ` Joe Perches [this message]
2020-09-14 16:42     ` Joe Perches
2020-09-15 11:20     ` Dan Carpenter
2020-09-15 11:20       ` Dan Carpenter
2020-09-15 15:25       ` Joe Perches
2020-09-15 15:25         ` Joe Perches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8c95d3d02dbdd36a048280cb8d9e8f171c3b4959.camel@perches.com \
    --to=joe@perches.com \
    --cc=Larry.Finger@lwfinger.net \
    --cc=dan.carpenter@oracle.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sohom.datta@learner.manipal.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.