hal/hald/linux net_class_device.c,1.21.2.1,1.21.2.2

David Zeuthen david at freedesktop.org
Mon Jan 3 14:07:41 PST 2005


Update of /cvs/hal/hal/hald/linux
In directory gabe:/tmp/cvs-serv12362/hald/linux

Modified Files:
      Tag: hal-0_4-stable-branch
	net_class_device.c 
Log Message:
2005-01-03  David Zeuthen  <davidz at redhat.com>

	* configure.in: Added it to ALL_LINGUAS

	* po/it.po: Italien translation from Pier Luigi Fiorini
	<pierluigi.fiorini at mockup.org>
	
2005-01-03  David Zeuthen  <davidz at redhat.com>

	* hald/linux/net_class_device.c (mii_get_link, mii_get_rate): Allocate
	the struct ifreq on the stack and reserve plenty of space; to work
	around a crasher with the sk98lin driver. RH #142183



Index: net_class_device.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/net_class_device.c,v
retrieving revision 1.21.2.1
retrieving revision 1.21.2.2
diff -u -d -r1.21.2.1 -r1.21.2.2
--- net_class_device.c	10 Dec 2004 18:26:49 -0000	1.21.2.1
+++ net_class_device.c	3 Jan 2005 22:07:39 -0000	1.21.2.2
@@ -147,7 +147,7 @@
 {
 	const char *ifname;
 	int sockfd;
-	struct ifreq ifr;
+	struct ifreq *ifr;
 	gboolean new_ioctl_nums;
 	int res;
 	guint16 link_word;
@@ -161,16 +161,20 @@
 		return;
 	}
 
-	snprintf (ifr.ifr_name, IFNAMSIZ, ifname);
+	/* reserve some extra space as the sk98lin driver seems to segfault otherwise */
+	ifr = g_new0 (struct ifreq, 10);
 
-	if (ioctl (sockfd, 0x8947, &ifr) >= 0)
+	snprintf (ifr->ifr_name, IFNAMSIZ, ifname);
+
+	if (ioctl (sockfd, 0x8947, ifr) >= 0)
 		new_ioctl_nums = TRUE;
-	else if (ioctl (sockfd, SIOCDEVPRIVATE, &ifr) >= 0)
+	else if (ioctl (sockfd, SIOCDEVPRIVATE, ifr) >= 0)
 		new_ioctl_nums = FALSE;
 	else {
 		HAL_ERROR (("SIOCGMIIPHY on %s failed: %s",
-			    ifr.ifr_name, strerror (errno)));
+			    ifr->ifr_name, strerror (errno)));
 		close (sockfd);
+		g_free (ifr);
 		return;
 	}
 
@@ -187,7 +191,7 @@
 	 * 0x0020  10baseT supported
 	 * 0x001F  Protocol selection bits, always 0x0001 for Ethernet.
 	 */
-	res = mdio_read (sockfd, &ifr, 5, new_ioctl_nums, &link_word);
+	res = mdio_read (sockfd, ifr, 5, new_ioctl_nums, &link_word);
 
 	if (res < 0) {
 		HAL_WARNING (("Error reading rate info"));
@@ -200,6 +204,7 @@
 	}
 
 	close (sockfd);
+	g_free (ifr);
 }
 
 static void
@@ -207,7 +212,7 @@
 {
 	const char *ifname;
 	int sockfd;
-	struct ifreq ifr;
+	struct ifreq *ifr;
 	gboolean new_ioctl_nums;
 	int res;
 	guint16 status_word;
@@ -221,16 +226,20 @@
 		return;
 	}
 
-	snprintf (ifr.ifr_name, IFNAMSIZ, ifname);
+	/* reserve some extra space as the sk98lin driver seems to segfault otherwise */
+	ifr = g_new0 (struct ifreq, 10);
 
-	if (ioctl (sockfd, 0x8947, &ifr) >= 0)
+	snprintf (ifr->ifr_name, IFNAMSIZ, ifname);
+
+	if (ioctl (sockfd, 0x8947, ifr) >= 0)
 		new_ioctl_nums = TRUE;
-	else if (ioctl (sockfd, SIOCDEVPRIVATE, &ifr) >= 0)
+	else if (ioctl (sockfd, SIOCDEVPRIVATE, ifr) >= 0)
 		new_ioctl_nums = FALSE;
 	else {
 		HAL_ERROR (("SIOCGMIIPHY on %s failed: %s",
-			    ifr.ifr_name, strerror (errno)));
+			    ifr->ifr_name, strerror (errno)));
 		close (sockfd);
+		g_free (ifr);
 		return;
 	}
 
@@ -250,8 +259,8 @@
 	 */
 
 	/* We have to read it twice to clear any "sticky" bits */
-	res = mdio_read (sockfd, &ifr, 1, new_ioctl_nums, &status_word);
-	res = mdio_read (sockfd, &ifr, 1, new_ioctl_nums, &status_word);
+	res = mdio_read (sockfd, ifr, 1, new_ioctl_nums, &status_word);
+	res = mdio_read (sockfd, ifr, 1, new_ioctl_nums, &status_word);
 
 	if (res < 0)
 		HAL_WARNING (("Error reading link info"));
@@ -261,6 +270,7 @@
 		hal_device_property_set_bool (d, "net.80203.link", FALSE);
 
 	close (sockfd);
+	g_free (ifr);
 
 	/* Also get the link rate */
 	mii_get_rate (d);




More information about the hal-commit mailing list