public inbox for linux-staging@lists.linux.dev
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Joash Naidoo <joash.n09@gmail.com>
Cc: larry.finger@lwfinger.net, phil@philpotter.co.uk,
	paskripkin@gmail.com, gregkh@linuxfoundation.org,
	linux-staging@lists.linux.dev
Subject: Re: [PATCH] staging: r8188eu: fix too many leading tabs
Date: Mon, 19 Sep 2022 11:56:14 +0300	[thread overview]
Message-ID: <YygurgpNWf5zqDAQ@kadam> (raw)
In-Reply-To: <20220918050728.3746-1-joash.n09@gmail.com>

On Sun, Sep 18, 2022 at 07:07:28AM +0200, Joash Naidoo wrote:
> Coding style fix. Fix too many leading tabs and line length. Convert
> __constant_htons to htons
> 

Convert the __constant_htons to htons in a separate patch from reversing
the if statements.

> Signed-off-by: Joash Naidoo <joash.n09@gmail.com>
> ---
>  drivers/staging/r8188eu/core/rtw_br_ext.c | 66 ++++++++++++-----------
>  1 file changed, 35 insertions(+), 31 deletions(-)
> 
> diff --git a/drivers/staging/r8188eu/core/rtw_br_ext.c b/drivers/staging/r8188eu/core/rtw_br_ext.c
> index bca20fe5c..8e951fc0e 100644
> --- a/drivers/staging/r8188eu/core/rtw_br_ext.c
> +++ b/drivers/staging/r8188eu/core/rtw_br_ext.c
> @@ -604,37 +604,41 @@ void dhcp_flag_bcast(struct adapter *priv, struct sk_buff *skb)
>  	if (!skb)
>  		return;
>  
> -	if (!priv->ethBrExtInfo.dhcp_bcst_disable) {
> -		__be16 protocol = *((__be16 *)(skb->data + 2 * ETH_ALEN));
> -
> -		if (protocol == __constant_htons(ETH_P_IP)) { /*  IP */
> -			struct iphdr *iph = (struct iphdr *)(skb->data + ETH_HLEN);
> -
> -			if (iph->protocol == IPPROTO_UDP) { /*  UDP */
> -				struct udphdr *udph = (struct udphdr *)((size_t)iph + (iph->ihl << 2));
> -
> -				if ((udph->source == __constant_htons(CLIENT_PORT)) &&
> -				    (udph->dest == __constant_htons(SERVER_PORT))) { /*  DHCP request */
> -					struct dhcpMessage *dhcph =
> -						(struct dhcpMessage *)((size_t)udph + sizeof(struct udphdr));
> -					u32 cookie = be32_to_cpu((__be32)dhcph->cookie);
> -
> -					if (cookie == DHCP_MAGIC) { /*  match magic word */
> -						if (!(dhcph->flags & htons(BROADCAST_FLAG))) {
> -							/*  if not broadcast */
> -							register int sum = 0;
> -
> -							/*  or BROADCAST flag */
> -							dhcph->flags |= htons(BROADCAST_FLAG);
> -							/*  recalculate checksum */
> -							sum = ~(udph->check) & 0xffff;
> -							sum += be16_to_cpu(dhcph->flags);
> -							while (sum >> 16)
> -								sum = (sum & 0xffff) + (sum >> 16);
> -							udph->check = ~sum;
> -						}
> -					}
> -				}
> +	if (priv->ethBrExtInfo.dhcp_bcst_disable)
> +		return;
> +
> +	__be16 protocol = *((__be16 *)(skb->data + 2 * ETH_ALEN));
> +
> +	if (protocol != htons(ETH_P_IP)) /*  IP */
> +		return;
> +
> +	struct iphdr *iph = (struct iphdr *)(skb->data + ETH_HLEN);
> +
> +	if (iph->protocol != IPPROTO_UDP) /*  UDP */
> +		return;
> +
> +	struct udphdr *udph = (struct udphdr *)((size_t)iph + (iph->ihl << 2));
> +
> +	if ((udph->source == htons(CLIENT_PORT)) &&
> +	    (udph->dest == htons(SERVER_PORT))) { /*  DHCP request */

Flip this condition around as well.  The anti-pattern here is "Don't
reverse the last if statement."

	/* DHCP request */
	if ((udph->source != __constant_htons(CLIENT_PORT)) ||
	    (udph->dest != __constant_htons(SERVER_PORT)))
		return;

> +		struct dhcpMessage *dhcph =
> +			(struct dhcpMessage *)((size_t)udph +
> +						   sizeof(struct udphdr));
> +		u32 cookie = be32_to_cpu((__be32)dhcph->cookie);

You'll have to move these declarations up the to start of the function
which is fine.

> +
> +		if (cookie == DHCP_MAGIC) { /*  match magic word */

Flip this as well.

	if (cookie != DHCP_MAGIC)
		return;

regards,
dan carpenter


      parent reply	other threads:[~2022-09-19  8:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-18  5:07 [PATCH] staging: r8188eu: fix too many leading tabs Joash Naidoo
2022-09-18  7:49 ` Philipp Hortmann
2022-09-18 10:11 ` Greg KH
2022-09-19  8:56 ` Dan Carpenter [this message]

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=YygurgpNWf5zqDAQ@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=joash.n09@gmail.com \
    --cc=larry.finger@lwfinger.net \
    --cc=linux-staging@lists.linux.dev \
    --cc=paskripkin@gmail.com \
    --cc=phil@philpotter.co.uk \
    /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