staging: ks7010: refactor ks_wlan_set_power_mgmt function
authorSergio Paracuellos <sergio.paracuellos@gmail.com>
Wed, 25 Apr 2018 14:01:43 +0000 (16:01 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 26 Apr 2018 07:35:03 +0000 (09:35 +0200)
This commit change logic to simplify conditional paths in
ks_wlan_set_power_mgmt function. It handles invalid's first
and just finally assign a valid value.

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

index e943d372c393c3e8ca4a3d6199f326ccd884153e..3c9fbb9bcd52b1813be5f563e7f0f0d56107db0a 100644 (file)
@@ -1895,23 +1895,16 @@ static int ks_wlan_set_power_mgmt(struct net_device *dev,
        if (priv->sleep_mode == SLP_SLEEP)
                return -EPERM;
 
-       /* for SLEEP MODE */
-       if (*uwrq == POWER_MGMT_ACTIVE) {       /* 0 */
-               priv->reg.power_mgmt = POWER_MGMT_ACTIVE;
-       } else if (*uwrq == POWER_MGMT_SAVE1) { /* 1 */
-               if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
-                       priv->reg.power_mgmt = POWER_MGMT_SAVE1;
-               else
-                       return -EINVAL;
-       } else if (*uwrq == POWER_MGMT_SAVE2) { /* 2 */
-               if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
-                       priv->reg.power_mgmt = POWER_MGMT_SAVE2;
-               else
-                       return -EINVAL;
-       } else {
+       if (*uwrq != POWER_MGMT_ACTIVE &&
+           *uwrq != POWER_MGMT_SAVE1 &&
+           *uwrq != POWER_MGMT_SAVE2)
+               return -EINVAL;
+
+       if ((*uwrq == POWER_MGMT_SAVE1 || *uwrq == POWER_MGMT_SAVE2) &&
+           (priv->reg.operation_mode != MODE_INFRASTRUCTURE))
                return -EINVAL;
-       }
 
+       priv->reg.power_mgmt = *uwrq;
        hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
 
        return 0;