From: Kalle Valo <kvalo-A+ZNKFmMK5xy9aJCnZT0Uw@public.gmane.org>
To: netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: linux-wireless-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH] ethtool: fix ethtool_get_regs() to work with zero length registers
Date: Wed, 20 Jul 2011 12:18:50 +0300 [thread overview]
Message-ID: <20110720091850.32210.2059.stgit@localhost6.localdomain6> (raw)
cfg80211 exports zero length register size as it currently only uses
struct ethtool_regs.version to export struct wiphy.hw_version. But the
problem is that ethtool_get_regs() assumes that the driver (cfg80211 in this
case) always has non-zero length for registers. With cfg80211
it would always fail and return -ENOMEM to user space.
Fix this by checking the register length from the driver and exporting
struct ethtool_regs to user space if the length is zero.
With this patch it's possible to get the hardware id from wireless drivers.
Tested with wl12xx and ath6kl.
Tested-by: Gery Kahn <geryk-l0cyMroinI0@public.gmane.org>
Signed-off-by: Kalle Valo <kvalo-A+ZNKFmMK5xy9aJCnZT0Uw@public.gmane.org>
---
net/core/ethtool.c | 20 +++++++++++++-------
1 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/net/core/ethtool.c b/net/core/ethtool.c
index fd14116..6f073f4 100644
--- a/net/core/ethtool.c
+++ b/net/core/ethtool.c
@@ -1213,7 +1213,7 @@ static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
{
struct ethtool_regs regs;
const struct ethtool_ops *ops = dev->ethtool_ops;
- void *regbuf;
+ void *regbuf = NULL;
int reglen, ret;
if (!ops->get_regs || !ops->get_regs_len)
@@ -1226,18 +1226,24 @@ static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
if (regs.len > reglen)
regs.len = reglen;
- regbuf = vzalloc(reglen);
- if (!regbuf)
- return -ENOMEM;
+ if (reglen > 0) {
+ regbuf = vzalloc(reglen);
+ if (!regbuf)
+ return -ENOMEM;
+ }
ops->get_regs(dev, ®s, regbuf);
ret = -EFAULT;
if (copy_to_user(useraddr, ®s, sizeof(regs)))
goto out;
- useraddr += offsetof(struct ethtool_regs, data);
- if (copy_to_user(useraddr, regbuf, regs.len))
- goto out;
+
+ if (regs.len > 0) {
+ useraddr += offsetof(struct ethtool_regs, data);
+ if (copy_to_user(useraddr, regbuf, regs.len))
+ goto out;
+ }
+
ret = 0;
out:
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next reply other threads:[~2011-07-20 9:18 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-20 9:18 Kalle Valo [this message]
2011-07-20 11:38 ` [PATCH] ethtool: fix ethtool_get_regs() to work with zero length registers Ben Hutchings
2011-07-20 11:58 ` Kalle Valo
[not found] ` <4E26C2DC.8090208-A+ZNKFmMK5xy9aJCnZT0Uw@public.gmane.org>
2011-07-20 14:36 ` John W. Linville
2011-07-21 17:46 ` Ben Hutchings
2011-07-21 17:54 ` [PATCH net-2.6] ethtool: Allow zero-length register dumps again Ben Hutchings
2011-07-21 22:25 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110720091850.32210.2059.stgit@localhost6.localdomain6 \
--to=kvalo-a+znkfmmk5xy9ajcnzt0uw@public.gmane.org \
--cc=linux-wireless-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).