Skip to content

Commit

Permalink
devlink: move linecard struct into linecard.c
Browse files Browse the repository at this point in the history
Instead of exposing linecard struct, expose a simple helper to get the
linecard index, which is all is needed outside linecard.c. Move the
linecard struct to linecard.c and keep it private similar to the rest of
the devlink objects.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jiri Pirko authored and David S. Miller committed Sep 17, 2023
1 parent 1e73cfe commit d0b7e99
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
14 changes: 1 addition & 13 deletions net/devlink/devl_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,19 +206,7 @@ int devlink_rate_nodes_check(struct devlink *devlink, u16 mode,
struct netlink_ext_ack *extack);

/* Linecards */
struct devlink_linecard {
struct list_head list;
struct devlink *devlink;
unsigned int index;
const struct devlink_linecard_ops *ops;
void *priv;
enum devlink_linecard_state state;
struct mutex state_lock; /* Protects state */
const char *type;
struct devlink_linecard_type *types;
unsigned int types_count;
struct devlink *nested_devlink;
};
unsigned int devlink_linecard_index(struct devlink_linecard *linecard);

/* Devlink nl cmds */
int devlink_nl_cmd_reload(struct sk_buff *skb, struct genl_info *info);
Expand Down
19 changes: 19 additions & 0 deletions net/devlink/linecard.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@

#include "devl_internal.h"

struct devlink_linecard {
struct list_head list;
struct devlink *devlink;
unsigned int index;
const struct devlink_linecard_ops *ops;
void *priv;
enum devlink_linecard_state state;
struct mutex state_lock; /* Protects state */
const char *type;
struct devlink_linecard_type *types;
unsigned int types_count;
struct devlink *nested_devlink;
};

unsigned int devlink_linecard_index(struct devlink_linecard *linecard)
{
return linecard->index;
}

static struct devlink_linecard *
devlink_linecard_get_by_index(struct devlink *devlink,
unsigned int linecard_index)
Expand Down
4 changes: 2 additions & 2 deletions net/devlink/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ static int devlink_nl_port_fill(struct sk_buff *msg,
goto nla_put_failure;
if (devlink_port->linecard &&
nla_put_u32(msg, DEVLINK_ATTR_LINECARD_INDEX,
devlink_port->linecard->index))
devlink_linecard_index(devlink_port->linecard)))
goto nla_put_failure;

genlmsg_end(msg, hdr);
Expand Down Expand Up @@ -1420,7 +1420,7 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
case DEVLINK_PORT_FLAVOUR_PHYSICAL:
if (devlink_port->linecard)
n = snprintf(name, len, "l%u",
devlink_port->linecard->index);
devlink_linecard_index(devlink_port->linecard));
if (n < len)
n += snprintf(name + n, len - n, "p%u",
attrs->phys.port_number);
Expand Down

0 comments on commit d0b7e99

Please sign in to comment.