]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
staging: rtl8712: Restructure code for clarity
authorNarcisa Ana Maria Vasile <narcisaanamaria12@gmail.com>
Tue, 21 Mar 2017 22:53:16 +0000 (00:53 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 23 Mar 2017 13:24:45 +0000 (14:24 +0100)
Invert if statements to be able to return immediately in case of error,
and to avoid additional else branch.

Improve layout of function since there is more horizontal space now.

This was found using the following Coccinelle 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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/rtl8712/rtl871x_ioctl_linux.c

index 38c17030eff0088ad988f76cf098c0fe929897dc..3d6e818a7cc25ca37d45e076cf82ed176c5cbcfc 100644 (file)
@@ -1406,44 +1406,41 @@ static int r8711_wx_get_rate(struct net_device *dev,
        u16 mcs_rate = 0;
 
        i = 0;
-       if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE)) {
-               p = r8712_get_ie(&pcur_bss->IEs[12],
-                                _HT_CAPABILITY_IE_, &ht_ielen,
-                   pcur_bss->IELength - 12);
-               if (p && ht_ielen > 0) {
-                       ht_cap = true;
-                       pht_capie = (struct ieee80211_ht_cap *)(p + 2);
-                       memcpy(&mcs_rate, pht_capie->supp_mcs_set, 2);
-                       bw_40MHz = (le16_to_cpu(pht_capie->cap_info) &
-                                   IEEE80211_HT_CAP_SUP_WIDTH) ? 1 : 0;
-                       short_GI = (le16_to_cpu(pht_capie->cap_info) &
-                                   (IEEE80211_HT_CAP_SGI_20 |
-                                   IEEE80211_HT_CAP_SGI_40)) ? 1 : 0;
-               }
-               while ((pcur_bss->rates[i] != 0) &&
-                       (pcur_bss->rates[i] != 0xFF)) {
-                       rate = pcur_bss->rates[i] & 0x7F;
-                       if (rate > max_rate)
-                               max_rate = rate;
-                       wrqu->bitrate.fixed = 0;        /* no auto select */
-                       wrqu->bitrate.value = rate * 500000;
-                       i++;
-               }
-               if (ht_cap) {
-                       if (mcs_rate & 0x8000 /* MCS15 */
-                               &&
-                               rf_type == RTL8712_RF_2T2R)
-                               max_rate = (bw_40MHz) ? ((short_GI) ? 300 :
-                                           270) : ((short_GI) ? 144 : 130);
-                       else /* default MCS7 */
-                               max_rate = (bw_40MHz) ? ((short_GI) ? 150 :
-                                           135) : ((short_GI) ? 72 : 65);
-                       max_rate *= 2; /* Mbps/2 */
-               }
-               wrqu->bitrate.value = max_rate * 500000;
-       } else {
+       if (!check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE))
                return -ENOLINK;
+       p = r8712_get_ie(&pcur_bss->IEs[12], _HT_CAPABILITY_IE_, &ht_ielen,
+                        pcur_bss->IELength - 12);
+       if (p && ht_ielen > 0) {
+               ht_cap = true;
+               pht_capie = (struct ieee80211_ht_cap *)(p + 2);
+               memcpy(&mcs_rate, pht_capie->supp_mcs_set, 2);
+               bw_40MHz = (le16_to_cpu(pht_capie->cap_info) &
+                           IEEE80211_HT_CAP_SUP_WIDTH) ? 1 : 0;
+               short_GI = (le16_to_cpu(pht_capie->cap_info) &
+                           (IEEE80211_HT_CAP_SGI_20 |
+                           IEEE80211_HT_CAP_SGI_40)) ? 1 : 0;
+       }
+       while ((pcur_bss->rates[i] != 0) &&
+              (pcur_bss->rates[i] != 0xFF)) {
+               rate = pcur_bss->rates[i] & 0x7F;
+               if (rate > max_rate)
+                       max_rate = rate;
+               wrqu->bitrate.fixed = 0;        /* no auto select */
+               wrqu->bitrate.value = rate * 500000;
+               i++;
+       }
+       if (ht_cap) {
+               if (mcs_rate & 0x8000 /* MCS15 */
+                   &&
+                   rf_type == RTL8712_RF_2T2R)
+                       max_rate = (bw_40MHz) ? ((short_GI) ? 300 : 270) :
+                       ((short_GI) ? 144 : 130);
+               else /* default MCS7 */
+                       max_rate = (bw_40MHz) ? ((short_GI) ? 150 : 135) :
+                       ((short_GI) ? 72 : 65);
+               max_rate *= 2; /* Mbps/2 */
        }
+       wrqu->bitrate.value = max_rate * 500000;
        return 0;
 }