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

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
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ struct devlink_port {
	struct list_head list;
	struct list_head param_list;
	struct devlink *devlink;
	unsigned index;
	unsigned int index;
	bool registered;
	spinlock_t type_lock; /* Protects type and type_dev
			       * pointer consistency.
+25 −19
Original line number Diff line number Diff line
@@ -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,
						      int port_index)
						      unsigned int port_index)
{
	struct devlink_port *devlink_port;

@@ -147,7 +147,8 @@ static struct devlink_port *devlink_port_get_by_index(struct devlink *devlink,
	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);
}
@@ -509,21 +510,22 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg,
		return 0;
	if (nla_put_u16(msg, DEVLINK_ATTR_PORT_FLAVOUR, attrs->flavour))
		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,
				attrs->pci_pf.pf))
			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,
				attrs->pci_vf.pf) ||
		    nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_VF_NUMBER,
				attrs->pci_vf.vf))
			return -EMSGSIZE;
	}
	if (devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_PHYSICAL &&
	    devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_CPU &&
	    devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_DSA)
		return 0;
		break;
	case DEVLINK_PORT_FLAVOUR_PHYSICAL:
	case DEVLINK_PORT_FLAVOUR_CPU:
	case DEVLINK_PORT_FLAVOUR_DSA:
		if (nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER,
				attrs->phys.port_number))
			return -EMSGSIZE;
@@ -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,
				attrs->phys.split_subport_number))
			return -EMSGSIZE;
		break;
	default:
		break;
	}
	return 0;
}