Skip to content

Commit

Permalink
wlcore: make usage of nla_put clearer
Browse files Browse the repository at this point in the history
handle errors of nla_put() inside the if(nla_put...) {}

This makes the code simpler and clearer because:
we take advantage from the fact that we have only one nla_put
in our routines (so no real need for goto label).
this avoids ugly goto forward followed by goto backward.

Signed-off-by: Yair Shapira <yair.shapira@ti.com>
Signed-off-by: Luciano Coelho <coelho@ti.com>
  • Loading branch information
Yair Shapira authored and Luciano Coelho committed Jul 18, 2012
1 parent ff32431 commit bf722d1
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions drivers/net/wireless/ti/wlcore/testmode.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,12 @@ static int wl1271_tm_cmd_test(struct wl1271 *wl, struct nlattr *tb[])
goto out_sleep;
}

if (nla_put(skb, WL1271_TM_ATTR_DATA, buf_len, buf))
goto nla_put_failure;
if (nla_put(skb, WL1271_TM_ATTR_DATA, buf_len, buf)) {
kfree_skb(skb);
ret = -EMSGSIZE;
goto out_sleep;
}

ret = cfg80211_testmode_reply(skb);
if (ret < 0)
goto out_sleep;
Expand All @@ -142,11 +146,6 @@ static int wl1271_tm_cmd_test(struct wl1271 *wl, struct nlattr *tb[])
mutex_unlock(&wl->mutex);

return ret;

nla_put_failure:
kfree_skb(skb);
ret = -EMSGSIZE;
goto out_sleep;
}

static int wl1271_tm_cmd_interrogate(struct wl1271 *wl, struct nlattr *tb[])
Expand Down Expand Up @@ -192,8 +191,12 @@ static int wl1271_tm_cmd_interrogate(struct wl1271 *wl, struct nlattr *tb[])
goto out_free;
}

if (nla_put(skb, WL1271_TM_ATTR_DATA, sizeof(*cmd), cmd))
goto nla_put_failure;
if (nla_put(skb, WL1271_TM_ATTR_DATA, sizeof(*cmd), cmd)) {
kfree_skb(skb);
ret = -EMSGSIZE;
goto out_free;
}

ret = cfg80211_testmode_reply(skb);
if (ret < 0)
goto out_free;
Expand All @@ -206,11 +209,6 @@ static int wl1271_tm_cmd_interrogate(struct wl1271 *wl, struct nlattr *tb[])
mutex_unlock(&wl->mutex);

return ret;

nla_put_failure:
kfree_skb(skb);
ret = -EMSGSIZE;
goto out_free;
}

static int wl1271_tm_cmd_configure(struct wl1271 *wl, struct nlattr *tb[])
Expand Down Expand Up @@ -343,20 +341,19 @@ static int wl12xx_tm_cmd_get_mac(struct wl1271 *wl, struct nlattr *tb[])
goto out;
}

if (nla_put(skb, WL1271_TM_ATTR_DATA, ETH_ALEN, mac_addr))
goto nla_put_failure;
if (nla_put(skb, WL1271_TM_ATTR_DATA, ETH_ALEN, mac_addr)) {
kfree_skb(skb);
ret = -EMSGSIZE;
goto out;
}

ret = cfg80211_testmode_reply(skb);
if (ret < 0)
goto out;

out:
mutex_unlock(&wl->mutex);
return ret;

nla_put_failure:
kfree_skb(skb);
ret = -EMSGSIZE;
goto out;
}

int wl1271_tm_cmd(struct ieee80211_hw *hw, void *data, int len)
Expand Down

0 comments on commit bf722d1

Please sign in to comment.