Skip to content

Commit

Permalink
net: devlink: introduce port registered assert helper and use it
Browse files Browse the repository at this point in the history
Instead of checking devlink_port->devlink pointer for not being NULL
which indicates that devlink port is registered, put this check to new
pair of helpers similar to what we have for devlink and use them in
other functions.

Signed-off-by: Jiri Pirko <[email protected]>
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
Jiri Pirko authored and kuba-moo committed Oct 1, 2022
1 parent 3406079 commit 3fcb698
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions net/core/devlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,11 @@ static struct devlink *devlink_get_from_attrs(struct net *net,
return ERR_PTR(-ENODEV);
}

#define ASSERT_DEVLINK_PORT_REGISTERED(devlink_port) \
WARN_ON_ONCE(!(devlink_port)->devlink)
#define ASSERT_DEVLINK_PORT_NOT_REGISTERED(devlink_port) \
WARN_ON_ONCE((devlink_port)->devlink)

static struct devlink_port *devlink_port_get_by_index(struct devlink *devlink,
unsigned int port_index)
{
Expand Down Expand Up @@ -9869,7 +9874,8 @@ int devl_port_register(struct devlink *devlink,
if (devlink_port_index_exists(devlink, port_index))
return -EEXIST;

WARN_ON(devlink_port->devlink);
ASSERT_DEVLINK_PORT_NOT_REGISTERED(devlink_port);

devlink_port->devlink = devlink;
devlink_port->index = port_index;
spin_lock_init(&devlink_port->type_lock);
Expand Down Expand Up @@ -9952,8 +9958,8 @@ static void __devlink_port_type_set(struct devlink_port *devlink_port,
enum devlink_port_type type,
void *type_dev)
{
if (WARN_ON(!devlink_port->devlink))
return;
ASSERT_DEVLINK_PORT_REGISTERED(devlink_port);

devlink_port_type_warn_cancel(devlink_port);
spin_lock_bh(&devlink_port->type_lock);
devlink_port->type = type;
Expand Down Expand Up @@ -10072,8 +10078,8 @@ void devlink_port_attrs_set(struct devlink_port *devlink_port,
{
int ret;

if (WARN_ON(devlink_port->devlink))
return;
ASSERT_DEVLINK_PORT_NOT_REGISTERED(devlink_port);

devlink_port->attrs = *attrs;
ret = __devlink_port_attrs_set(devlink_port, attrs->flavour);
if (ret)
Expand All @@ -10096,8 +10102,8 @@ void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port, u32 contro
struct devlink_port_attrs *attrs = &devlink_port->attrs;
int ret;

if (WARN_ON(devlink_port->devlink))
return;
ASSERT_DEVLINK_PORT_NOT_REGISTERED(devlink_port);

ret = __devlink_port_attrs_set(devlink_port,
DEVLINK_PORT_FLAVOUR_PCI_PF);
if (ret)
Expand All @@ -10123,8 +10129,8 @@ void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, u32 contro
struct devlink_port_attrs *attrs = &devlink_port->attrs;
int ret;

if (WARN_ON(devlink_port->devlink))
return;
ASSERT_DEVLINK_PORT_NOT_REGISTERED(devlink_port);

ret = __devlink_port_attrs_set(devlink_port,
DEVLINK_PORT_FLAVOUR_PCI_VF);
if (ret)
Expand All @@ -10151,8 +10157,8 @@ void devlink_port_attrs_pci_sf_set(struct devlink_port *devlink_port, u32 contro
struct devlink_port_attrs *attrs = &devlink_port->attrs;
int ret;

if (WARN_ON(devlink_port->devlink))
return;
ASSERT_DEVLINK_PORT_NOT_REGISTERED(devlink_port);

ret = __devlink_port_attrs_set(devlink_port,
DEVLINK_PORT_FLAVOUR_PCI_SF);
if (ret)
Expand Down Expand Up @@ -10267,8 +10273,8 @@ EXPORT_SYMBOL_GPL(devl_rate_nodes_destroy);
void devlink_port_linecard_set(struct devlink_port *devlink_port,
struct devlink_linecard *linecard)
{
if (WARN_ON(devlink_port->devlink))
return;
ASSERT_DEVLINK_PORT_NOT_REGISTERED(devlink_port);

devlink_port->linecard = linecard;
}
EXPORT_SYMBOL_GPL(devlink_port_linecard_set);
Expand Down

0 comments on commit 3fcb698

Please sign in to comment.