]>
Commit | Line | Data |
---|---|---|
632d9a26 GKH |
1 | From 67ae7cf1eeda777f79259c4c6cb17a0bd28dee71 Mon Sep 17 00:00:00 2001 |
2 | From: Ben Hutchings <bhutchings@solarflare.com> | |
3 | Date: Thu, 21 Jul 2011 15:25:30 -0700 | |
4 | Subject: ethtool: Allow zero-length register dumps again | |
5 | ||
6 | From: Ben Hutchings <bhutchings@solarflare.com> | |
7 | ||
8 | commit 67ae7cf1eeda777f79259c4c6cb17a0bd28dee71 upstream. | |
9 | ||
10 | Some drivers (ab)use the ethtool_ops::get_regs operation to expose | |
11 | only a hardware revision ID. Commit | |
12 | a77f5db361ed9953b5b749353ea2c7fed2bf8d93 ('ethtool: Allocate register | |
13 | dump buffer with vmalloc()') had the side-effect of breaking these, as | |
14 | vmalloc() returns a null pointer for size=0 whereas kmalloc() did not. | |
15 | ||
16 | For backward-compatibility, allow zero-length dumps again. | |
17 | ||
18 | Reported-by: Kalle Valo <kvalo@qca.qualcomm.com> | |
19 | Signed-off-by: Ben Hutchings <bhutchings@solarflare.com> | |
20 | Signed-off-by: David S. Miller <davem@davemloft.net> | |
21 | Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> | |
22 | ||
23 | --- | |
24 | net/core/ethtool.c | 4 ++-- | |
25 | 1 file changed, 2 insertions(+), 2 deletions(-) | |
26 | ||
27 | --- a/net/core/ethtool.c | |
28 | +++ b/net/core/ethtool.c | |
29 | @@ -1227,7 +1227,7 @@ static int ethtool_get_regs(struct net_d | |
30 | regs.len = reglen; | |
31 | ||
32 | regbuf = vzalloc(reglen); | |
33 | - if (!regbuf) | |
34 | + if (reglen && !regbuf) | |
35 | return -ENOMEM; | |
36 | ||
37 | ops->get_regs(dev, ®s, regbuf); | |
38 | @@ -1236,7 +1236,7 @@ static int ethtool_get_regs(struct net_d | |
39 | if (copy_to_user(useraddr, ®s, sizeof(regs))) | |
40 | goto out; | |
41 | useraddr += offsetof(struct ethtool_regs, data); | |
42 | - if (copy_to_user(useraddr, regbuf, regs.len)) | |
43 | + if (regbuf && copy_to_user(useraddr, regbuf, regs.len)) | |
44 | goto out; | |
45 | ret = 0; | |
46 |