[PATCH] Rewrite mdio_read() in linkdetect.c for strict aliasing rules.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Can't cast from a void pointer to struct mii_ioctl_data.  Create
a local variable and copy in to struct ifreq and back out again
to do the same thing.
---
 isys/linkdetect.c |   24 ++++++++++++++++--------
 1 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/isys/linkdetect.c b/isys/linkdetect.c
index fd89db3..cffdd89 100644
--- a/isys/linkdetect.c
+++ b/isys/linkdetect.c
@@ -25,6 +25,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdint.h>
 #include <sys/ioctl.h>
 #include <string.h>
 #include <unistd.h>
@@ -41,19 +42,26 @@
 
 static struct ifreq ifr;
 
-static int mdio_read(int skfd, int location)
+static int mdio_read(int skfd, uint16_t location)
 {
-    void *data = &ifr.ifr_data;
-    struct mii_ioctl_data *mii = data;
-    mii->reg_num = location;
+    struct mii_ioctl_data mii;
+
+    memset(&mii, 0, sizeof(mii));
+    memcpy(&mii, &ifr.ifr_data, sizeof(mii));
+    mii.reg_num = location;
+    memcpy(&ifr.ifr_data, &mii, sizeof(mii));
+
     if (ioctl(skfd, SIOCGMIIREG, &ifr) < 0) {
 #ifdef STANDALONE
-	fprintf(stderr, "SIOCGMIIREG on %s failed: %s\n", ifr.ifr_name,
-		strerror(errno));
+        fprintf(stderr, "SIOCGMIIREG on %s failed: %s\n", ifr.ifr_name,
+                strerror(errno));
 #endif
-	return -1;
+        return -1;
+    } else {
+        memcpy(&mii, &ifr.ifr_data, sizeof(mii));
     }
-    return mii->val_out;
+
+    return mii.val_out;
 }
 
 /* we don't need writing right now */
-- 
1.6.1.2

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux