ethtool: Allow zero-length register dumps again

Some drivers (ab)use the ethtool_ops::get_regs operation to expose
only a hardware revision ID.  Commit
a77f5db361 ('ethtool: Allocate register
dump buffer with vmalloc()') had the side-effect of breaking these, as
vmalloc() returns a null pointer for size=0 whereas kmalloc() did not.

For backward-compatibility, allow zero-length dumps again.

Reported-by: Kalle Valo <[email protected]>
Signed-off-by: Ben Hutchings <[email protected]>
Cc: [email protected] [2.6.37+]
Signed-off-by: David S. Miller <[email protected]>
This commit is contained in:
Ben Hutchings
2011-07-21 15:25:30 -07:00
committed by David S. Miller
parent 1511022c9a
commit 67ae7cf1ee
+2 -2
View File
@@ -923,7 +923,7 @@ static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
regs.len = reglen;
regbuf = vzalloc(reglen);
if (!regbuf)
if (reglen && !regbuf)
return -ENOMEM;
ops->get_regs(dev, &regs, regbuf);
@@ -932,7 +932,7 @@ static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
if (copy_to_user(useraddr, &regs, sizeof(regs)))
goto out;
useraddr += offsetof(struct ethtool_regs, data);
if (copy_to_user(useraddr, regbuf, regs.len))
if (regbuf && copy_to_user(useraddr, regbuf, regs.len))
goto out;
ret = 0;