diff mbox series

[21/27] lnet: simplify lnet_ni_add_interface

Message ID 1623625897-17706-22-git-send-email-jsimmons@infradead.org (mailing list archive)
State New, archived
Headers show
Series lustre: sync to 2.14.52 | expand

Commit Message

James Simmons June 13, 2021, 11:11 p.m. UTC
From: Olaf Faaland <faaland1@llnl.gov>

Remove an unnecessary counter and move the comment before
the relevant code.  Improve error messages.

WC-bug-id: https://jira.whamcloud.com/browse/LU-14665
Lustre-commit: b77a6d86936c32bb ("LU-14665 lnet: simplify lnet_ni_add_interface")
Signed-off-by: Olaf Faaland <faaland1@llnl.gov>
Reviewed-on: https://review.whamcloud.com/43525
Reviewed-by: Serguei Smirnov <ssmirnov@whamcloud.com>
Reviewed-by: Neil Brown <neilb@suse.de>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Signed-off-by: James Simmons <jsimmons@infradead.org>
---
 net/lnet/lnet/config.c | 27 +++++++++++----------------
 1 file changed, 11 insertions(+), 16 deletions(-)
diff mbox series

Patch

diff --git a/net/lnet/lnet/config.c b/net/lnet/lnet/config.c
index 5f4b90b..0117611 100644
--- a/net/lnet/lnet/config.c
+++ b/net/lnet/lnet/config.c
@@ -369,31 +369,26 @@  struct lnet_net *
 static int
 lnet_ni_add_interface(struct lnet_ni *ni, char *iface)
 {
-	int niface = 0;
-
 	if (!ni)
 		return -ENOMEM;
 
-	/* Allocate a separate piece of memory and copy
-	 * into it the string, so we don't have
-	 * a depencency on the tokens string.  This way we
-	 * can free the tokens at the end of the function.
-	 * The newly allocated ni_interface[] can be
-	 * freed when freeing the NI */
-	if (ni->ni_interface)
-		niface++;
-
-	if (niface >= 1) {
-		LCONSOLE_ERROR_MSG(0x115, "Too many interfaces "
-				   "for net %s\n",
-				   libcfs_net2str(LNET_NIDNET(ni->ni_nid)));
+	if (ni->ni_interface) {
+		LCONSOLE_ERROR_MSG(0x115, "%s: interface %s already set for net %s: rc = %d\n",
+				   iface, ni->ni_interface,
+				   libcfs_net2str(LNET_NIDNET(ni->ni_nid)),
+				   -EINVAL);
 		return -EINVAL;
 	}
 
+	/* Allocate memory for the interface, so the code parsing input into
+	 * tokens and adding interfaces can free the input safely.
+	 * ni->ni_interface is freed in lnet_ni_free().
+	 */
 	ni->ni_interface = kstrdup(iface, GFP_KERNEL);
 
 	if (!ni->ni_interface) {
-		CERROR("Can't allocate net interface name\n");
+		CERROR("%s: cannot allocate net interface name: rc = %d\n",
+		       iface, -ENOMEM);
 		return -ENOMEM;
 	}