aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorMandeep Singh Baines <msb@google.com>2008-04-15 22:24:17 -0400
committerDavid S. Miller <davem@davemloft.net>2008-04-15 22:29:17 -0400
commitb131dd5d659aaf287a3809473130c3ff5eddb71b (patch)
treea65425bc2a4119b0e668dafa528d1f4e0286ff40 /net
parent73e87e02ec484ac459c4be262ab76960b89dc019 (diff)
[ETHTOOL]: Add support for large eeproms
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. Updated original patch as per suggestions from Joe Perches. Signed-off-by: Mandeep Singh Baines <msb@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r--net/core/ethtool.c64
1 files changed, 36 insertions, 28 deletions
diff --git a/net/core/ethtool.c b/net/core/ethtool.c
index 1163eb2256d0..a29b43d0b450 100644
--- a/net/core/ethtool.c
+++ b/net/core/ethtool.c
@@ -284,8 +284,10 @@ static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
284{ 284{
285 struct ethtool_eeprom eeprom; 285 struct ethtool_eeprom eeprom;
286 const struct ethtool_ops *ops = dev->ethtool_ops; 286 const struct ethtool_ops *ops = dev->ethtool_ops;
287 void __user *userbuf = useraddr + sizeof(eeprom);
288 u32 bytes_remaining;
287 u8 *data; 289 u8 *data;
288 int ret; 290 int ret = 0;
289 291
290 if (!ops->get_eeprom || !ops->get_eeprom_len) 292 if (!ops->get_eeprom || !ops->get_eeprom_len)
291 return -EOPNOTSUPP; 293 return -EOPNOTSUPP;
@@ -301,26 +303,26 @@ static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
301 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev)) 303 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
302 return -EINVAL; 304 return -EINVAL;
303 305
304 data = kmalloc(eeprom.len, GFP_USER); 306 data = kmalloc(PAGE_SIZE, GFP_USER);
305 if (!data) 307 if (!data)
306 return -ENOMEM; 308 return -ENOMEM;
307 309
308 ret = -EFAULT; 310 bytes_remaining = eeprom.len;
309 if (copy_from_user(data, useraddr + sizeof(eeprom), eeprom.len)) 311 while (bytes_remaining > 0) {
310 goto out; 312 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
311
312 ret = ops->get_eeprom(dev, &eeprom, data);
313 if (ret)
314 goto out;
315 313
316 ret = -EFAULT; 314 ret = ops->get_eeprom(dev, &eeprom, data);
317 if (copy_to_user(useraddr, &eeprom, sizeof(eeprom))) 315 if (ret)
318 goto out; 316 break;
319 if (copy_to_user(useraddr + sizeof(eeprom), data, eeprom.len)) 317 if (copy_to_user(userbuf, data, eeprom.len)) {
320 goto out; 318 ret = -EFAULT;
321 ret = 0; 319 break;
320 }
321 userbuf += eeprom.len;
322 eeprom.offset += eeprom.len;
323 bytes_remaining -= eeprom.len;
324 }
322 325
323 out:
324 kfree(data); 326 kfree(data);
325 return ret; 327 return ret;
326} 328}
@@ -329,8 +331,10 @@ static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
329{ 331{
330 struct ethtool_eeprom eeprom; 332 struct ethtool_eeprom eeprom;
331 const struct ethtool_ops *ops = dev->ethtool_ops; 333 const struct ethtool_ops *ops = dev->ethtool_ops;
334 void __user *userbuf = useraddr + sizeof(eeprom);
335 u32 bytes_remaining;
332 u8 *data; 336 u8 *data;
333 int ret; 337 int ret = 0;
334 338
335 if (!ops->set_eeprom || !ops->get_eeprom_len) 339 if (!ops->set_eeprom || !ops->get_eeprom_len)
336 return -EOPNOTSUPP; 340 return -EOPNOTSUPP;
@@ -346,22 +350,26 @@ static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
346 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev)) 350 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
347 return -EINVAL; 351 return -EINVAL;
348 352
349 data = kmalloc(eeprom.len, GFP_USER); 353 data = kmalloc(PAGE_SIZE, GFP_USER);
350 if (!data) 354 if (!data)
351 return -ENOMEM; 355 return -ENOMEM;
352 356
353 ret = -EFAULT; 357 bytes_remaining = eeprom.len;
354 if (copy_from_user(data, useraddr + sizeof(eeprom), eeprom.len)) 358 while (bytes_remaining > 0) {
355 goto out; 359 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
356
357 ret = ops->set_eeprom(dev, &eeprom, data);
358 if (ret)
359 goto out;
360 360
361 if (copy_to_user(useraddr + sizeof(eeprom), data, eeprom.len)) 361 if (copy_from_user(data, userbuf, eeprom.len)) {
362 ret = -EFAULT; 362 ret = -EFAULT;
363 break;
364 }
365 ret = ops->set_eeprom(dev, &eeprom, data);
366 if (ret)
367 break;
368 userbuf += eeprom.len;
369 eeprom.offset += eeprom.len;
370 bytes_remaining -= eeprom.len;
371 }
363 372
364 out:
365 kfree(data); 373 kfree(data);
366 return ret; 374 return ret;
367} 375}