public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Johannes Czekay <johannes.czekay@fau.de>
Cc: gregkh@linuxfoundation.org, devel@driverdev.osuosl.org,
	jbwyatt4@gmail.com, gustavo@embeddedor.com,
	linux-kernel@i4.cs.fau.de, linux-kernel@vger.kernel.org,
	rkovhaev@gmail.com, nicolai.fischer@fau.de, hqjagain@gmail.com
Subject: Re: [PATCH 6/6] wlan-ng: clean up reused macros
Date: Tue, 19 Jan 2021 12:33:56 +0300	[thread overview]
Message-ID: <20210119093356.GL2696@kadam> (raw)
In-Reply-To: <20210118010955.48663-7-johannes.czekay@fau.de>

On Mon, Jan 18, 2021 at 02:09:56AM +0100, Johannes Czekay wrote:
> This patch cleans up two "macro argument reuse" warnings by checkpatch.
> This should also make the code much more readable.
> 
> Signed-off-by: Johannes Czekay <johannes.czekay@fau.de>
> Co-developed-by: Nicolai Fischer <nicolai.fischer@fau.de>
> Signed-off-by: Nicolai Fischer <nicolai.fischer@fau.de>
> ---
>  drivers/staging/wlan-ng/p80211metastruct.h | 18 +-------
>  drivers/staging/wlan-ng/prism2mgmt.c       | 48 ++++++----------------
>  2 files changed, 14 insertions(+), 52 deletions(-)
> 
> diff --git a/drivers/staging/wlan-ng/p80211metastruct.h b/drivers/staging/wlan-ng/p80211metastruct.h
> index 4adc64580185..e963227f797c 100644
> --- a/drivers/staging/wlan-ng/p80211metastruct.h
> +++ b/drivers/staging/wlan-ng/p80211metastruct.h
> @@ -114,22 +114,8 @@ struct p80211msg_dot11req_scan_results {
>  	struct p80211item_uint32 cfpollreq;
>  	struct p80211item_uint32 privacy;
>  	struct p80211item_uint32 capinfo;
> -	struct p80211item_uint32 basicrate1;
> -	struct p80211item_uint32 basicrate2;
> -	struct p80211item_uint32 basicrate3;
> -	struct p80211item_uint32 basicrate4;
> -	struct p80211item_uint32 basicrate5;
> -	struct p80211item_uint32 basicrate6;
> -	struct p80211item_uint32 basicrate7;
> -	struct p80211item_uint32 basicrate8;
> -	struct p80211item_uint32 supprate1;
> -	struct p80211item_uint32 supprate2;
> -	struct p80211item_uint32 supprate3;
> -	struct p80211item_uint32 supprate4;
> -	struct p80211item_uint32 supprate5;
> -	struct p80211item_uint32 supprate6;
> -	struct p80211item_uint32 supprate7;
> -	struct p80211item_uint32 supprate8;
> +	struct p80211item_uint32 basicrate[8];
> +	struct p80211item_uint32 supprate[8];
>  } __packed;
>  
>  struct p80211msg_dot11req_start {
> diff --git a/drivers/staging/wlan-ng/prism2mgmt.c b/drivers/staging/wlan-ng/prism2mgmt.c
> index 1bd36dc2b7ff..8540c3336907 100644
> --- a/drivers/staging/wlan-ng/prism2mgmt.c
> +++ b/drivers/staging/wlan-ng/prism2mgmt.c
> @@ -388,6 +388,7 @@ int prism2mgmt_scan_results(struct wlandevice *wlandev, void *msgp)
>  	struct hfa384x_hscan_result_sub *item = NULL;
>  
>  	int count;
> +	int i;
>  
>  	req = msgp;
>  
> @@ -437,42 +438,17 @@ int prism2mgmt_scan_results(struct wlandevice *wlandev, void *msgp)
>  		if (item->supprates[count] == 0)
>  			break;
>  
> -#define REQBASICRATE(N) \
> -	do { \
> -		if ((count >= (N)) && DOT11_RATE5_ISBASIC_GET(	\
> -			item->supprates[(N) - 1])) { \
> -			req->basicrate ## N .data = item->supprates[(N) - 1]; \
> -			req->basicrate ## N .status = \
> -				P80211ENUM_msgitem_status_data_ok; \
> -		} \
> -	} while (0)
> -
> -	REQBASICRATE(1);
> -	REQBASICRATE(2);
> -	REQBASICRATE(3);
> -	REQBASICRATE(4);
> -	REQBASICRATE(5);
> -	REQBASICRATE(6);
> -	REQBASICRATE(7);
> -	REQBASICRATE(8);
> -
> -#define REQSUPPRATE(N) \
> -	do { \
> -		if (count >= (N)) {					\
> -			req->supprate ## N .data = item->supprates[(N) - 1]; \
> -			req->supprate ## N .status = \
> -				P80211ENUM_msgitem_status_data_ok; \
> -		} \
> -	} while (0)
> -
> -	REQSUPPRATE(1);
> -	REQSUPPRATE(2);
> -	REQSUPPRATE(3);
> -	REQSUPPRATE(4);
> -	REQSUPPRATE(5);
> -	REQSUPPRATE(6);
> -	REQSUPPRATE(7);
> -	REQSUPPRATE(8);
> +	for (i = 0; i < 8; i++) {
> +		if (count > 1) {

This should be "i" instead of "1".  And conditions are more readable if
you put the part that changes first "if (variable < limit)" to avoid
backwards think.

	if (i < count) {

Or you could reverse it the other way:

	if (i >= count)
		break;

> +			if (DOT11_RATE5_ISBASIC_GET(item->supprates[i])) {
> +				req->basicrate[i].data = item->supprates[i];
> +				req->basicrate[i].status = P80211ENUM_msgitem_status_data_ok;
> +			}
> +
> +			req->supprate[i].data = item->supprates[i];
> +			req->supprate[i].status = P80211ENUM_msgitem_status_data_ok;
> +		}
> +	}

It's sort of surprising that we can change how we write this information
but we don't have to change how it is read.  I guess presumably it's
just dumped as hex to debugfs or something like that...  Who knows.  :/

regards,
dan carpenter


  reply	other threads:[~2021-01-19  9:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-18  1:09 [PATCH 0/6] wlan-ng: checkpatch.pl cleanup series Johannes Czekay
2021-01-18  1:09 ` [PATCH 1/6] wlan-ng: clean up line ending Johannes Czekay
2021-01-27 13:58   ` Greg KH
2021-01-18  1:09 ` [PATCH 2/6] wlan-ng: clean up spinlock_t definition Johannes Czekay
2021-01-18  1:09 ` [PATCH 3/6] wlan-ng: rename macros Johannes Czekay
2021-01-18  1:09 ` [PATCH 4/6] wlan-ng: clean up line length Johannes Czekay
2021-01-18  1:09 ` [PATCH 5/6] wlan-ng: clean up alignment Johannes Czekay
2021-01-18  1:09 ` [PATCH 6/6] wlan-ng: clean up reused macros Johannes Czekay
2021-01-19  9:33   ` Dan Carpenter [this message]
  -- strict thread matches above, loose matches on Subject: below --
2020-12-22 22:20 [PATCH 0/6] wlan-ng: checkpatch.pl cleanup series Johannes Czekay
2020-12-22 22:20 ` [PATCH 6/6] wlan-ng: clean up reused macros Johannes Czekay

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=20210119093356.GL2696@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=gustavo@embeddedor.com \
    --cc=hqjagain@gmail.com \
    --cc=jbwyatt4@gmail.com \
    --cc=johannes.czekay@fau.de \
    --cc=linux-kernel@i4.cs.fau.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nicolai.fischer@fau.de \
    --cc=rkovhaev@gmail.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox