From ab089dda34a44bd118180a9403abb942b255ad2e Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Mon, 26 Jun 2017 07:22:10 +0200 Subject: [PATCH] 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 --- iwinfo_nl80211.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/iwinfo_nl80211.c b/iwinfo_nl80211.c index e3a7e4d..3d9ee73 100644 --- a/iwinfo_nl80211.c +++ b/iwinfo_nl80211.c @@ -369,10 +369,10 @@ nla_put_failure: return NULL; } -static struct nl80211_msg_conveyor * nl80211_send( - struct nl80211_msg_conveyor *cv, - int (*cb_func)(struct nl_msg *, void *), void *cb_arg -) { +static int nl80211_send(struct nl80211_msg_conveyor *cv, + int (*cb_func)(struct nl_msg *, void *), + void *cb_arg) +{ static struct nl80211_msg_conveyor rcv; int err = 1; @@ -381,8 +381,10 @@ static struct nl80211_msg_conveyor * nl80211_send( else 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) - goto err; + err = nl_send_auto_complete(nls->nl_sock, cv->msg); + + if (err < 0) + goto out; 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); @@ -391,13 +393,8 @@ static struct nl80211_msg_conveyor * nl80211_send( while (err > 0) nl_recvmsgs(nls->nl_sock, cv->cb); - return &rcv; - -err: - nl_cb_put(cv->cb); - nlmsg_free(cv->msg); - - return NULL; +out: + return err; } static struct nlattr ** nl80211_parse(struct nl_msg *msg)