Commit 38320f69 authored by David S. Miller's avatar David S. Miller

Merge branch 'Minor-cleanup-in-devlink'

Parav Pandit says:

====================
Minor cleanup in devlink

Two minor cleanup in devlink.

Patch-1 Explicitly defines devlink port index as unsigned int
Patch-2 Uses switch-case to handle different port flavours attributes
====================
Acked-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 1b6ca07b 58b6be41
...@@ -75,7 +75,7 @@ struct devlink_port { ...@@ -75,7 +75,7 @@ struct devlink_port {
struct list_head list; struct list_head list;
struct list_head param_list; struct list_head param_list;
struct devlink *devlink; struct devlink *devlink;
unsigned index; unsigned int index;
bool registered; bool registered;
spinlock_t type_lock; /* Protects type and type_dev spinlock_t type_lock; /* Protects type and type_dev
* pointer consistency. * pointer consistency.
......
...@@ -136,7 +136,7 @@ static struct devlink *devlink_get_from_info(struct genl_info *info) ...@@ -136,7 +136,7 @@ static struct devlink *devlink_get_from_info(struct genl_info *info)
} }
static struct devlink_port *devlink_port_get_by_index(struct devlink *devlink, static struct devlink_port *devlink_port_get_by_index(struct devlink *devlink,
int port_index) unsigned int port_index)
{ {
struct devlink_port *devlink_port; struct devlink_port *devlink_port;
...@@ -147,7 +147,8 @@ static struct devlink_port *devlink_port_get_by_index(struct devlink *devlink, ...@@ -147,7 +147,8 @@ static struct devlink_port *devlink_port_get_by_index(struct devlink *devlink,
return NULL; return NULL;
} }
static bool devlink_port_index_exists(struct devlink *devlink, int port_index) static bool devlink_port_index_exists(struct devlink *devlink,
unsigned int port_index)
{ {
return devlink_port_get_by_index(devlink, port_index); return devlink_port_get_by_index(devlink, port_index);
} }
...@@ -509,21 +510,22 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg, ...@@ -509,21 +510,22 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg,
return 0; return 0;
if (nla_put_u16(msg, DEVLINK_ATTR_PORT_FLAVOUR, attrs->flavour)) if (nla_put_u16(msg, DEVLINK_ATTR_PORT_FLAVOUR, attrs->flavour))
return -EMSGSIZE; return -EMSGSIZE;
if (devlink_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_PCI_PF) { switch (devlink_port->attrs.flavour) {
case DEVLINK_PORT_FLAVOUR_PCI_PF:
if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER, if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
attrs->pci_pf.pf)) attrs->pci_pf.pf))
return -EMSGSIZE; return -EMSGSIZE;
} else if (devlink_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_PCI_VF) { break;
case DEVLINK_PORT_FLAVOUR_PCI_VF:
if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER, if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
attrs->pci_vf.pf) || attrs->pci_vf.pf) ||
nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_VF_NUMBER, nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_VF_NUMBER,
attrs->pci_vf.vf)) attrs->pci_vf.vf))
return -EMSGSIZE; return -EMSGSIZE;
} break;
if (devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_PHYSICAL && case DEVLINK_PORT_FLAVOUR_PHYSICAL:
devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_CPU && case DEVLINK_PORT_FLAVOUR_CPU:
devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_DSA) case DEVLINK_PORT_FLAVOUR_DSA:
return 0;
if (nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER, if (nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER,
attrs->phys.port_number)) attrs->phys.port_number))
return -EMSGSIZE; return -EMSGSIZE;
...@@ -535,6 +537,10 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg, ...@@ -535,6 +537,10 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg,
if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_SUBPORT_NUMBER, if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_SUBPORT_NUMBER,
attrs->phys.split_subport_number)) attrs->phys.split_subport_number))
return -EMSGSIZE; return -EMSGSIZE;
break;
default:
break;
}
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment