login
Header Space

 
 

Re: [PATCH] [ETHTOOL]: Add support for large eeproms

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <netdev@...>, <jeff@...>, <matthew@...>, <davem@...>, <joe@...>
Cc: <nil@...>, <thockin@...>
Date: Thursday, April 3, 2008 - 2:00 pm

Thanks Joe,

Fixed and updated patch. Please take another look.

Regards,
Mandeep

Joe Perches (joe@perches.com) wrote:

Fixed


Fixed

---
Currently, it is not possible to read/write to an eeprom larger than
128k in size because the buffer used for temporarily storing the
eeprom contents is allocated using kmalloc. kmalloc can only allocate
a maximum of 128k depending on architecture.

Modified ethtool_get/set_eeprom to only allocate a page of memory and
then copy the eeprom a page at a time.

Signed-off-by: Mandeep Singh Baines <msb@google.com>
---
 net/core/ethtool.c |   57 +++++++++++++++++++++++++++++----------------------
 1 files changed, 32 insertions(+), 25 deletions(-)

diff --git a/net/core/ethtool.c b/net/core/ethtool.c
index 1163eb2..45d5f35 100644
--- a/net/core/ethtool.c
+++ b/net/core/ethtool.c
@@ -284,6 +284,8 @@ static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
 {
 	struct ethtool_eeprom eeprom;
 	const struct ethtool_ops *ops = dev->ethtool_ops;
+	void __user *userbuf = useraddr + sizeof(eeprom);
+	u32 bytes_remaining;
 	u8 *data;
 	int ret;
 
@@ -301,26 +303,26 @@ static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
 	if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
 		return -EINVAL;
 
-	data = kmalloc(eeprom.len, GFP_USER);
+	data = kmalloc(PAGE_SIZE, GFP_USER);
 	if (!data)
 		return -ENOMEM;
 
-	ret = -EFAULT;
-	if (copy_from_user(data, useraddr + sizeof(eeprom), eeprom.len))
-		goto out;
-
-	ret = ops->get_eeprom(dev, &eeprom, data);
-	if (ret)
-		goto out;
+	bytes_remaining = eeprom.len;
+	while (bytes_remaining > 0) {
+		eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
 
-	ret = -EFAULT;
-	if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
-		goto out;
-	if (copy_to_user(useraddr + sizeof(eeprom), data, eeprom.len))
-		goto out;
-	ret = 0;
+		ret = ops->get_eeprom(dev, &eeprom, data)
+		if (ret)
+			break;
+		ret = -EFAULT;
+		if (copy_to_user(userbuf, data, eeprom.len))
+			break;
+		ret = 0;
+		userbuf += eeprom.len;
+		eeprom.offset += eeprom.len;
+		bytes_remaining -= eeprom.len;
+	}
 
- out:
 	kfree(data);
 	return ret;
 }
@@ -329,6 +331,8 @@ static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
 {
 	struct ethtool_eeprom eeprom;
 	const struct ethtool_ops *ops = dev->ethtool_ops;
+	void __user *userbuf = useraddr + sizeof(eeprom);
+	u32 bytes_remaining;
 	u8 *data;
 	int ret;
 
@@ -346,22 +350,25 @@ static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
 	if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
 		return -EINVAL;
 
-	data = kmalloc(eeprom.len, GFP_USER);
+	data = kmalloc(PAGE_SIZE, GFP_USER);
 	if (!data)
 		return -ENOMEM;
 
-	ret = -EFAULT;
-	if (copy_from_user(data, useraddr + sizeof(eeprom), eeprom.len))
-		goto out;
-
-	ret = ops->set_eeprom(dev, &eeprom, data);
-	if (ret)
-		goto out;
+	bytes_remaining = eeprom.len;
+	while (bytes_remaining > 0) {
+		eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
 
-	if (copy_to_user(useraddr + sizeof(eeprom), data, eeprom.len))
 		ret = -EFAULT;
+		if (copy_from_user(data, userbuf, eeprom.len))
+			break;
+		ret = ops->set_eeprom(dev, &eeprom, data);
+		if (ret)
+			break;
+		userbuf += eeprom.len;
+		eeprom.offset += eeprom.len;
+		bytes_remaining -= eeprom.len;
+	}
 
- out:
 	kfree(data);
 	return ret;
 }
-- 
1.5.2.5

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: [PATCH] [ETHTOOL]: Add support for large eeproms, Mandeep Singh Baines, (Thu Apr 3, 2:00 pm)
Re: [PATCH] [ETHTOOL]: Add support for large eeproms, Joe Perches, (Thu Apr 3, 8:03 pm)
Re: [PATCH] [ETHTOOL]: Add support for large eeproms, Mandeep Singh Baines, (Thu Apr 3, 9:41 pm)
Re: [PATCH] [ETHTOOL]: Add support for large eeproms, Jeff Garzik, (Sat Apr 12, 5:10 am)
[PATCH] [ETHTOOL]: Add support for large eeproms, Mandeep Singh Baines, (Mon Apr 14, 2:03 pm)
Re: [PATCH] [ETHTOOL]: Add support for large eeproms, David Miller, (Tue Apr 15, 10:24 pm)
Re: [PATCH] [ETHTOOL]: Add support for large eeproms, David Miller, (Tue Apr 15, 3:31 am)
Re: [PATCH] [ETHTOOL]: Add support for large eeproms, Mandeep Singh Baines, (Tue Apr 15, 1:39 pm)
Re: [PATCH] [ETHTOOL]: Add support for large eeproms, Tim Hockin, (Tue Apr 15, 1:07 pm)
Re: [PATCH] [ETHTOOL]: Add support for large eeproms, David Miller, (Tue Apr 15, 10:23 pm)
Re: [PATCH] [ETHTOOL]: Add support for large eeproms, Breno Leitao, (Thu Apr 24, 2:17 pm)
Re: [PATCH] [ETHTOOL]: Add support for large eeproms, Mandeep Singh Baines, (Thu Apr 24, 3:01 pm)
Re: [PATCH] [ETHTOOL]: Add support for large eeproms, Breno Leitao, (Thu Apr 24, 4:21 pm)
Re: [PATCH] [ETHTOOL]: Add support for large eeproms, Mandeep Singh Baines, (Thu Apr 24, 9:15 pm)
speck-geostationary