nl80211: propagate netlink errors to callers

Adjust nl80211_send() to propagate errors back to the caller and do not
free message and callbacks in send error case anymore since all callsites
immediately invoke nl80211_free() anyway.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
Jo-Philipp Wich 2017-06-26 07:22:10 +02:00
parent 7bba117a3a
commit ab089dda34

View file

@ -369,10 +369,10 @@ nla_put_failure:
return NULL; return NULL;
} }
static struct nl80211_msg_conveyor * nl80211_send( static int nl80211_send(struct nl80211_msg_conveyor *cv,
struct nl80211_msg_conveyor *cv, int (*cb_func)(struct nl_msg *, void *),
int (*cb_func)(struct nl_msg *, void *), void *cb_arg void *cb_arg)
) { {
static struct nl80211_msg_conveyor rcv; static struct nl80211_msg_conveyor rcv;
int err = 1; int err = 1;
@ -381,8 +381,10 @@ static struct nl80211_msg_conveyor * nl80211_send(
else else
nl_cb_set(cv->cb, NL_CB_VALID, NL_CB_CUSTOM, nl80211_msg_response, &rcv); nl_cb_set(cv->cb, NL_CB_VALID, NL_CB_CUSTOM, nl80211_msg_response, &rcv);
if (nl_send_auto_complete(nls->nl_sock, cv->msg) < 0) err = nl_send_auto_complete(nls->nl_sock, cv->msg);
goto err;
if (err < 0)
goto out;
nl_cb_err(cv->cb, NL_CB_CUSTOM, nl80211_msg_error, &err); nl_cb_err(cv->cb, NL_CB_CUSTOM, nl80211_msg_error, &err);
nl_cb_set(cv->cb, NL_CB_FINISH, NL_CB_CUSTOM, nl80211_msg_finish, &err); nl_cb_set(cv->cb, NL_CB_FINISH, NL_CB_CUSTOM, nl80211_msg_finish, &err);
@ -391,13 +393,8 @@ static struct nl80211_msg_conveyor * nl80211_send(
while (err > 0) while (err > 0)
nl_recvmsgs(nls->nl_sock, cv->cb); nl_recvmsgs(nls->nl_sock, cv->cb);
return &rcv; out:
return err;
err:
nl_cb_put(cv->cb);
nlmsg_free(cv->msg);
return NULL;
} }
static struct nlattr ** nl80211_parse(struct nl_msg *msg) static struct nlattr ** nl80211_parse(struct nl_msg *msg)