From patchwork Thu Jun 21 01:29:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 10478929 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E3E5960230 for ; Thu, 21 Jun 2018 01:30:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D5EDF28D9C for ; Thu, 21 Jun 2018 01:30:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C9D7D28DA4; Thu, 21 Jun 2018 01:30:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C5EC28D9C for ; Thu, 21 Jun 2018 01:30:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754317AbeFUBaE (ORCPT ); Wed, 20 Jun 2018 21:30:04 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:45830 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754104AbeFUBaC (ORCPT ); Wed, 20 Jun 2018 21:30:02 -0400 Received: by mail-pl0-f65.google.com with SMTP id o18-v6so29851pll.12 for ; Wed, 20 Jun 2018 18:30:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=JUNWyT1fHJMPNX/hy198vkCapR8JExiNDwqcfSvq+28=; b=k/i337MGQfh1S4b7+9PEpHjIFVFB/+rtsr5097CzkvsItC4DgaIy4+ejD9mfL7tYLp v+F9fMRhUjLHyApITjmkNBupc6k+rZJSabouF6Jc4KPhtMWVLT9iR/jy8EX49VOoAiwQ lwKHSAOG8uirpBANvA6EXJjoHuVEfXnnXeTMI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=JUNWyT1fHJMPNX/hy198vkCapR8JExiNDwqcfSvq+28=; b=hb31gnyq6Iom5EIPevHQH81ZVJSX3Bp+lpmRO63aGzsNjbGrVbHAElE97nyqFuec7Y jiE2yM/9iPMsEUMPPHR7NgAyfKCb1OEvby4/kpUeyF/rapx4LTAVys7UnvgvELO7ZJ/K HISEPWY6h/syj7yHoZUR/v9AwMwLO1RZIN2ez9+/DcicOaRXTcBjcMgL/3rWIYKnzUSw UDbVC1LQCjlUqqgETTAwFqNhmjNcitmbVFpe8vWshJ4OCjDZs9bk9uxLeSMdNpxPTJ4P wEg7c96XzFKjJ/Y9PkiVSemsIHEJ2+QzIY+l2oo+CaxRjnzrjW0XtIFy+lZbtxTSHthy 9mvw== X-Gm-Message-State: APt69E2mOvn8SPqUh3H13mbWINaSDgmOlcoyu7bFJKL+hOVRytjbR3+e YwDap8FtfNK3YRkZTW0MkcVFjg== X-Google-Smtp-Source: ADUXVKIZP6T5stDWfzfamsNbarz6E66sR64DqJR4x8sXNlLwgpTnVEIJx2IJvNXGnRoVwDcm9j4SLQ== X-Received: by 2002:a17:902:5501:: with SMTP id f1-v6mr26097329pli.108.1529544601916; Wed, 20 Jun 2018 18:30:01 -0700 (PDT) Received: from ban.mtv.corp.google.com ([2620:0:1000:1501:bc2f:3082:9938:5d41]) by smtp.gmail.com with ESMTPSA id f11-v6sm4073918pgq.18.2018.06.20.18.29.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Jun 2018 18:30:00 -0700 (PDT) From: Brian Norris To: Johannes Berg Cc: , linux-wireless@vger.kernel.org, netdev@vger.kernel.org, Brian Norris Subject: [PATCH] cfg80211: use IDA to allocate wiphy indeces Date: Wed, 20 Jun 2018 18:29:45 -0700 Message-Id: <20180621012945.185705-1-briannorris@chromium.org> X-Mailer: git-send-email 2.18.0.rc1.244.gcf134e6275-goog Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP It's annoying to see the phy index increase arbitrarily, just because a device got removed and re-probed (e.g., during a device reset, or due to probe testing). We can use the in-kernel index allocator for this, instead of just an increasing counter. Signed-off-by: Brian Norris --- net/wireless/core.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/net/wireless/core.c b/net/wireless/core.c index c0fd8a85e7f7..80c108c3ca38 100644 --- a/net/wireless/core.c +++ b/net/wireless/core.c @@ -8,6 +8,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#include #include #include #include @@ -380,11 +381,11 @@ static void cfg80211_propagate_cac_done_wk(struct work_struct *work) /* exported functions */ +static DEFINE_IDA(wiphy_ida); + struct wiphy *wiphy_new_nm(const struct cfg80211_ops *ops, int sizeof_priv, const char *requested_name) { - static atomic_t wiphy_counter = ATOMIC_INIT(0); - struct cfg80211_registered_device *rdev; int alloc_size; @@ -413,18 +414,12 @@ struct wiphy *wiphy_new_nm(const struct cfg80211_ops *ops, int sizeof_priv, rdev->ops = ops; - rdev->wiphy_idx = atomic_inc_return(&wiphy_counter); - + rdev->wiphy_idx = ida_simple_get(&wiphy_ida, 0, 0, GFP_KERNEL); if (unlikely(rdev->wiphy_idx < 0)) { - /* ugh, wrapped! */ - atomic_dec(&wiphy_counter); kfree(rdev); return NULL; } - /* atomic_inc_return makes it start at 1, make it start at 0 */ - rdev->wiphy_idx--; - /* give it a proper name */ if (requested_name && requested_name[0]) { int rv; @@ -452,10 +447,8 @@ struct wiphy *wiphy_new_nm(const struct cfg80211_ops *ops, int sizeof_priv, * value, and use a different name if this one exists? */ rv = dev_set_name(&rdev->wiphy.dev, PHY_NAME "%d", rdev->wiphy_idx); - if (rv < 0) { - kfree(rdev); - return NULL; - } + if (rv < 0) + goto err; } INIT_LIST_HEAD(&rdev->wiphy.wdev_list); @@ -497,10 +490,8 @@ struct wiphy *wiphy_new_nm(const struct cfg80211_ops *ops, int sizeof_priv, &rdev->wiphy.dev, RFKILL_TYPE_WLAN, &rdev->rfkill_ops, rdev); - if (!rdev->rfkill) { - kfree(rdev); - return NULL; - } + if (!rdev->rfkill) + goto err; INIT_WORK(&rdev->rfkill_sync, cfg80211_rfkill_sync_work); INIT_WORK(&rdev->conn_work, cfg80211_conn_work); @@ -525,6 +516,11 @@ struct wiphy *wiphy_new_nm(const struct cfg80211_ops *ops, int sizeof_priv, rdev->wiphy.max_sched_scan_plan_interval = U32_MAX; return &rdev->wiphy; + +err: + ida_simple_remove(&wiphy_ida, rdev->wiphy_idx); + kfree(rdev); + return NULL; } EXPORT_SYMBOL(wiphy_new_nm); @@ -972,6 +968,7 @@ void cfg80211_dev_free(struct cfg80211_registered_device *rdev) } list_for_each_entry_safe(scan, tmp, &rdev->bss_list, list) cfg80211_put_bss(&rdev->wiphy, &scan->pub); + ida_simple_remove(&wiphy_ida, rdev->wiphy_idx); kfree(rdev); }