[patch] handle failure of mdio_read

Sjoerd Simons sjoerd at luon.net
Wed May 12 14:58:35 PDT 2004


Hi,

  In the current failure of mdio_read is not really handled. Attached
  patch solves this. As a side effect it solves a segv on startup on the
  machine where these failures happen, but i don't understand why :(

  Sjoerd
-- 
The truth of a proposition has nothing to do with its credibility.  And
vice versa.
-------------- next part --------------
Index: hald/linux/net_class_device.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/net_class_device.c,v
retrieving revision 1.4
diff -c -u -r1.4 net_class_device.c
--- hald/linux/net_class_device.c	30 Apr 2004 20:59:08 -0000	1.4
+++ hald/linux/net_class_device.c	12 May 2004 21:52:03 -0000
@@ -115,11 +115,11 @@
  *
  *  @param  iface               Which interface
  *  @param  location            Which register
- *  @return                     Word that is read
+ *  @return                     0 on success, -1 on failure
  */
-static guint16
+static int
 mdio_read (int sockfd, struct ifreq *ifr, int location,
-	   gboolean new_ioctl_nums)
+	   gboolean new_ioctl_nums, guint16 *result)
 {
 	guint16 *data = (guint16 *) &(ifr->ifr_data);
 
@@ -132,7 +132,8 @@
 			    ifr->ifr_name, strerror (errno)));
 		return -1;
 	}
-	return data[3];
+  *result = data[3];
+	return 0;
 }
 
 static void
@@ -142,6 +143,7 @@
 	int sockfd;
 	struct ifreq ifr;
 	gboolean new_ioctl_nums;
+  int res;
 	guint16 link_word;
 
 	ifname = hal_device_property_get_string (d, "net.interface");
@@ -179,18 +181,19 @@
 	 * 0x0020  10baseT supported
 	 * 0x001F  Protocol selection bits, always 0x0001 for Ethernet.
 	 */
-	link_word = mdio_read (sockfd, &ifr, 5, new_ioctl_nums);
+	res = mdio_read (sockfd, &ifr, 5, new_ioctl_nums, &link_word);
 
-	if (link_word & 0x380) {
+  if (res < 0) {
+    /* read failure */
+    ;
+  } else if (link_word & 0x380) {
 		hal_device_property_set_int (d, "net.ethernet.rate",
 					     100 * 1000 * 1000);
-	}
-
-	if (link_word & 0x60) {
+	} else if (link_word & 0x60) {
 		hal_device_property_set_int (d, "net.ethernet.rate",
 					     10 * 1000 * 1000);
 	}
-
+      
 	close (sockfd);
 }
 
@@ -201,6 +204,7 @@
 	int sockfd;
 	struct ifreq ifr;
 	gboolean new_ioctl_nums;
+  int res;
 	guint16 status_word;
 
 	ifname = hal_device_property_get_string (d, "net.interface");
@@ -241,10 +245,12 @@
 	 */
 
 	/* We have to read it twice to clear any "sticky" bits */
-	status_word = mdio_read (sockfd, &ifr, 1, new_ioctl_nums);
-	status_word = mdio_read (sockfd, &ifr, 1, new_ioctl_nums);
+	res = mdio_read (sockfd, &ifr, 1, new_ioctl_nums, &status_word);
+	res = mdio_read (sockfd, &ifr, 1, new_ioctl_nums, &status_word);
 
-	if ((status_word & 0x0016) == 0x0004)
+  if (res < 0) {
+    /* mdio_read failure */
+  } else if ((status_word & 0x0016) == 0x0004)
 		hal_device_property_set_bool (d, "net.ethernet.link", TRUE);
 	else
 		hal_device_property_set_bool (d, "net.ethernet.link", FALSE);
-------------- next part --------------
_______________________________________________
hal mailing list
hal at freedesktop.org
http://freedesktop.org/mailman/listinfo/hal


More information about the Hal mailing list