[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <f3ce2879f0f16dbbf9c320aa6c225e1a6a23d2c0.1638690564.git.leonro@nvidia.com>
Date: Sun, 5 Dec 2021 10:22:01 +0200
From: Leon Romanovsky <leon@...nel.org>
To: "David S . Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>
Cc: Leon Romanovsky <leonro@...dia.com>,
Ido Schimmel <idosch@...dia.com>, Jiri Pirko <jiri@...dia.com>,
linux-kernel@...r.kernel.org, netdev@...r.kernel.org
Subject: [PATCH net-next 1/6] devlink: Clean registration of devlink port
From: Leon Romanovsky <leonro@...dia.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@...dia.com>
Signed-off-by: Leon Romanovsky <leonro@...dia.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
Powered by blists - more mailing lists