staging: ks7010: avoid some if-else code in get_current_ap function
authorSergio Paracuellos <sergio.paracuellos@gmail.com>
Tue, 24 Apr 2018 13:49:50 +0000 (15:49 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 25 Apr 2018 13:50:18 +0000 (15:50 +0200)
This commits avoid some if-else code extracting common code before
its use and making use of a new variable 'size' which is assigned
using a ternary operator. This improves readability.

Signed-off-by: Sergio Paracuellos <sergio.paracuellos@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/ks7010/ks_hostif.c

index d46a9553e835597da562cfe08006f530dc7d0e3a..5e8bc9354e566ed202b98445e13b3d845b57df6d 100644 (file)
@@ -103,6 +103,7 @@ int get_current_ap(struct ks_wlan_private *priv, struct link_ap_info *ap_info)
        struct local_ap *ap;
        union iwreq_data wrqu;
        struct net_device *netdev = priv->net_dev;
+       u8 size;
 
        ap = &priv->current_ap;
 
@@ -129,30 +130,18 @@ int get_current_ap(struct ks_wlan_private *priv, struct link_ap_info *ap_info)
        ap->sq = ap_info->sq;
        ap->noise = ap_info->noise;
        ap->capability = le16_to_cpu(ap_info->capability);
+       size = (ap_info->rsn.size <= RSN_IE_BODY_MAX) ?
+               ap_info->rsn.size : RSN_IE_BODY_MAX;
        if ((ap_info->rsn_mode & RSN_MODE_WPA2) &&
            (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)) {
                ap->rsn_ie.id = 0x30;
-               if (ap_info->rsn.size <= RSN_IE_BODY_MAX) {
-                       ap->rsn_ie.size = ap_info->rsn.size;
-                       memcpy(ap->rsn_ie.body, ap_info->rsn.body,
-                              ap_info->rsn.size);
-               } else {
-                       ap->rsn_ie.size = RSN_IE_BODY_MAX;
-                       memcpy(ap->rsn_ie.body, ap_info->rsn.body,
-                              RSN_IE_BODY_MAX);
-               }
+               ap->rsn_ie.size = size;
+               memcpy(ap->rsn_ie.body, ap_info->rsn.body, size);
        } else if ((ap_info->rsn_mode & RSN_MODE_WPA) &&
                   (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA)) {
                ap->wpa_ie.id = 0xdd;
-               if (ap_info->rsn.size <= RSN_IE_BODY_MAX) {
-                       ap->wpa_ie.size = ap_info->rsn.size;
-                       memcpy(ap->wpa_ie.body, ap_info->rsn.body,
-                              ap_info->rsn.size);
-               } else {
-                       ap->wpa_ie.size = RSN_IE_BODY_MAX;
-                       memcpy(ap->wpa_ie.body, ap_info->rsn.body,
-                              RSN_IE_BODY_MAX);
-               }
+               ap->wpa_ie.size = size;
+               memcpy(ap->wpa_ie.body, ap_info->rsn.body, size);
        } else {
                ap->rsn_ie.id = 0;
                ap->rsn_ie.size = 0;