net: add phys ID compare helper to test if two IDs are the same
authorScott Feldman <sfeldma@gmail.com>
Sun, 19 Jul 2015 01:24:49 +0000 (18:24 -0700)
committerDavid S. Miller <davem@davemloft.net>
Tue, 21 Jul 2015 01:32:44 +0000 (18:32 -0700)
Signed-off-by: Scott Feldman <sfeldma@gmail.com>
Acked-by: Jiri Pirko <jiri@resnulli.us>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/netdevice.h
net/switchdev/switchdev.c

index 8364f29e08be2b9d0d46a5ef5aa6de6ade9b5613..607b5f41f46f93e506adbefd7b3ed11ed8acfb67 100644 (file)
@@ -766,6 +766,13 @@ struct netdev_phys_item_id {
        unsigned char id_len;
 };
 
+static inline bool netdev_phys_item_id_same(struct netdev_phys_item_id *a,
+                                           struct netdev_phys_item_id *b)
+{
+       return a->id_len == b->id_len &&
+              memcmp(a->id, b->id, a->id_len) == 0;
+}
+
 typedef u16 (*select_queue_fallback_t)(struct net_device *dev,
                                       struct sk_buff *skb);
 
index 9f2add3cba26e54eadc15aeea05c3db167a75665..4e5bba50ccffaf1b7741876fcff5a12630094836 100644 (file)
@@ -910,13 +910,9 @@ static struct net_device *switchdev_get_dev_by_nhs(struct fib_info *fi)
                if (switchdev_port_attr_get(dev, &attr))
                        return NULL;
 
-               if (nhsel > 0) {
-                       if (prev_attr.u.ppid.id_len != attr.u.ppid.id_len)
+               if (nhsel > 0 &&
+                   !netdev_phys_item_id_same(&prev_attr.u.ppid, &attr.u.ppid))
                                return NULL;
-                       if (memcmp(prev_attr.u.ppid.id, attr.u.ppid.id,
-                                  attr.u.ppid.id_len))
-                               return NULL;
-               }
 
                prev_attr = attr;
        }