The data items returned by netdev_get_devices() are "struct netdev *"s.
The code fixed up by this commit used them as "struct netdev_bsd *" or
"struct netdev_linux *", which happens to work because struct netdev
happens to be at offset 0 in each struct but it's better to do a proper
cast in case someday struct netdev gets moved to a nonzero offset.

Signed-off-by: Ben Pfaff <[email protected]>
---
 lib/netdev-bsd.c   |    6 ++++--
 lib/netdev-linux.c |    9 ++++++---
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/lib/netdev-bsd.c b/lib/netdev-bsd.c
index 79643e1..2e49c94 100644
--- a/lib/netdev-bsd.c
+++ b/lib/netdev-bsd.c
@@ -267,7 +267,8 @@ netdev_bsd_cache_cb(const struct rtbsd_change *change,
         shash_init(&device_shash);
         netdev_get_devices(&netdev_bsd_class, &device_shash);
         SHASH_FOR_EACH (node, &device_shash) {
-            dev = node->data;
+            struct netdev *netdev = node->data;
+            dev = netdev_bsd_cast(netdev);
             dev->cache_valid = 0;
             netdev_bsd_changed(dev);
         }
@@ -1208,7 +1209,8 @@ find_netdev_by_kernel_name(const char *kernel_name)
     shash_init(&device_shash);
     netdev_get_devices(&netdev_tap_class, &device_shash);
     SHASH_FOR_EACH(node, &device_shash) {
-        struct netdev_bsd * const dev = node->data;
+        struct netdev *netdev = node->data;
+        struct netdev_bsd * const dev = netdev_bsd_cast(netdev);
 
         if (!strcmp(dev->kernel_name, kernel_name)) {
             shash_destroy(&device_shash);
diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
index 55f676a..29d8ad9 100644
--- a/lib/netdev-linux.c
+++ b/lib/netdev-linux.c
@@ -557,9 +557,10 @@ netdev_linux_cache_cb(const struct rtnetlink_link_change 
*change,
         shash_init(&device_shash);
         netdev_get_devices(&netdev_linux_class, &device_shash);
         SHASH_FOR_EACH (node, &device_shash) {
+            struct netdev *netdev = node->data;
             unsigned int flags;
 
-            dev = node->data;
+            dev = netdev_linux_cast(netdev);
 
             get_flags(&dev->up, &flags);
             netdev_linux_changed(dev, flags, 0);
@@ -1194,7 +1195,8 @@ netdev_linux_miimon_run(void)
     shash_init(&device_shash);
     netdev_get_devices(&netdev_linux_class, &device_shash);
     SHASH_FOR_EACH (node, &device_shash) {
-        struct netdev_linux *dev = node->data;
+        struct netdev *netdev = node->data;
+        struct netdev_linux *dev = netdev_linux_cast(netdev);
         bool miimon;
 
         if (dev->miimon_interval <= 0 || !timer_expired(&dev->miimon_timer)) {
@@ -1222,7 +1224,8 @@ netdev_linux_miimon_wait(void)
     shash_init(&device_shash);
     netdev_get_devices(&netdev_linux_class, &device_shash);
     SHASH_FOR_EACH (node, &device_shash) {
-        struct netdev_linux *dev = node->data;
+        struct netdev *netdev = node->data;
+        struct netdev_linux *dev = netdev_linux_cast(netdev);
 
         if (dev->miimon_interval > 0) {
             timer_wait(&dev->miimon_timer);
-- 
1.7.10.4

_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev

Reply via email to