From 8a52ee8fc93e0c9a476a56c7e9ed4f8a7d422105 Mon Sep 17 00:00:00 2001 From: David Cantrell Date: Mon, 9 Feb 2009 12:54:57 -1000 Subject: Rewrite mdio_read() in linkdetect.c for strict aliasing rules. 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 file changed, 16 insertions(+), 8 deletions(-) (limited to 'isys') diff --git a/isys/linkdetect.c b/isys/linkdetect.c index fd89db351..cffdd89d4 100644 --- a/isys/linkdetect.c +++ b/isys/linkdetect.c @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -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 */ -- cgit