From patchwork Sat Dec 24 16:52:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 9488099 X-Patchwork-Delegate: kvalo@adurom.com 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 98F45601D3 for ; Sat, 24 Dec 2016 17:02:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8655A2074F for ; Sat, 24 Dec 2016 17:02:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7894F212BE; Sat, 24 Dec 2016 17:02:49 +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=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 275E32074F for ; Sat, 24 Dec 2016 17:02:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755627AbcLXRCP (ORCPT ); Sat, 24 Dec 2016 12:02:15 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:34103 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755478AbcLXRCN (ORCPT ); Sat, 24 Dec 2016 12:02:13 -0500 Received: by mail-wm0-f66.google.com with SMTP id c85so8839696wmi.1; Sat, 24 Dec 2016 09:02:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=H00JJydN4xkW4AAW+KW+1KaheT0b3LAJHZfGRoNuPNQ=; b=WkHE6KYLO0VVCcv3wPezgnFBUKjEtEE677xQKXUUpULb46E6ySJJ146CyCGL71MnS2 oZQj3n9+Vkwtj2By7rAQO72UaqQjqIaaE4bw7EmN7iyw3tN/xTtPhe6WFLDagXBgjI6x F64P5sUjy9IVBTUsJU/SVa6UaPW77Ua9siCfqjhYadN+u1aNsrpA+l1pEPCkJbcgnY5z gSOV/UBtMvT0wwHOh2AKBiVIFVBk/woGI0Secf+I8AoHrwSCSIELo4AYmbYvgu2LohE4 64i1pdSGHTRPAAV6zozMLztZFhn+ccnOAqGys9nic50KMtPzC6gheMe9FYOKFcZPL5w2 eA2g== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=H00JJydN4xkW4AAW+KW+1KaheT0b3LAJHZfGRoNuPNQ=; b=CjQPPPpxLjdpHjp1NkDDYOLzWs8X0YuPDcdHtHHbhwpMJSZBFLV/nikfAOJFiJ1Lcq e3SbjzKjhponKWrsaYqyr4zRdkgCxh9socw+rj72N/RCbyF2OW/v6Vgf0L4DfC6/6TiF Pyan35EFUmxP+mHoRLk4iGmo+c++2qcHzq9qcUUbXF7DzfU/QMUtSfhBec9u6oBcaXSJ v+yITNoabX7NS5P19GiGQdJO5WWZG/OmQHjWgbltkEiLxCZExwh2D2NvL93ODtkkzV0i xOlcMub29KNvhKuzmCSC6l6D7gad9tFvd2Z3ii1RuPsfoyOHkaJHI6b3d/y9xT9Ad0L5 uqNw== X-Gm-Message-State: AIkVDXI47n1bm5AQqpZxtJfsgBjbEJ/VPmADIRG0gw+EQDlje80dEc4+lavKR2mnDXMAMQ== X-Received: by 10.28.191.87 with SMTP id p84mr18272103wmf.63.1482598451047; Sat, 24 Dec 2016 08:54:11 -0800 (PST) Received: from localhost.localdomain (ip-88-212-34-237.antik.sk. [88.212.34.237]) by smtp.gmail.com with ESMTPSA id b15sm42736940wma.5.2016.12.24.08.54.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Dec 2016 08:54:10 -0800 (PST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Ming Lei , "Luis R. Rodriguez" , Greg Kroah-Hartman , Kalle Valo , David Gnedt , Michal Kazior , Daniel Wagner , Tony Lindgren , Sebastian Reichel , Pavel Machek , Ivaylo Dimitrov , Aaro Koskinen , Grazvydas Ignotas Cc: linux-kernel@vger.kernel.org, linux-wireless@vger.kernel.org, netdev@vger.kernel.org, =?UTF-8?q?Pali=20Roh=C3=A1r?= Subject: [PATCH 4/6] wl1251: Generate random MAC address only if driver does not have valid Date: Sat, 24 Dec 2016 17:52:59 +0100 Message-Id: <1482598381-16513-5-git-send-email-pali.rohar@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1482598381-16513-1-git-send-email-pali.rohar@gmail.com> References: <1482598381-16513-1-git-send-email-pali.rohar@gmail.com> MIME-Version: 1.0 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 Before this patch driver generated random MAC address every time when was doing initialization. And after that random MAC address could be overwritten with fixed one if provided. This patch changes order. First it tries to read fixed MAC address and if it fails then driver generates random MAC address. Signed-off-by: Pali Rohár Acked-by: Pavel Machek --- drivers/net/wireless/ti/wl1251/main.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/drivers/net/wireless/ti/wl1251/main.c b/drivers/net/wireless/ti/wl1251/main.c index 8971b64..c3fa0b6 100644 --- a/drivers/net/wireless/ti/wl1251/main.c +++ b/drivers/net/wireless/ti/wl1251/main.c @@ -1582,7 +1582,24 @@ int wl1251_init_ieee80211(struct wl1251 *wl) wl->hw->queues = 4; if (wl->use_eeprom) - wl1251_read_eeprom_mac(wl); + ret = wl1251_read_eeprom_mac(wl); + else + ret = -EINVAL; + + if (ret == 0 && !is_valid_ether_addr(wl->mac_addr)) + ret = -EINVAL; + + if (ret < 0) { + /* + * In case our MAC address is not correctly set, + * we use a random but Nokia MAC. + */ + static const u8 nokia_oui[3] = {0x00, 0x1f, 0xdf}; + memcpy(wl->mac_addr, nokia_oui, 3); + get_random_bytes(wl->mac_addr + 3, 3); + wl1251_warning("MAC address in eeprom or nvs data is not valid"); + wl1251_warning("Setting random MAC address: %pM", wl->mac_addr); + } ret = wl1251_register_hw(wl); if (ret) @@ -1623,7 +1640,6 @@ struct ieee80211_hw *wl1251_alloc_hw(void) struct ieee80211_hw *hw; struct wl1251 *wl; int i; - static const u8 nokia_oui[3] = {0x00, 0x1f, 0xdf}; hw = ieee80211_alloc_hw(sizeof(*wl), &wl1251_ops); if (!hw) { @@ -1674,13 +1690,6 @@ struct ieee80211_hw *wl1251_alloc_hw(void) INIT_WORK(&wl->irq_work, wl1251_irq_work); INIT_WORK(&wl->tx_work, wl1251_tx_work); - /* - * In case our MAC address is not correctly set, - * we use a random but Nokia MAC. - */ - memcpy(wl->mac_addr, nokia_oui, 3); - get_random_bytes(wl->mac_addr + 3, 3); - wl->state = WL1251_STATE_OFF; mutex_init(&wl->mutex);