All of lore.kernel.org
 help / color / mirror / Atom feed
From: Julia Lawall <julia.lawall@lip6.fr>
To: Narcisa Ana Maria Vasile <narcisaanamaria12@gmail.com>
Cc: Larry.Finger@lwfinger.net, florian.c.schilhabel@googlemail.com,
	 gregkh@linuxfoundation.org, outreachy-kernel@googlegroups.com
Subject: Re: [Outreachy kernel] [PATCH 1/4] staging: rtl8712: Refactor conditionals in wpa_set_encryption
Date: Fri, 10 Mar 2017 19:21:19 +0100 (CET)	[thread overview]
Message-ID: <alpine.DEB.2.20.1703101920470.3356@hadrien> (raw)
In-Reply-To: <9f0c0614b6cc60771b82e96cd3973b4eca2c0acb.1489161001.git.narcisaanamaria12@gmail.com>



On Fri, 10 Mar 2017, Narcisa Ana Maria Vasile wrote:

> Reduce the indentation level in wpa_set_encryption.
> This was done using the following Cocinelle script:
>
> @disable neg_if@
> expression e,E;
> statement S;
> @@
>
> *if (e)
> S
> else { return -E; }
>
> @disable neg_if@
> expression e,E;
> statement S;
> identifier l;
> @@
>
> *if (e)
> S
> else { rc = -E; goto l; }
>
> Signed-off-by: Narcisa Ana Maria Vasile <narcisaanamaria12@gmail.com>
> ---
>  drivers/staging/rtl8712/rtl871x_ioctl_linux.c | 42 +++++++++++++--------------
>  1 file changed, 20 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
> index 0322795..aff3628 100644
> --- a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
> +++ b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
> @@ -378,14 +378,14 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param,
>  	if (param_len != (u32)((u8 *) param->u.crypt.key - (u8 *)param) +
>  			 param->u.crypt.key_len)
>  		return -EINVAL;
> -	if (is_broadcast_ether_addr(param->sta_addr)) {
> -		if (param->u.crypt.idx >= WEP_KEYS) {
> -			/* for large key indices, set the default (0) */
> -			param->u.crypt.idx = 0;
> -		}
> -	} else {
> +	if (!is_broadcast_ether_addr(param->sta_addr))
>  		return -EINVAL;
> +
> +	if (param->u.crypt.idx >= WEP_KEYS) {
> +		/* for large key indices, set the default (0) */
> +		param->u.crypt.idx = 0;
>  	}
> +
>  	if (strcmp(param->u.crypt.alg, "WEP") == 0) {
>  		netdev_info(dev, "r8712u: %s: crypt.alg = WEP\n", __func__);
>  		padapter->securitypriv.ndisencryptstatus =
> @@ -396,24 +396,22 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param,
>  		wep_key_len = param->u.crypt.key_len;
>  		if (wep_key_idx >= WEP_KEYS)
>  			wep_key_idx = 0;
> -		if (wep_key_len > 0) {
> -			wep_key_len = wep_key_len <= 5 ? 5 : 13;
> -			pwep = kzalloc(sizeof(*pwep), GFP_ATOMIC);
> -			if (!pwep)
> -				return -ENOMEM;
> -			pwep->KeyLength = wep_key_len;
> -			pwep->Length = wep_key_len +
> -				 FIELD_OFFSET(struct NDIS_802_11_WEP,
> -				 KeyMaterial);
> -			if (wep_key_len == 13) {
> -				padapter->securitypriv.PrivacyAlgrthm =
> -					 _WEP104_;
> -				padapter->securitypriv.XGrpPrivacy =
> -					 _WEP104_;
> -			}
> -		} else {
> +		if (wep_key_len <= 0)
>  			return -EINVAL;
> +
> +		wep_key_len = wep_key_len <= 5 ? 5 : 13;
> +		pwep = kzalloc(sizeof(*pwep), GFP_ATOMIC);
> +		if (!pwep)
> +			return -ENOMEM;
> +		pwep->KeyLength = wep_key_len;
> +		pwep->Length = wep_key_len +
> +			 FIELD_OFFSET(struct NDIS_802_11_WEP,
> +			 KeyMaterial);

The layout can be improved here.  At least KeyMaterial can move up one
line.

julia

> +		if (wep_key_len == 13) {
> +			padapter->securitypriv.PrivacyAlgrthm = _WEP104_;
> +			padapter->securitypriv.XGrpPrivacy = _WEP104_;
>  		}
> +
>  		pwep->KeyIndex = wep_key_idx;
>  		pwep->KeyIndex |= 0x80000000;
>  		memcpy(pwep->KeyMaterial, param->u.crypt.key, pwep->KeyLength);
> --
> 1.9.1
>
> --
> 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 outreachy-kernel+unsubscribe@googlegroups.com.
> To post to this group, send email to outreachy-kernel@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/9f0c0614b6cc60771b82e96cd3973b4eca2c0acb.1489161001.git.narcisaanamaria12%40gmail.com.
> For more options, visit https://groups.google.com/d/optout.
>


  reply	other threads:[~2017-03-10 18:21 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-10 15:58 [PATCH 0/4] staging: rtl8712: Refactor conditionals Narcisa Ana Maria Vasile
2017-03-10 15:59 ` [PATCH 1/4] staging: rtl8712: Refactor conditionals in wpa_set_encryption Narcisa Ana Maria Vasile
2017-03-10 18:21   ` Julia Lawall [this message]
2017-03-10 15:59 ` [PATCH 2/4] staging: rtl8712: Refactor conditional in r8711_wx_get_freq Narcisa Ana Maria Vasile
2017-03-10 18:19   ` [Outreachy kernel] " Julia Lawall
2017-03-10 15:59 ` [PATCH 3/4] staging: rtl8712: Refactor conditionals in r8711_wx_get_rate Narcisa Ana Maria Vasile
2017-03-10 18:15   ` [Outreachy kernel] " Julia Lawall
2017-03-10 16:00 ` [PATCH 4/4] staging: rtl8712: Refactor conditional in r871x_get_ap_info Narcisa Ana Maria Vasile
2017-03-10 18:08   ` [Outreachy kernel] " Julia Lawall
2017-03-10 20:37     ` Narcisa Ana Maria Vasile
2017-03-10 20:41       ` Julia Lawall
2017-03-10 18:22 ` [Outreachy kernel] [PATCH 0/4] staging: rtl8712: Refactor conditionals Julia Lawall
2017-03-18 18:33 ` [PATCH v2 0/4] staging: rtl8712: Invert if statements to reduce indentation level Narcisa Ana Maria Vasile
2017-03-18 18:34   ` [PATCH v2 1/4] " Narcisa Ana Maria Vasile
2017-03-18 18:35   ` [PATCH v2 2/4] staging: rtl8712: Invert if statement " Narcisa Ana Maria Vasile
2017-03-18 18:35   ` [PATCH v2 3/4] staging: rtl8712: Invert if statements to " Narcisa Ana Maria Vasile
2017-03-18 18:35   ` [PATCH v2 4/4] staging: rtl8712: Invert if statement " Narcisa Ana Maria Vasile
2017-03-21  7:44   ` [PATCH v2 0/4] staging: rtl8712: Invert if statements " Greg KH
2017-03-21 22:52 ` [PATCH v3 0/4] staging: rtl8712: Refactor conditionals to reduce indentation Narcisa Ana Maria Vasile
2017-03-21 22:52   ` [PATCH v3 1/4] staging: rtl8712: Invert if statements to reduce indentation level Narcisa Ana Maria Vasile
2017-03-21 22:52   ` [PATCH v3 2/4] staging: rtl8712: Invert the test on check_fwstate() to reduce indentation Narcisa Ana Maria Vasile
2017-03-21 22:53   ` [PATCH v3 3/4] staging: rtl8712: Restructure code for clarity Narcisa Ana Maria Vasile
2017-03-21 22:53   ` [PATCH v3 4/4] staging: rtl8712: Invert comparison to reduce indentation Narcisa Ana Maria Vasile

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=alpine.DEB.2.20.1703101920470.3356@hadrien \
    --to=julia.lawall@lip6.fr \
    --cc=Larry.Finger@lwfinger.net \
    --cc=florian.c.schilhabel@googlemail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=narcisaanamaria12@gmail.com \
    --cc=outreachy-kernel@googlegroups.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 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.