linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH internal net-next 0/2] Minor refactor in devlink
@ 2019-08-30  4:10 Parav Pandit
  2019-08-30  4:10 ` [PATCH internal net-next 1/2] devlink: Make port index data type as unsigned int Parav Pandit
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Parav Pandit @ 2019-08-30  4:10 UTC (permalink / raw)
  To: linux-kernel, jiri; +Cc: Parav Pandit

Two minor refactors in devlink.

Patch-1 Explicitly defines devlink port index as unsigned int
Patch-2 Uses switch-case to handle different port flavours attributes

Parav Pandit (2):
  devlink: Make port index data type as unsigned int
  devlink: Use switch-case instead of if-else

 include/net/devlink.h |  2 +-
 net/core/devlink.c    | 44 ++++++++++++++++++++++++-------------------
 2 files changed, 26 insertions(+), 20 deletions(-)

-- 
2.19.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH internal net-next 1/2] devlink: Make port index data type as unsigned int
  2019-08-30  4:10 [PATCH internal net-next 0/2] Minor refactor in devlink Parav Pandit
@ 2019-08-30  4:10 ` Parav Pandit
  2019-08-30  4:10 ` [PATCH internal net-next 2/2] devlink: Use switch-case instead of if-else Parav Pandit
  2019-08-30  4:13 ` [PATCH internal net-next 0/2] Minor refactor in devlink Parav Pandit
  2 siblings, 0 replies; 4+ messages in thread
From: Parav Pandit @ 2019-08-30  4:10 UTC (permalink / raw)
  To: linux-kernel, jiri; +Cc: Parav Pandit

Devlink port index attribute is returned to users as u32 through
netlink response.
Change index data type from 'unsigned' to 'unsigned int' to avoid any
size ambiguity and to avoid below checkpatch.pl warning.

WARNING: Prefer 'unsigned int' to bare use of 'unsigned'
81: FILE: include/net/devlink.h:81:
+       unsigned index;

Signed-off-by: Parav Pandit <parav@mellanox.com>
---
 include/net/devlink.h | 2 +-
 net/core/devlink.c    | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/include/net/devlink.h b/include/net/devlink.h
index 7f43c48f54cd..13523b0a0642 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -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.
diff --git a/net/core/devlink.c b/net/core/devlink.c
index 650f36379203..b7091329987a 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -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);
 }
-- 
2.19.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH internal net-next 2/2] devlink: Use switch-case instead of if-else
  2019-08-30  4:10 [PATCH internal net-next 0/2] Minor refactor in devlink Parav Pandit
  2019-08-30  4:10 ` [PATCH internal net-next 1/2] devlink: Make port index data type as unsigned int Parav Pandit
@ 2019-08-30  4:10 ` Parav Pandit
  2019-08-30  4:13 ` [PATCH internal net-next 0/2] Minor refactor in devlink Parav Pandit
  2 siblings, 0 replies; 4+ messages in thread
From: Parav Pandit @ 2019-08-30  4:10 UTC (permalink / raw)
  To: linux-kernel, jiri; +Cc: Parav Pandit

Make core more readable with switch-case for various port flavours.

Signed-off-by: Parav Pandit <parav@mellanox.com>
---
 net/core/devlink.c | 39 ++++++++++++++++++++++-----------------
 1 file changed, 22 insertions(+), 17 deletions(-)

diff --git a/net/core/devlink.c b/net/core/devlink.c
index b7091329987a..6e52d639dac6 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -510,32 +510,37 @@ 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;
+		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;
+		if (!attrs->split)
+			return 0;
+		if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_GROUP,
+				attrs->phys.port_number))
+			return -EMSGSIZE;
+		if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_SUBPORT_NUMBER,
+				attrs->phys.split_subport_number))
+			return -EMSGSIZE;
+		break;
+	default:
+		break;
 	}
-	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;
-	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER,
-			attrs->phys.port_number))
-		return -EMSGSIZE;
-	if (!attrs->split)
-		return 0;
-	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_GROUP,
-			attrs->phys.port_number))
-		return -EMSGSIZE;
-	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_SUBPORT_NUMBER,
-			attrs->phys.split_subport_number))
-		return -EMSGSIZE;
 	return 0;
 }
 
-- 
2.19.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* RE: [PATCH internal net-next 0/2] Minor refactor in devlink
  2019-08-30  4:10 [PATCH internal net-next 0/2] Minor refactor in devlink Parav Pandit
  2019-08-30  4:10 ` [PATCH internal net-next 1/2] devlink: Make port index data type as unsigned int Parav Pandit
  2019-08-30  4:10 ` [PATCH internal net-next 2/2] devlink: Use switch-case instead of if-else Parav Pandit
@ 2019-08-30  4:13 ` Parav Pandit
  2 siblings, 0 replies; 4+ messages in thread
From: Parav Pandit @ 2019-08-30  4:13 UTC (permalink / raw)
  To: Parav Pandit, linux-kernel, Jiri Pirko



> -----Original Message-----
> From: linux-kernel-owner@vger.kernel.org <linux-kernel-
> owner@vger.kernel.org> On Behalf Of Parav Pandit
> Sent: Friday, August 30, 2019 9:41 AM
> To: linux-kernel@vger.kernel.org; Jiri Pirko <jiri@mellanox.com>
> Cc: Parav Pandit <parav@mellanox.com>
> Subject: [PATCH internal net-next 0/2] Minor refactor in devlink
> 
> Two minor refactors in devlink.
> 
> Patch-1 Explicitly defines devlink port index as unsigned int
> Patch-2 Uses switch-case to handle different port flavours attributes
> 
> Parav Pandit (2):
>   devlink: Make port index data type as unsigned int
>   devlink: Use switch-case instead of if-else
> 
>  include/net/devlink.h |  2 +-
>  net/core/devlink.c    | 44 ++++++++++++++++++++++++-------------------
>  2 files changed, 26 insertions(+), 20 deletions(-)
> 
> --
> 2.19.2

I am sorry for noise.
By mistake send to wrong list.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-08-30  4:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-30  4:10 [PATCH internal net-next 0/2] Minor refactor in devlink Parav Pandit
2019-08-30  4:10 ` [PATCH internal net-next 1/2] devlink: Make port index data type as unsigned int Parav Pandit
2019-08-30  4:10 ` [PATCH internal net-next 2/2] devlink: Use switch-case instead of if-else Parav Pandit
2019-08-30  4:13 ` [PATCH internal net-next 0/2] Minor refactor in devlink Parav Pandit

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).