Commit 67ae7cf1 authored by Ben Hutchings's avatar Ben Hutchings Committed by David S. Miller

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
a77f5db3 ('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: default avatarKalle Valo <kvalo@qca.qualcomm.com>
Signed-off-by: default avatarBen Hutchings <bhutchings@solarflare.com>
Cc: stable@kernel.org [2.6.37+]
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1511022c
...@@ -923,7 +923,7 @@ static int ethtool_get_regs(struct net_device *dev, char __user *useraddr) ...@@ -923,7 +923,7 @@ static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
regs.len = reglen; regs.len = reglen;
regbuf = vzalloc(reglen); regbuf = vzalloc(reglen);
if (!regbuf) if (reglen && !regbuf)
return -ENOMEM; return -ENOMEM;
ops->get_regs(dev, &regs, regbuf); ops->get_regs(dev, &regs, regbuf);
...@@ -932,7 +932,7 @@ static int ethtool_get_regs(struct net_device *dev, char __user *useraddr) ...@@ -932,7 +932,7 @@ static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
if (copy_to_user(useraddr, &regs, sizeof(regs))) if (copy_to_user(useraddr, &regs, sizeof(regs)))
goto out; goto out;
useraddr += offsetof(struct ethtool_regs, data); 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; goto out;
ret = 0; ret = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment