From patchwork Thu Nov 9 23:38:24 2017 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: 10052105 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 C08986032D for ; Thu, 9 Nov 2017 23:41:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B2E492B1D8 for ; Thu, 9 Nov 2017 23:41:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A79F22B1DC; Thu, 9 Nov 2017 23:41:28 +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.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, 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 4FC242B1D8 for ; Thu, 9 Nov 2017 23:41:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755203AbdKIXlI (ORCPT ); Thu, 9 Nov 2017 18:41:08 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:45840 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754802AbdKIXiv (ORCPT ); Thu, 9 Nov 2017 18:38:51 -0500 Received: by mail-wm0-f68.google.com with SMTP id y80so20381847wmd.0; Thu, 09 Nov 2017 15:38:50 -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=NIOuqHZFjClZVAJk6bmfBNgFCyrhdDEGx+1xtZgRaXo=; b=KLajNXCLoG3bHDm+rzRXQEnN+Ol5GQV45Sil1S7gkcWKYFLTavv0X/fd+sPxsFAVHu XGmjg8z6YgD97TevAra8kmx2tUDiDvtjCuQYsGizYSpDYISmXN1lKYzWmQIoiO0Q6aBT HSM9Wwf5rkSat+/fI1/qnOdSOTpXT8GxxdmiCxhOrPIUyXcgNJcaS57UhDfpSybTuFHA 3dqmOWuRXncNor/7sO+/79xN1iSVDXivdKNim42MyrurFNPDRMkjJkq7IHDz+XBzcHOJ SFlda8mP/zxAI2X1AxC59r8GKDeEO7V8lNJCUr894dlzsNx3XEPt+Uk9IzDkiI7cltwG zwZw== 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=NIOuqHZFjClZVAJk6bmfBNgFCyrhdDEGx+1xtZgRaXo=; b=NsAfvuCzKFFukCU6ZureHvgyVMpJV8Ns/W4+TPgaaimDs79MkHEw3KSV2b7y0NhlNB spZMjydmKUadT6nVkE1ekufv26lA9z++C17YWD/24SVHDLkCUjTjuirTlOUl6satgkzw 6C7P5OT9qgfziDqVevyh80jhWNa+AabrY8apeWk/CqoBInWK3xuwM0ChS7w+zm5wcC9H yq2AxYoBWiWzGKOnNXvf9FRT/GPYua2N9vkPGOIHg5W1ynC1GuEFD2g0Y/tuLzco5jHt XoONf2HapbYIliQejQoHzCR9AMUpW7YHgQkoTml9dHWGLE34ORetahPp7Kad0R3KH0Xy M/VQ== X-Gm-Message-State: AJaThX79O3o+bxYl/fLaTco72M8UAQLhVwOUrroA3G996z+hLlp3oWZm Abcm08jEe2hml68ZVeAV60o= X-Google-Smtp-Source: AGs4zMYsuWZNWwggWQF+IFQNgE9r0CexwA4gy8B+67gdOI6F7uf5FpaJkYON3X8heJYTeK/MQZJqLQ== X-Received: by 10.28.197.65 with SMTP id v62mr1017199wmf.9.1510270729595; Thu, 09 Nov 2017 15:38:49 -0800 (PST) Received: from Pali-Latitude.lan (pali.kolej.mff.cuni.cz. [78.128.193.202]) by smtp.gmail.com with ESMTPSA id 55sm9578181wrw.60.2017.11.09.15.38.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Nov 2017 15:38:48 -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 v2 2/6] wl1251: Generate random MAC address only if driver does not have valid Date: Fri, 10 Nov 2017 00:38:24 +0100 Message-Id: <1510270708-14377-3-git-send-email-pali.rohar@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1510270708-14377-1-git-send-email-pali.rohar@gmail.com> References: <1482598381-16513-1-git-send-email-pali.rohar@gmail.com> <1510270708-14377-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 it was initialized. 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 8929bb3..9106c20 100644 --- a/drivers/net/wireless/ti/wl1251/main.c +++ b/drivers/net/wireless/ti/wl1251/main.c @@ -1492,7 +1492,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) @@ -1513,7 +1530,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) { @@ -1563,13 +1579,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); spin_lock_init(&wl->wl_lock);