From: Joe Perches <joe@perches.com>
To: Kalle Valo <kvalo@qca.qualcomm.com>, linux-kernel@vger.kernel.org
Cc: devel@linuxdriverproject.org, gregkh@suse.de, error27@gmail.com,
"John W. Linville" <linville@tuxdriver.com>,
linux-wireless@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCH 3/3] ath6kl: cfg80211: Add and use ath6kl_cfg80211_ready helper
Date: Sun, 17 Jul 2011 11:43:44 -0700 [thread overview]
Message-ID: <46870c7654d2d0d10b44ee45097762c482eee1d0.1310927985.git.joe@perches.com> (raw)
In-Reply-To: <cover.1310927985.git.joe@perches.com>
Reduce code duplication by using a helper function to
check if the device is ready.
Signed-off-by: Joe Perches <joe@perches.com>
---
drivers/net/wireless/ath/ath6kl/cfg80211.c | 150 ++++++----------------------
1 files changed, 30 insertions(+), 120 deletions(-)
diff --git a/drivers/net/wireless/ath/ath6kl/cfg80211.c b/drivers/net/wireless/ath/ath6kl/cfg80211.c
index 34df184..71515bb 100644
--- a/drivers/net/wireless/ath/ath6kl/cfg80211.c
+++ b/drivers/net/wireless/ath/ath6kl/cfg80211.c
@@ -217,6 +217,21 @@ static void ath6kl_set_key_mgmt(struct ath6kl *ar, u32 key_mgmt)
}
}
+static bool ath6kl_cfg80211_ready(struct ath6kl *ar)
+{
+ if (!test_bit(WMI_READY, &ar->flag)) {
+ ath6kl_err("wmi is not ready\n");
+ return false;
+ }
+
+ if (ar->wlan_state == WLAN_DISABLED) {
+ ath6kl_err("wlan disabled\n");
+ return false;
+ }
+
+ return true;
+}
+
static int ath6kl_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
struct cfg80211_connect_params *sme)
{
@@ -225,15 +240,8 @@ static int ath6kl_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
ar->sme_state = SME_CONNECTING;
- if (!test_bit(WMI_READY, &ar->flag)) {
- ath6kl_err("wmi is not ready yet\n");
+ if (!ath6kl_cfg80211_ready(ar))
return -EIO;
- }
-
- if (ar->wlan_state == WLAN_DISABLED) {
- ath6kl_err("wlan disabled\n");
- return -EIO;
- }
if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
ath6kl_err("destroy in progress\n");
@@ -575,15 +583,8 @@ static int ath6kl_cfg80211_disconnect(struct wiphy *wiphy,
ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: reason=%u\n", __func__,
reason_code);
- if (!test_bit(WMI_READY, &ar->flag)) {
- ath6kl_err("wmi is not ready\n");
- return -EIO;
- }
-
- if (ar->wlan_state == WLAN_DISABLED) {
- ath6kl_err("wlan disabled\n");
+ if (!ath6kl_cfg80211_ready(ar))
return -EIO;
- }
if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
ath6kl_err("busy, destroy in progress\n");
@@ -781,15 +782,8 @@ static int ath6kl_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
int ret = 0;
u32 force_fg_scan = 0;
- if (!test_bit(WMI_READY, &ar->flag)) {
- ath6kl_err("wmi is not ready\n");
+ if (!ath6kl_cfg80211_ready(ar))
return -EIO;
- }
-
- if (ar->wlan_state == WLAN_DISABLED) {
- ath6kl_err("wlan disabled\n");
- return -EIO;
- }
if (!ar->usr_bss_filter) {
if (ath6kl_wmi_bssfilter_cmd(ar->wmi,
@@ -866,15 +860,8 @@ static int ath6kl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev,
u8 key_type;
int status = 0;
- if (!test_bit(WMI_READY, &ar->flag)) {
- ath6kl_err("wmi is not ready\n");
- return -EIO;
- }
-
- if (ar->wlan_state == WLAN_DISABLED) {
- ath6kl_err("wlan disabled\n");
+ if (!ath6kl_cfg80211_ready(ar))
return -EIO;
- }
if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
@@ -951,15 +938,8 @@ static int ath6kl_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev,
ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
- if (!test_bit(WMI_READY, &ar->flag)) {
- ath6kl_err("wmi is not ready\n");
- return -EIO;
- }
-
- if (ar->wlan_state == WLAN_DISABLED) {
- ath6kl_err("wlan disabled\n");
+ if (!ath6kl_cfg80211_ready(ar))
return -EIO;
- }
if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
@@ -991,15 +971,8 @@ static int ath6kl_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev,
ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
- if (!test_bit(WMI_READY, &ar->flag)) {
- ath6kl_err("wmi is not ready\n");
- return -EIO;
- }
-
- if (ar->wlan_state == WLAN_DISABLED) {
- ath6kl_err("wlan disabled\n");
+ if (!ath6kl_cfg80211_ready(ar))
return -EIO;
- }
if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
@@ -1033,15 +1006,8 @@ static int ath6kl_cfg80211_set_default_key(struct wiphy *wiphy,
ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
- if (!test_bit(WMI_READY, &ar->flag)) {
- ath6kl_err("wmi is not ready\n");
- return -EIO;
- }
-
- if (ar->wlan_state == WLAN_DISABLED) {
- ath6kl_err("wlan disabled\n");
+ if (!ath6kl_cfg80211_ready(ar))
return -EIO;
- }
if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
@@ -1081,15 +1047,8 @@ static int ath6kl_cfg80211_set_default_mgmt_key(struct wiphy *wiphy,
ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
- if (!test_bit(WMI_READY, &ar->flag)) {
- ath6kl_err("wmi is not ready\n");
+ if (!ath6kl_cfg80211_ready(ar))
return -EIO;
- }
-
- if (ar->wlan_state == WLAN_DISABLED) {
- ath6kl_err("wlan disabled\n");
- return -EIO;
- }
ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: not supported\n", __func__);
return -ENOTSUPP;
@@ -1115,15 +1074,8 @@ static int ath6kl_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: changed 0x%x\n", __func__,
changed);
- if (!test_bit(WMI_READY, &ar->flag)) {
- ath6kl_err("wmi is not ready\n");
- return -EIO;
- }
-
- if (ar->wlan_state == WLAN_DISABLED) {
- ath6kl_err("wlan disabled\n");
+ if (!ath6kl_cfg80211_ready(ar))
return -EIO;
- }
if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
ret = ath6kl_wmi_set_rts_cmd(ar->wmi, wiphy->rts_threshold);
@@ -1150,15 +1102,8 @@ static int ath6kl_cfg80211_set_txpower(struct wiphy *wiphy,
ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x, dbm %d\n", __func__,
type, dbm);
- if (!test_bit(WMI_READY, &ar->flag)) {
- ath6kl_err("wmi is not ready\n");
- return -EIO;
- }
-
- if (ar->wlan_state == WLAN_DISABLED) {
- ath6kl_err("wlan disabled\n");
+ if (!ath6kl_cfg80211_ready(ar))
return -EIO;
- }
switch (type) {
case NL80211_TX_POWER_AUTOMATIC:
@@ -1181,15 +1126,8 @@ static int ath6kl_cfg80211_get_txpower(struct wiphy *wiphy, int *dbm)
{
struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
- if (!test_bit(WMI_READY, &ar->flag)) {
- ath6kl_err("wmi is not ready\n");
- return -EIO;
- }
-
- if (ar->wlan_state == WLAN_DISABLED) {
- ath6kl_err("wlan disabled\n");
+ if (!ath6kl_cfg80211_ready(ar))
return -EIO;
- }
if (test_bit(CONNECTED, &ar->flag)) {
ar->tx_pwr = 0;
@@ -1222,15 +1160,8 @@ static int ath6kl_cfg80211_set_power_mgmt(struct wiphy *wiphy,
ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: pmgmt %d, timeout %d\n",
__func__, pmgmt, timeout);
- if (!test_bit(WMI_READY, &ar->flag)) {
- ath6kl_err("wmi is not ready\n");
- return -EIO;
- }
-
- if (ar->wlan_state == WLAN_DISABLED) {
- ath6kl_err("wlan disabled\n");
+ if (!ath6kl_cfg80211_ready(ar))
return -EIO;
- }
if (pmgmt) {
ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: max perf\n", __func__);
@@ -1258,15 +1189,8 @@ static int ath6kl_cfg80211_change_iface(struct wiphy *wiphy,
ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type %u\n", __func__, type);
- if (!test_bit(WMI_READY, &ar->flag)) {
- ath6kl_err("wmi is not ready\n");
- return -EIO;
- }
-
- if (ar->wlan_state == WLAN_DISABLED) {
- ath6kl_err("wlan disabled\n");
+ if (!ath6kl_cfg80211_ready(ar))
return -EIO;
- }
switch (type) {
case NL80211_IFTYPE_STATION:
@@ -1292,15 +1216,8 @@ static int ath6kl_cfg80211_join_ibss(struct wiphy *wiphy,
struct ath6kl *ar = ath6kl_priv(dev);
int status;
- if (!test_bit(WMI_READY, &ar->flag)) {
- ath6kl_err("wmi is not ready\n");
- return -EIO;
- }
-
- if (ar->wlan_state == WLAN_DISABLED) {
- ath6kl_err("wlan disabled\n");
+ if (!ath6kl_cfg80211_ready(ar))
return -EIO;
- }
if (!ibss_param->ssid_len ||
IEEE80211_MAX_SSID_LEN < ibss_param->ssid_len) {
@@ -1367,15 +1284,8 @@ static int ath6kl_cfg80211_leave_ibss(struct wiphy *wiphy,
{
struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(dev);
- if (!test_bit(WMI_READY, &ar->flag)) {
- ath6kl_err("wmi is not ready\n");
- return -EIO;
- }
-
- if (ar->wlan_state == WLAN_DISABLED) {
- ath6kl_err("wlan disabled\n");
+ if (!ath6kl_cfg80211_ready(ar))
return -EIO;
- }
ath6kl_disconnect(ar);
memset(ar->ssid, 0, sizeof(ar->ssid));
--
1.7.6.131.g99019
next prev parent reply other threads:[~2011-07-17 18:44 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-17 18:43 [PATCH 0/3] ath6kl: neatening Joe Perches
2011-07-17 18:43 ` [PATCH 1/3] ath6kl: Add missing newlines and coalesce messages Joe Perches
2011-07-17 18:43 ` [PATCH 2/3] ath6kl: Remove __func__ uses from ath6kl_err Joe Perches
2011-07-17 18:43 ` Joe Perches [this message]
2011-07-17 18:56 ` [PATCH 0/3] ath6kl: neatening Kalle Valo
2011-07-17 19:52 ` Joe Perches
2011-07-17 20:45 ` Kalle Valo
2011-07-17 21:38 ` [PATCH 0/2] ath6kl: more neatening Joe Perches
2011-07-17 21:38 ` [PATCH 1/2] ath6kl: Remove __func__ uses from ath6kl_dbg Joe Perches
2011-07-17 21:38 ` [PATCH 2/2] ath6kl: Remove trailing unpaired close paren from ath6kl_err uses Joe Perches
2011-07-17 21:49 ` [PATCH 0/2] ath6kl: more neatening Kalle Valo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=46870c7654d2d0d10b44ee45097762c482eee1d0.1310927985.git.joe@perches.com \
--to=joe@perches.com \
--cc=devel@linuxdriverproject.org \
--cc=error27@gmail.com \
--cc=gregkh@suse.de \
--cc=kvalo@qca.qualcomm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=linville@tuxdriver.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®