From: Mandeep Singh Baines <msb@google.com>
To: netdev@vger.kernel.org, jeff@garzik.org, matthew@wil.cx,
davem@davemloft.net
Cc: nil@google.com, thockin@google.com
Subject: [PATCH] [ETHTOOL]: Add support for large eeproms
Date: Wed, 2 Apr 2008 19:12:31 -0700 [thread overview]
Message-ID: <20080403021230.GA22357@google.com> (raw)
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, 31 insertions(+), 26 deletions(-)
diff --git a/net/core/ethtool.c b/net/core/ethtool.c
index 1163eb2..54f1004 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,25 @@ 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;
+ if ((ret = ops->get_eeprom(dev, &eeprom, data)))
+ 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,8 +330,10 @@ 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;
+ int ret = 0;
if (!ops->set_eeprom || !ops->get_eeprom_len)
return -EOPNOTSUPP;
@@ -346,22 +349,24 @@ 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;
+ bytes_remaining = eeprom.len;
+ while (bytes_remaining > 0) {
+ eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
- ret = ops->set_eeprom(dev, &eeprom, data);
- if (ret)
- goto out;
-
- if (copy_to_user(useraddr + sizeof(eeprom), data, eeprom.len))
ret = -EFAULT;
+ if (copy_from_user(data, userbuf, eeprom.len))
+ break;
+ if ((ret = ops->set_eeprom(dev, &eeprom, data)))
+ break;
+ userbuf += eeprom.len;
+ eeprom.offset += eeprom.len;
+ bytes_remaining -= eeprom.len;
+ }
- out:
kfree(data);
return ret;
}
--
1.5.2.5
next reply other threads:[~2008-04-03 2:12 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-03 2:12 Mandeep Singh Baines [this message]
[not found] <1207195123.23161.291.camel@localhost>
2008-04-03 18:00 ` [PATCH] [ETHTOOL]: Add support for large eeproms Mandeep Singh Baines
2008-04-04 0:03 ` Joe Perches
2008-04-04 1:41 ` Mandeep Singh Baines
2008-04-12 9:10 ` Jeff Garzik
2008-04-14 18:03 ` Mandeep Singh Baines
2008-04-15 7:31 ` David Miller
2008-04-15 17:07 ` Tim Hockin
2008-04-16 2:23 ` David Miller
2008-04-24 18:17 ` Breno Leitao
2008-04-24 19:01 ` Mandeep Singh Baines
2008-04-24 20:21 ` Breno Leitao
2008-04-25 1:15 ` Mandeep Singh Baines
2008-04-15 17:39 ` Mandeep Singh Baines
2008-04-16 2:24 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080403021230.GA22357@google.com \
--to=msb@google.com \
--cc=davem@davemloft.net \
--cc=jeff@garzik.org \
--cc=matthew@wil.cx \
--cc=netdev@vger.kernel.org \
--cc=nil@google.com \
--cc=thockin@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).