lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 27 Dec 2017 09:57:52 +0200
From:   Leon Romanovsky <leon@...nel.org>
To:     David Ahern <dsahern@...il.com>
Cc:     Leon Romanovsky <leonro@...lanox.com>,
        netdev <netdev@...r.kernel.org>,
        Stephen Hemminger <stephen@...workplumber.org>
Subject: [PATCH iproute2-next 03/10] rdma: Move per-device handler function to generic code

From: Leon Romanovsky <leonro@...lanox.com>

Most of the proposed objects are working in the scope "dev"
and will implement the same logic. Move the code to utils.c,
so other objects will be able to reuse the code.

Signed-off-by: Leon Romanovsky <leonro@...lanox.com>
---
 rdma/dev.c   | 28 +---------------------------
 rdma/rdma.h  |  1 +
 rdma/utils.c | 31 +++++++++++++++++++++++++++++++
 3 files changed, 33 insertions(+), 27 deletions(-)

diff --git a/rdma/dev.c b/rdma/dev.c
index 9fadf3ac..03ab8683 100644
--- a/rdma/dev.c
+++ b/rdma/dev.c
@@ -241,33 +241,7 @@ static int dev_one_show(struct rd *rd)
 
 static int dev_show(struct rd *rd)
 {
-	struct dev_map *dev_map;
-	int ret = 0;
-
-	if (rd->json_output)
-		jsonw_start_array(rd->jw);
-	if (rd_no_arg(rd)) {
-		list_for_each_entry(dev_map, &rd->dev_map_list, list) {
-			rd->dev_idx = dev_map->idx;
-			ret = dev_one_show(rd);
-			if (ret)
-				goto out;
-		}
-	} else {
-		dev_map = dev_map_lookup(rd, false);
-		if (!dev_map) {
-			pr_err("Wrong device name\n");
-			ret = -ENOENT;
-			goto out;
-		}
-		rd_arg_inc(rd);
-		rd->dev_idx = dev_map->idx;
-		ret = dev_one_show(rd);
-	}
-out:
-	if (rd->json_output)
-		jsonw_end_array(rd->jw);
-	return ret;
+	return rd_exec_dev(rd, dev_one_show);
 }
 
 int cmd_dev(struct rd *rd)
diff --git a/rdma/rdma.h b/rdma/rdma.h
index c07493c9..b85e3748 100644
--- a/rdma/rdma.h
+++ b/rdma/rdma.h
@@ -72,6 +72,7 @@ uint32_t get_port_from_argv(struct rd *rd);
 int cmd_dev(struct rd *rd);
 int cmd_link(struct rd *rd);
 int rd_exec_cmd(struct rd *rd, const struct rd_cmd *c, const char *str);
+int rd_exec_dev(struct rd *rd, int (*cb)(struct rd *rd));
 
 /*
  * Device manipulation
diff --git a/rdma/utils.c b/rdma/utils.c
index bb29fa1a..5c0f021a 100644
--- a/rdma/utils.c
+++ b/rdma/utils.c
@@ -159,6 +159,37 @@ void rd_free_devmap(struct rd *rd)
 	dev_map_cleanup(rd);
 }
 
+int rd_exec_dev(struct rd *rd, int (*cb)(struct rd *rd))
+{
+	struct dev_map *dev_map;
+	int ret = 0;
+
+	if (rd->json_output)
+		jsonw_start_array(rd->jw);
+	if (rd_no_arg(rd)) {
+		list_for_each_entry(dev_map, &rd->dev_map_list, list) {
+			rd->dev_idx = dev_map->idx;
+			ret = cb(rd);
+			if (ret)
+				goto out;
+		}
+	} else {
+		dev_map = dev_map_lookup(rd, false);
+		if (!dev_map) {
+			pr_err("Wrong device name\n");
+			ret = -ENOENT;
+			goto out;
+		}
+		rd_arg_inc(rd);
+		rd->dev_idx = dev_map->idx;
+		ret = cb(rd);
+	}
+out:
+	if (rd->json_output)
+		jsonw_end_array(rd->jw);
+	return ret;
+}
+
 int rd_exec_cmd(struct rd *rd, const struct rd_cmd *cmds, const char *str)
 {
 	const struct rd_cmd *c;
-- 
2.15.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ