From: Ben Hutchings Date: Thu, 21 Jul 2011 22:25:30 +0000 (-0700) Subject: ethtool: Allow zero-length register dumps again X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=67ae7cf1eeda;p=GitHub%2Fmoto-9609%2Fandroid_kernel_motorola_exynos9610.git 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 a77f5db361ed9953b5b749353ea2c7fed2bf8d93 ('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 Signed-off-by: Ben Hutchings Cc: stable@kernel.org [2.6.37+] Signed-off-by: David S. Miller --- diff --git a/net/core/ethtool.c b/net/core/ethtool.c index b7c12a63d0ce..6cdba5fc2bed 100644 --- a/net/core/ethtool.c +++ b/net/core/ethtool.c @@ -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, ®s, regbuf); @@ -932,7 +932,7 @@ static int ethtool_get_regs(struct net_device *dev, char __user *useraddr) if (copy_to_user(useraddr, ®s, 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;