mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Leon Romanovsky <leon@kernel.org>
To: "David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>
Cc: Leon Romanovsky <leonro@nvidia.com>,
	Ido Schimmel <idosch@nvidia.com>, Jiri Pirko <jiri@nvidia.com>,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCH net-next 1/6] devlink: Clean registration of devlink port
Date: Sun,  5 Dec 2021 10:22:01 +0200	[thread overview]
Message-ID: <f3ce2879f0f16dbbf9c320aa6c225e1a6a23d2c0.1638690564.git.leonro@nvidia.com> (raw)
In-Reply-To: <cover.1638690564.git.leonro@nvidia.com>

From: Leon Romanovsky <leonro@nvidia.com>

devlink_port_register() is in-kernel API and as such can't really
fail as long as driver author didn't make a mistake by providing
already existing port index.

Instead of relying on various error prints from the driver, convert
the existence check to be WARN_ON(), so such a mistake will be caught
immediately.

Tested-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
 net/core/devlink.c | 23 ++++++++---------------
 1 file changed, 8 insertions(+), 15 deletions(-)

diff --git a/net/core/devlink.c b/net/core/devlink.c
index db3b52110cf2..34d0f623b2a9 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -268,12 +268,6 @@ static struct devlink_port *devlink_port_get_by_index(struct devlink *devlink,
 	return NULL;
 }
 
-static bool devlink_port_index_exists(struct devlink *devlink,
-				      unsigned int port_index)
-{
-	return devlink_port_get_by_index(devlink, port_index);
-}
-
 static struct devlink_port *devlink_port_get_from_attrs(struct devlink *devlink,
 							struct nlattr **attrs)
 {
@@ -9255,25 +9249,24 @@ int devlink_port_register(struct devlink *devlink,
 			  struct devlink_port *devlink_port,
 			  unsigned int port_index)
 {
-	mutex_lock(&devlink->lock);
-	if (devlink_port_index_exists(devlink, port_index)) {
-		mutex_unlock(&devlink->lock);
-		return -EEXIST;
-	}
-
+	WARN_ON(devlink_port_get_by_index(devlink, port_index));
 	WARN_ON(devlink_port->devlink);
+
 	devlink_port->devlink = devlink;
 	devlink_port->index = port_index;
 	spin_lock_init(&devlink_port->type_lock);
 	INIT_LIST_HEAD(&devlink_port->reporter_list);
 	mutex_init(&devlink_port->reporters_lock);
-	list_add_tail(&devlink_port->list, &devlink->port_list);
 	INIT_LIST_HEAD(&devlink_port->param_list);
 	INIT_LIST_HEAD(&devlink_port->region_list);
-	mutex_unlock(&devlink->lock);
 	INIT_DELAYED_WORK(&devlink_port->type_warn_dw, &devlink_port_type_warn);
-	devlink_port_type_warn_schedule(devlink_port);
+
+	mutex_lock(&devlink->lock);
+	list_add_tail(&devlink_port->list, &devlink->port_list);
+	mutex_unlock(&devlink->lock);
+
 	devlink_port_notify(devlink_port, DEVLINK_CMD_PORT_NEW);
+	devlink_port_type_warn_schedule(devlink_port);
 	return 0;
 }
 EXPORT_SYMBOL_GPL(devlink_port_register);
-- 
2.33.1


  reply	other threads:[~2021-12-05  8:22 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-05  8:22 [PATCH net-next 0/6] Allow parallel devlink execution Leon Romanovsky
2021-12-05  8:22 ` Leon Romanovsky [this message]
2021-12-05  8:22 ` [PATCH net-next 2/6] devlink: Be explicit with devlink port protection Leon Romanovsky
2021-12-05  8:22 ` [PATCH net-next 3/6] devlink: Add devlink nested locking primitive Leon Romanovsky
2021-12-05  8:22 ` [PATCH net-next 4/6] devlink: Require devlink lock during device reload Leon Romanovsky
2021-12-05  8:22 ` [PATCH net-next 5/6] devlink: Use xarray locking mechanism instead big devlink lock Leon Romanovsky
2021-12-05  8:22 ` [PATCH net-next 6/6] devlink: Open devlink to parallel operations Leon Romanovsky
2021-12-07  2:00 ` [PATCH net-next 0/6] Allow parallel devlink execution Jakub Kicinski
2021-12-07  7:29   ` Leon Romanovsky
2021-12-08  4:21     ` Jakub Kicinski
2021-12-08  7:54       ` Leon Romanovsky
2021-12-08 15:15         ` Jakub Kicinski
2021-12-08 19:38           ` Leon Romanovsky

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=f3ce2879f0f16dbbf9c320aa6c225e1a6a23d2c0.1638690564.git.leonro@nvidia.com \
    --to=leon@kernel.org \
    --cc=davem@davemloft.net \
    --cc=idosch@nvidia.com \
    --cc=jiri@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=leonro@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --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

all inboxes | Powered by JetHome®