From: Sergio Paracuellos Date: Tue, 24 Apr 2018 13:49:50 +0000 (+0200) Subject: staging: ks7010: avoid some if-else code in get_current_ap function X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=0ff7968d6a8d8293968e1be55a458f9d34a6dff4;p=openwrt%2Fstaging%2Fblogic.git staging: ks7010: avoid some if-else code in get_current_ap function 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 Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/ks7010/ks_hostif.c b/drivers/staging/ks7010/ks_hostif.c index d46a9553e835..5e8bc9354e56 100644 --- a/drivers/staging/ks7010/ks_hostif.c +++ b/drivers/staging/ks7010/ks_hostif.c @@ -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;