From: Sergio Paracuellos Date: Wed, 25 Apr 2018 14:01:43 +0000 (+0200) Subject: staging: ks7010: refactor ks_wlan_set_power_mgmt function X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=c87125805216ba3c66d3cb8ed3ff5c36d2ddff01;p=linux.git staging: ks7010: refactor ks_wlan_set_power_mgmt function 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 Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/ks7010/ks_wlan_net.c b/drivers/staging/ks7010/ks_wlan_net.c index e943d372c393c..3c9fbb9bcd52b 100644 --- a/drivers/staging/ks7010/ks_wlan_net.c +++ b/drivers/staging/ks7010/ks_wlan_net.c @@ -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;