Thread (3 messages) 3 messages, 2 authors, 2013-07-02

Re: [PATCH v1 net-next] net: Add phys_port identifier to struct net_device and export it to sysfs

From: Ben Hutchings <hidden>
Date: 2013-07-01 20:12:26

On Fri, 2013-06-28 at 20:57 +0530, Narendra_K@Dell.com wrote:
[...]
quoted hunk ↗ jump to hunk
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -1062,6 +1062,14 @@ struct net_device_ops {
 						      bool new_carrier);
 };
 
+/* This structure holds a universally unique identifier to
+ * identify the physical port used by a netdevice
+ */
+struct port_identifier {
+	unsigned char port_id[MAX_ADDR_LEN];
+	unsigned port_id_len;
Was this meant to be unsigned (int) or unsigned char?  The length is
typed as unsigned char in show_phys_port().
+};
[...]
quoted hunk ↗ jump to hunk
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -334,6 +334,27 @@ static ssize_t store_group(struct device *dev, struct device_attribute *attr,
 	return netdev_store(dev, attr, buf, len, change_group);
 }
 
+static ssize_t show_phys_port(struct device *dev,
+			      struct device_attribute *attr, char *buf)
+{
+	struct net_device *net = to_net_dev(dev);
+	ssize_t ret = -EINVAL;
+	unsigned char len;
+
+	read_lock(&dev_base_lock);
+	if (dev_isalive(net)) {
+		len = net->phys_port.port_id_len;
+		if (!len) {
+			read_unlock(&dev_base_lock);
+			return 0;
+		}
I would write this as:
		if (!len)
			ret = 0;
		else
so that the same exit path is used in all three cases.

Ben.
+		ret = sysfs_format_mac(buf, net->phys_port.port_id, len);
+	}
+	read_unlock(&dev_base_lock);
+
+	return ret;
+}
[...]

-- 
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help