Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751553AbdIJSe6 (ORCPT ); Sun, 10 Sep 2017 14:34:58 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:34115 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750742AbdIJSe4 (ORCPT ); Sun, 10 Sep 2017 14:34:56 -0400 X-Google-Smtp-Source: ADKCNb7kaIsyGNGFFDge1XypPJlr/woqjtUG5IHcIr3SvsQYQzpNl0jdS5WKW+OaV0iH/Qkm6sclBA== From: Ivan Safonov To: Greg Kroah-Hartman Cc: simran singhal , "David S. Miller" , Colin Ian King , Julia Lawall , Ivan Safonov , devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: [PATCH] staging:r8192u: replace request_module with try_then_request_module Date: Sun, 10 Sep 2017 21:34:28 +0300 Message-Id: <20170910183428.27157-1-insafonov@gmail.com> X-Mailer: git-send-email 2.13.5 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3742 Lines: 90 Return value of request_module() does not handled, so it is possible to use shorter try_then_request_module(). Signed-off-by: Ivan Safonov --- .../staging/rtl8192u/ieee80211/ieee80211_softmac.c | 27 +++++++++++----------- drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c | 15 ++++-------- 2 files changed, 17 insertions(+), 25 deletions(-) diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c index fe6f38b7ec35..4e7908322d77 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c @@ -2948,8 +2948,9 @@ static int ieee80211_wpa_set_encryption(struct ieee80211_device *ieee, struct ieee_param *param, int param_len) { int ret = 0; + const char *module = NULL; - struct ieee80211_crypto_ops *ops; + struct ieee80211_crypto_ops *ops = NULL; struct ieee80211_crypt_data **crypt; struct ieee80211_security sec = { @@ -2995,19 +2996,17 @@ static int ieee80211_wpa_set_encryption(struct ieee80211_device *ieee, strcmp(param->u.crypt.alg, "TKIP")) goto skip_host_crypt; - ops = ieee80211_get_crypto_ops(param->u.crypt.alg); - if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) { - request_module("ieee80211_crypt_wep"); - ops = ieee80211_get_crypto_ops(param->u.crypt.alg); - //set WEP40 first, it will be modified according to WEP104 or WEP40 at other place - } else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) { - request_module("ieee80211_crypt_tkip"); - ops = ieee80211_get_crypto_ops(param->u.crypt.alg); - } else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) { - request_module("ieee80211_crypt_ccmp"); - ops = ieee80211_get_crypto_ops(param->u.crypt.alg); - } - if (ops == NULL) { + //set WEP40 first, it will be modified according to WEP104 or WEP40 at other place + if (!strcmp(param->u.crypt.alg, "WEP")) + module = "ieee80211_crypt_wep"; + else if (!strcmp(param->u.crypt.alg, "TKIP")) + module = "ieee80211_crypt_tkip"; + else if (!strcmp(param->u.crypt.alg, "CCMP")) + module = "ieee80211_crypt_ccmp"; + if (module) + ops = try_then_request_module(ieee80211_get_crypto_ops(param->u.crypt.alg), + module); + if (!ops) { printk("unknown crypto alg '%s'\n", param->u.crypt.alg); param->u.crypt.err = IEEE_CRYPT_ERR_UNKNOWN_ALG; ret = -EINVAL; diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c index c925e53bf013..f2fcdec9bd17 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c @@ -364,11 +364,8 @@ int ieee80211_wx_set_encode(struct ieee80211_device *ieee, GFP_KERNEL); if (!new_crypt) return -ENOMEM; - new_crypt->ops = ieee80211_get_crypto_ops("WEP"); - if (!new_crypt->ops) { - request_module("ieee80211_crypt_wep"); - new_crypt->ops = ieee80211_get_crypto_ops("WEP"); - } + new_crypt->ops = try_then_request_module(ieee80211_get_crypto_ops("WEP"), + "ieee80211_crypt_wep"); if (new_crypt->ops && try_module_get(new_crypt->ops->owner)) new_crypt->priv = new_crypt->ops->init(key); @@ -591,12 +588,8 @@ int ieee80211_wx_set_encode_ext(struct ieee80211_device *ieee, } printk("alg name:%s\n",alg); - ops = ieee80211_get_crypto_ops(alg); - if (ops == NULL) { - request_module(module); - ops = ieee80211_get_crypto_ops(alg); - } - if (ops == NULL) { + ops = try_then_request_module(ieee80211_get_crypto_ops(alg), module); + if (!ops) { IEEE80211_DEBUG_WX("%s: unknown crypto alg %d\n", dev->name, ext->alg); printk("========>unknown crypto alg %d\n", ext->alg); -- 2.13.5