From 52cd3c14ce42db53637f8f5dafaf0d5c24d724db Mon Sep 17 00:00:00 2001
From: Thomas Haller <thaller@redhat.com>
Date: Mon, 8 Oct 2018 13:41:25 +0200
Subject: [PATCH 62/76] lib/tc: ensure correct error code in
 rtnl_tc_msg_build()

---
 lib/route/tc.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/lib/route/tc.c b/lib/route/tc.c
index 62efd35..061e54e 100644
--- a/lib/route/tc.c
+++ b/lib/route/tc.c
@@ -202,14 +202,16 @@ int rtnl_tc_msg_build(struct rtnl_tc *tc, int type, int flags,
 		.tcm_handle = tc->tc_handle,
 		.tcm_parent = tc->tc_parent,
 	};
-	int err = -NLE_MSGSIZE;
+	int err;
 
 	msg = nlmsg_alloc_simple(type, flags);
 	if (!msg)
 		return -NLE_NOMEM;
 
-	if (nlmsg_append(msg, &tchdr, sizeof(tchdr), NLMSG_ALIGNTO) < 0)
+	if (nlmsg_append(msg, &tchdr, sizeof(tchdr), NLMSG_ALIGNTO) < 0) {
+		err = -NLE_MSGSIZE;
 		goto nla_put_failure;
+	}
 
 	if (tc->ce_mask & TCA_ATTR_KIND)
 	    NLA_PUT_STRING(msg, TCA_KIND, tc->tc_kind);
@@ -220,8 +222,10 @@ int rtnl_tc_msg_build(struct rtnl_tc *tc, int type, int flags,
 		void *data = rtnl_tc_data(tc);
 
 		if (ops->to_msg_fill) {
-			if (!(opts = nla_nest_start(msg, TCA_OPTIONS)))
+			if (!(opts = nla_nest_start(msg, TCA_OPTIONS))) {
+				err = -NLE_NOMEM;
 				goto nla_put_failure;
+			}
 
 			if ((err = ops->to_msg_fill(tc, data, msg)) < 0)
 				goto nla_put_failure;
-- 
1.8.3.1

