Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging: rtl8712: Restructure code for clarity

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>

authored by

Narcisa Ana Maria Vasile and committed by
Greg Kroah-Hartman
ad93cc9f 09e1aa1a

+33 -36
+33 -36
drivers/staging/rtl8712/rtl871x_ioctl_linux.c
··· 1406 1406 u16 mcs_rate = 0; 1407 1407 1408 1408 i = 0; 1409 - if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE)) { 1410 - p = r8712_get_ie(&pcur_bss->IEs[12], 1411 - _HT_CAPABILITY_IE_, &ht_ielen, 1412 - pcur_bss->IELength - 12); 1413 - if (p && ht_ielen > 0) { 1414 - ht_cap = true; 1415 - pht_capie = (struct ieee80211_ht_cap *)(p + 2); 1416 - memcpy(&mcs_rate, pht_capie->supp_mcs_set, 2); 1417 - bw_40MHz = (le16_to_cpu(pht_capie->cap_info) & 1418 - IEEE80211_HT_CAP_SUP_WIDTH) ? 1 : 0; 1419 - short_GI = (le16_to_cpu(pht_capie->cap_info) & 1420 - (IEEE80211_HT_CAP_SGI_20 | 1421 - IEEE80211_HT_CAP_SGI_40)) ? 1 : 0; 1422 - } 1423 - while ((pcur_bss->rates[i] != 0) && 1424 - (pcur_bss->rates[i] != 0xFF)) { 1425 - rate = pcur_bss->rates[i] & 0x7F; 1426 - if (rate > max_rate) 1427 - max_rate = rate; 1428 - wrqu->bitrate.fixed = 0; /* no auto select */ 1429 - wrqu->bitrate.value = rate * 500000; 1430 - i++; 1431 - } 1432 - if (ht_cap) { 1433 - if (mcs_rate & 0x8000 /* MCS15 */ 1434 - && 1435 - rf_type == RTL8712_RF_2T2R) 1436 - max_rate = (bw_40MHz) ? ((short_GI) ? 300 : 1437 - 270) : ((short_GI) ? 144 : 130); 1438 - else /* default MCS7 */ 1439 - max_rate = (bw_40MHz) ? ((short_GI) ? 150 : 1440 - 135) : ((short_GI) ? 72 : 65); 1441 - max_rate *= 2; /* Mbps/2 */ 1442 - } 1443 - wrqu->bitrate.value = max_rate * 500000; 1444 - } else { 1409 + if (!check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE)) 1445 1410 return -ENOLINK; 1411 + p = r8712_get_ie(&pcur_bss->IEs[12], _HT_CAPABILITY_IE_, &ht_ielen, 1412 + pcur_bss->IELength - 12); 1413 + if (p && ht_ielen > 0) { 1414 + ht_cap = true; 1415 + pht_capie = (struct ieee80211_ht_cap *)(p + 2); 1416 + memcpy(&mcs_rate, pht_capie->supp_mcs_set, 2); 1417 + bw_40MHz = (le16_to_cpu(pht_capie->cap_info) & 1418 + IEEE80211_HT_CAP_SUP_WIDTH) ? 1 : 0; 1419 + short_GI = (le16_to_cpu(pht_capie->cap_info) & 1420 + (IEEE80211_HT_CAP_SGI_20 | 1421 + IEEE80211_HT_CAP_SGI_40)) ? 1 : 0; 1446 1422 } 1423 + while ((pcur_bss->rates[i] != 0) && 1424 + (pcur_bss->rates[i] != 0xFF)) { 1425 + rate = pcur_bss->rates[i] & 0x7F; 1426 + if (rate > max_rate) 1427 + max_rate = rate; 1428 + wrqu->bitrate.fixed = 0; /* no auto select */ 1429 + wrqu->bitrate.value = rate * 500000; 1430 + i++; 1431 + } 1432 + if (ht_cap) { 1433 + if (mcs_rate & 0x8000 /* MCS15 */ 1434 + && 1435 + rf_type == RTL8712_RF_2T2R) 1436 + max_rate = (bw_40MHz) ? ((short_GI) ? 300 : 270) : 1437 + ((short_GI) ? 144 : 130); 1438 + else /* default MCS7 */ 1439 + max_rate = (bw_40MHz) ? ((short_GI) ? 150 : 135) : 1440 + ((short_GI) ? 72 : 65); 1441 + max_rate *= 2; /* Mbps/2 */ 1442 + } 1443 + wrqu->bitrate.value = max_rate * 500000; 1447 1444 return 0; 1448 1445 } 1449 1446