From patchwork Tue Nov 10 11:51:43 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Holger Schurig X-Patchwork-Id: 59019 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id nAABqWNX028707 for ; Tue, 10 Nov 2009 11:52:32 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751041AbZKJLwN (ORCPT ); Tue, 10 Nov 2009 06:52:13 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751214AbZKJLwN (ORCPT ); Tue, 10 Nov 2009 06:52:13 -0500 Received: from mail-bw0-f227.google.com ([209.85.218.227]:45885 "EHLO mail-bw0-f227.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750912AbZKJLwM (ORCPT ); Tue, 10 Nov 2009 06:52:12 -0500 Received: by bwz27 with SMTP id 27so4429551bwz.21 for ; Tue, 10 Nov 2009 03:52:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:date:message-id:from:to:cc :subject:mime-version:content-type; bh=p7cvNoTEMhyvCRnjp++uLSU7WAHl/TcCuKbrTth3oQA=; b=bx4dbl0Kb57T3fcUG+oiv8qIyzGlkjg2c+8I/9VL0DpkjwGIZcJiir8KE8Tg7vZxbo R5WOi4Kwg09NKtIjZqASXQgmuMExQ6Dso4ZV5EDV3qUYdpEI+s6BQSMVJzZjAkKwgP1Z JTI6Mr4Xc2KH3vIbQDhdd07ipP7aXAhYweh3U= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=date:message-id:from:to:cc:subject:mime-version:content-type; b=UFxI6KuRpWR9FFX3bZF3hPz3Fmlu5DN9+lPHj2OwgHhnp8//kEtulONwVG5GotwuWW 0LP2KqZVFLX5af07TBlDitOOVkgOvMPQl7MC1FHYu991G6+h9hUtTJoagHNOl01OHarH 5S2XPAORs5QvO3OerNUlwGgtxtQpvuJPLdLJA= Received: by 10.103.67.31 with SMTP id u31mr3532221muk.93.1257853936622; Tue, 10 Nov 2009 03:52:16 -0800 (PST) Received: from mnz66.mn-solutions.de.gmail.com (pD95F8B6C.dip0.t-ipconnect.de [217.95.139.108]) by mx.google.com with ESMTPS id 25sm2599996mul.55.2009.11.10.03.52.15 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 10 Nov 2009 03:52:15 -0800 (PST) Date: Tue, 10 Nov 2009 12:51:43 +0100 Message-ID: From: Holger Schurig To: linux-wireless cc: Johannes Berg Subject: [PATCH] cfg80211: introduce nl80211_get_ifidx() MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org --- linux-wl.orig/net/wireless/nl80211.c +++ linux-wl/net/wireless/nl80211.c @@ -151,6 +151,26 @@ [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, }; +/* ifidx get helper */ +static int nl80211_get_ifidx(struct netlink_callback *cb) +{ + int res; + + res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, + nl80211_fam.attrbuf, nl80211_fam.maxattr, + nl80211_policy); + if (res) + return res; + + if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) + return -EINVAL; + + res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); + if (!res) + return -EINVAL; + return res; +} + /* IE validation */ static bool is_valid_ie_attr(const struct nlattr *attr) { @@ -1682,20 +1702,10 @@ int sta_idx = cb->args[1]; int err; - if (!ifidx) { - err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, - nl80211_fam.attrbuf, nl80211_fam.maxattr, - nl80211_policy); - if (err) - return err; - - if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) - return -EINVAL; - - ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); - if (!ifidx) - return -EINVAL; - } + if (!ifidx) + ifidx = nl80211_get_ifidx(cb); + if (ifidx < 0) + return ifidx; rtnl_lock(); @@ -2145,20 +2155,10 @@ int path_idx = cb->args[1]; int err; - if (!ifidx) { - err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, - nl80211_fam.attrbuf, nl80211_fam.maxattr, - nl80211_policy); - if (err) - return err; - - if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) - return -EINVAL; - - ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); - if (!ifidx) - return -EINVAL; - } + if (!ifidx) + ifidx = nl80211_get_ifidx(cb); + if (ifidx < 0) + return ifidx; rtnl_lock(); @@ -3182,20 +3182,11 @@ int err; if (!ifidx) { - err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, - nl80211_fam.attrbuf, nl80211_fam.maxattr, - nl80211_policy); - if (err) - return err; - - if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) - return -EINVAL; - - ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); - if (!ifidx) - return -EINVAL; + ifidx = nl80211_get_ifidx(cb); cb->args[0] = ifidx; } + if (ifidx < 0) + return ifidx; dev = dev_get_by_index(sock_net(skb->sk), ifidx); if (!dev)