netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vlad Buslov <vladbu@mellanox.com>
To: netdev@vger.kernel.org
Cc: chrism@mellanox.com, Vlad Buslov <vladbu@mellanox.com>
Subject: [PATCH] tc: fix batch force option
Date: Wed, 20 Jun 2018 10:24:21 +0300	[thread overview]
Message-ID: <1529479461-32048-1-git-send-email-vladbu@mellanox.com> (raw)

When sending accumulated compound command results an error, check 'force'
option before exiting. Move return code check after putting batch bufs and
freeing iovs to prevent memory leak. Break from loop, instead of returning
error code to allow cleanup at the end of batch function. Don't reset ret
code on each iteration.

Fixes: 485d0c6001c4 ("tc: Add batchsize feature for filter and actions")
Reviewed-by: Roi Dayan <roid@mellanox.com>
Reviewed-by: Chris Mi <chrism@mellanox.com>
Signed-off-by: Vlad Buslov <vladbu@mellanox.com>
---
 tc/tc.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/tc/tc.c b/tc/tc.c
index 0d223281ba25..62d54186ec66 100644
--- a/tc/tc.c
+++ b/tc/tc.c
@@ -331,6 +331,7 @@ static int batch(const char *name)
 	int batchsize = 0;
 	size_t len = 0;
 	int ret = 0;
+	int err;
 	bool send;
 
 	batch_mode = 1;
@@ -399,9 +400,9 @@ static int batch(const char *name)
 			continue;	/* blank line */
 		}
 
-		ret = do_cmd(largc, largv, tail == NULL ? NULL : tail->buf,
+		err = do_cmd(largc, largv, tail == NULL ? NULL : tail->buf,
 			     tail == NULL ? 0 : sizeof(tail->buf));
-		if (ret != 0) {
+		if (err != 0) {
 			fprintf(stderr, "Command failed %s:%d\n", name,
 				cmdlineno - 1);
 			ret = 1;
@@ -423,15 +424,17 @@ static int batch(const char *name)
 				iov->iov_len = n->nlmsg_len;
 			}
 
-			ret = rtnl_talk_iov(&rth, iovs, batchsize, NULL);
-			if (ret < 0) {
+			err = rtnl_talk_iov(&rth, iovs, batchsize, NULL);
+			put_batch_bufs(&buf_pool, &head, &tail);
+			free(iovs);
+			if (err < 0) {
 				fprintf(stderr, "Command failed %s:%d\n", name,
-					cmdlineno - (batchsize + ret) - 1);
-				return 2;
+					cmdlineno - (batchsize + err) - 1);
+				ret = 1;
+				if (!force)
+					break;
 			}
-			put_batch_bufs(&buf_pool, &head, &tail);
 			batchsize = 0;
-			free(iovs);
 		}
 	} while (!lastline);
 
-- 
2.7.5

             reply	other threads:[~2018-06-20  9:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-20  7:24 Vlad Buslov [this message]
2018-06-20 16:33 ` [PATCH] tc: fix batch force option Stephen Hemminger

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=1529479461-32048-1-git-send-email-vladbu@mellanox.com \
    --to=vladbu@mellanox.com \
    --cc=chrism@mellanox.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;
as well as URLs for NNTP newsgroup(s).