From patchwork Mon Feb 11 15:02:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 10806103 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-2.web.codeaurora.org (Postfix) with ESMTP id CA57417E0 for ; Mon, 11 Feb 2019 15:24:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B41862A96C for ; Mon, 11 Feb 2019 15:24:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A5A382A9DC; Mon, 11 Feb 2019 15:24:35 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham 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 A27EA2A96C for ; Mon, 11 Feb 2019 15:24:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387771AbfBKPYd (ORCPT ); Mon, 11 Feb 2019 10:24:33 -0500 Received: from s3.sipsolutions.net ([144.76.43.62]:44722 "EHLO sipsolutions.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390406AbfBKPC0 (ORCPT ); Mon, 11 Feb 2019 10:02:26 -0500 Received: by sipsolutions.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92-RC4) (envelope-from ) id 1gtD6G-00089o-Q3; Mon, 11 Feb 2019 16:02:24 +0100 From: Johannes Berg To: linux-wireless@vger.kernel.org Cc: Jouni Malinen , Peng Xu , Sara Sharon , Johannes Berg Subject: [PATCH] cfg80211: fix and clean up cfg80211_gen_new_bssid() Date: Mon, 11 Feb 2019 16:02:22 +0100 Message-Id: <20190211150222.1304-1-johannes@sipsolutions.net> X-Mailer: git-send-email 2.17.2 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 From: Johannes Berg Fix cfg80211_gen_new_bssid() to not rely on u64 modulo arithmetic, which isn't needed since we really just want to mask there. Also, clean it up to calculate the mask only once and use GENMASK_ULL() instead of open-coding the mask calculation. Signed-off-by: Johannes Berg --- include/net/cfg80211.h | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index b61b71f369c7..3f7820b2ea4d 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -5475,22 +5475,20 @@ cfg80211_inform_bss_frame(struct wiphy *wiphy, * @bssid: transmitter BSSID * @max_bssid: max BSSID indicator, taken from Multiple BSSID element * @mbssid_index: BSSID index, taken from Multiple BSSID index element - * @new_bssid_addr: address of the resulting BSSID + * @new_bssid: address of the resulting BSSID */ static inline void cfg80211_gen_new_bssid(const u8 *bssid, u8 max_bssid, - u8 mbssid_index, u8 *new_bssid_addr) + u8 mbssid_index, u8 *new_bssid) { - u64 bssid_tmp, new_bssid; - u64 lsb_n; + u64 bssid_u64 = ether_addr_to_u64(bssid_addr); + u64 mask = GENMASK_ULL(max_bssid - 1, 0); + u64 new_bssid_u64; - bssid_tmp = ether_addr_to_u64(bssid); + new_bssid_u64 = bssid_u64 & ~mask; - lsb_n = bssid_tmp & ((1 << max_bssid) - 1); - new_bssid = bssid_tmp; - new_bssid &= ~((1 << max_bssid) - 1); - new_bssid |= (lsb_n + mbssid_index) % (1 << max_bssid); + new_bssid_u64 |= ((bssid_u64 & mask) + mbssid_index) & mask; - u64_to_ether_addr(new_bssid, new_bssid_addr); + u64_to_ether_addr(new_bssid_u64, new_bssid); } /**