From patchwork Wed Jul 20 09:18:50 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalle Valo X-Patchwork-Id: 990712 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p6K9J1Cg016543 for ; Wed, 20 Jul 2011 09:19:01 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751228Ab1GTJS7 (ORCPT ); Wed, 20 Jul 2011 05:18:59 -0400 Received: from emh02.mail.saunalahti.fi ([62.142.5.108]:44521 "EHLO emh02.mail.saunalahti.fi" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751151Ab1GTJS7 (ORCPT ); Wed, 20 Jul 2011 05:18:59 -0400 Received: from saunalahti-vams (vs3-11.mail.saunalahti.fi [62.142.5.95]) by emh02-2.mail.saunalahti.fi (Postfix) with SMTP id B7E7BEF54D; Wed, 20 Jul 2011 12:18:57 +0300 (EEST) Received: from emh06.mail.saunalahti.fi ([62.142.5.116]) by vs3-11.mail.saunalahti.fi ([62.142.5.95]) with SMTP (gateway) id A05247B5451; Wed, 20 Jul 2011 12:18:57 +0300 Received: from localhost6.localdomain6 (a88-115-184-248.elisa-laajakaista.fi [88.115.184.248]) by emh06.mail.saunalahti.fi (Postfix) with ESMTP id 74546E51A4; Wed, 20 Jul 2011 12:18:50 +0300 (EEST) Subject: [PATCH] ethtool: fix ethtool_get_regs() to work with zero length registers To: netdev@vger.kernel.org From: Kalle Valo Cc: linux-wireless@vger.kernel.org Date: Wed, 20 Jul 2011 12:18:50 +0300 Message-ID: <20110720091850.32210.2059.stgit@localhost6.localdomain6> User-Agent: StGit/0.15 MIME-Version: 1.0 X-Antivirus: VAMS Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Wed, 20 Jul 2011 09:19:01 +0000 (UTC) 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 Signed-off-by: Kalle Valo --- net/core/ethtool.c | 20 +++++++++++++------- 1 files changed, 13 insertions(+), 7 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-wireless" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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: