From patchwork Wed May 20 18:15:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 6448401 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 63FF9C0432 for ; Wed, 20 May 2015 18:15:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 834EA20394 for ; Wed, 20 May 2015 18:15:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8AF5220382 for ; Wed, 20 May 2015 18:15:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754333AbbETSPJ (ORCPT ); Wed, 20 May 2015 14:15:09 -0400 Received: from mail-wi0-f170.google.com ([209.85.212.170]:35626 "EHLO mail-wi0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753731AbbETSPH (ORCPT ); Wed, 20 May 2015 14:15:07 -0400 Received: by wicmx19 with SMTP id mx19so164273633wic.0 for ; Wed, 20 May 2015 11:15:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=+BCsNjCfX89Z0P3V7RTpePGKFCw28LwBFWswIFT9/fE=; b=Sc7SNH/O50A15M01Um+uQtKWwhqWibuE9XAjk/MVFW46x158vQdGl4+euTFnvy3OoL WGkm5ipMZo40iN4XjFMRGtyB46FExT4WqAceGv+x5Jo5Th+7f/bnM0Bmt8TkwdJFhZq2 VF0fjbWNpc9Q0/bqy+ZmE2Mpr+oCwtXmI3F8l+V6mzamSWSVecCD75o2Okbd6Eo3oQvl FSFaH5tRrgy89ciQoSgTfJ3eR/OaGyRu0nYaRUQ74o4U8EvrSO3fUFzMmINnDgq5c5zQ 8b4FFe2VydVfg6JyCSyzDxnDWDvLTwLcoL5bquen8lk6LndFW24O0dDIOisEVx0VZJ0n rtFg== X-Received: by 10.180.19.100 with SMTP id d4mr44267207wie.29.1432145706652; Wed, 20 May 2015 11:15:06 -0700 (PDT) Received: from linux-tdhb.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by mx.google.com with ESMTPSA id l6sm28057088wjz.4.2015.05.20.11.15.05 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 May 2015 11:15:05 -0700 (PDT) From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= To: Kalle Valo , linux-wireless@vger.kernel.org Cc: Brett Rudley , Arend van Spriel , "Franky (Zhenhui) Lin" , Hante Meuleman , brcm80211-dev-list@broadcom.com, =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= Subject: [PATCH V2] brcmfmac: allow NVRAM values to contain space and '#' chars Date: Wed, 20 May 2015 20:15:01 +0200 Message-Id: <1432145701-15150-1-git-send-email-zajec5@gmail.com> X-Mailer: git-send-email 1.8.4.5 In-Reply-To: <1432145442-14284-1-git-send-email-zajec5@gmail.com> References: <1432145442-14284-1-git-send-email-zajec5@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-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Both chars often require special handling (and brcmf_nvram_handle_idle already takes care of them) but they should be allowed when parsing entry value. Some example entries from SR400ac device NVRAM: 1:ccode=#a wl0_version=7.14.43.16 (r) Signed-off-by: Rafa? Mi?ecki --- V2: Minor change in commit message only. Provide an example of NVRAM entry using space (not just a '#'). It's unprefixed (shouldn't be uploaded to hardware anyway), but proves it's allowed in general. --- drivers/net/wireless/brcm80211/brcmfmac/firmware.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/net/wireless/brcm80211/brcmfmac/firmware.c b/drivers/net/wireless/brcm80211/brcmfmac/firmware.c index 45d7191..64e2491 100644 --- a/drivers/net/wireless/brcm80211/brcmfmac/firmware.c +++ b/drivers/net/wireless/brcm80211/brcmfmac/firmware.c @@ -66,14 +66,15 @@ struct nvram_parser { bool multi_dev_v2; }; -static bool is_nvram_char(char c) +/** + * is_printable_char() - check if char is ASCII printable one + * + * Please note that '#' may require different handling depending on the context. + * It's used as comment beginning and it's not allowed in key name. + */ +static bool is_printable_char(char c) { - /* comment marker excluded */ - if (c == '#') - return false; - - /* key and value may have any other readable character */ - return (c > 0x20 && c < 0x7f); + return (c >= 0x20 && c < 0x7f); } static bool is_whitespace(char c) @@ -92,7 +93,7 @@ static enum nvram_parser_state brcmf_nvram_handle_idle(struct nvram_parser *nvp) goto proceed; if (c == '#') return COMMENT; - if (is_nvram_char(c)) { + if (is_printable_char(c)) { nvp->entry = nvp->pos; return KEY; } @@ -120,7 +121,7 @@ static enum nvram_parser_state brcmf_nvram_handle_key(struct nvram_parser *nvp) nvp->multi_dev_v1 = true; if (strncmp(&nvp->fwnv->data[nvp->entry], "pcie/", 5) == 0) nvp->multi_dev_v2 = true; - } else if (!is_nvram_char(c)) { + } else if (!is_printable_char(c) || c == ' ' || c == '#') { brcmf_dbg(INFO, "warning: ln=%d:col=%d: '=' expected, skip invalid key entry\n", nvp->line, nvp->column); return COMMENT; @@ -140,7 +141,7 @@ brcmf_nvram_handle_value(struct nvram_parser *nvp) u32 cplen; c = nvp->fwnv->data[nvp->pos]; - if (!is_nvram_char(c)) { + if (!is_printable_char(c)) { /* key,value pair complete */ ekv = (u8 *)&nvp->fwnv->data[nvp->pos]; skv = (u8 *)&nvp->fwnv->data[nvp->entry];