Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2395808yba; Mon, 6 May 2019 05:30:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqxZAcBpiujUXx8E2ixcNrM4VMJYDDredm/yPL7e6RSz16NhvjLnndz0sCLIs7+GCMck3G06 X-Received: by 2002:a17:902:8ec8:: with SMTP id x8mr31538194plo.21.1557145802340; Mon, 06 May 2019 05:30:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557145802; cv=none; d=google.com; s=arc-20160816; b=YXK3L7QZKpma3hP0MJct18kSfMhmTR+suxwf+jWWvyCHucXwyMsTFUL3aKuOOg/Qsv cjvOrreLG5FjlhBLgmk2+HSaqr7MRQdhgjbSh4j/a3zyerhjsJWH0y1cPTVZuMkVZdae Vdojjmdzyn8vRKTKAelRqsddEtshwlICLobJnJyiKPHfFXOiaJGPpN9C0vItFCQ27lvN UiLlHKUA+GFYbcIGpj6lOVolMxhu3spXIckRe7YGCySiotJXGY1WoQSKSDAg1x7DvrW6 wm2hZG00l2fg1L6ZjRqBOirbgs+4GL1rP1AbBSA/yqT9JdVVdPzQ1xENUMRNXe1Sl3xe qr2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from:dmarc-filter :dkim-signature:dkim-signature; bh=y5R3XDf7jio3gxX0CMY1TyvtD4Gw/y21EswkMV1EMjo=; b=fx5HurCDAlb5QlhpZdD9e4GQd8I+FyEB5w+5EQfFc/k9RObPTnmleEamdM4rfpOCDH twdrh3PT71TnhZCBtNDR3+2E5HQD3xbPhTgOc7VG5N3lKjrq3GaF3NX81hFboIbpEaqK WUTSXvKzKaerLSzjH9OTDCC4UMWlnqkXKg0hUHNdAwRu5ZRVtoHmwtH8rKkwYIxK2s9k rHEX5yal4DXYEW2+rhbZbN5FDYyrIQTWqpzE2KZpoLuI/5gFNuCK5z/IX+pk5eS7oCTf lVuDiVzzV7hmc7BKXMh2HRscDXq6gnfz+9W/LG9cqtFwqhF9+2cQPRwKJCshu85k+x9L RR7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b="gKs7elg/"; dkim=pass header.i=@codeaurora.org header.s=default header.b=Zo1+MTb4; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j12si14417473plk.144.2019.05.06.05.29.47; Mon, 06 May 2019 05:30:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b="gKs7elg/"; dkim=pass header.i=@codeaurora.org header.s=default header.b=Zo1+MTb4; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726321AbfEFM32 (ORCPT + 99 others); Mon, 6 May 2019 08:29:28 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:58148 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726302AbfEFM31 (ORCPT ); Mon, 6 May 2019 08:29:27 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id C7CFC60AA8; Mon, 6 May 2019 12:29:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1557145766; bh=VCvP/gZAtcdtOifWNcdeLJAMQjdxY3mj3YVbMsOAGFI=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=gKs7elg/jakUd1+If6pY68R2V2fGRDiDkVZnz7fRxK+hiBdNjaMGjyvIp9KnI/hKJ z9MXEHrPirmW10V6rW3x+jEr4zKke9MZjCvwZQElbkqUqA3xyppoSvil+P268o2Az+ nEabs75gO9UfpmaqXTCWcB1NUqULdTYT4upQvfMM= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_INVALID,DKIM_SIGNED autolearn=no autolearn_force=no version=3.4.0 Received: from x230.qca.qualcomm.com (85-76-75-57-nat.elisa-mobile.fi [85.76.75.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: kvalo@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 3B5676063F; Mon, 6 May 2019 12:29:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1557145765; bh=VCvP/gZAtcdtOifWNcdeLJAMQjdxY3mj3YVbMsOAGFI=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=Zo1+MTb4vOE/Wr9aNHItSl0CLGLIok2gBzecwaLxeD8j8IWrtk6cFTxoD9gQAm3ba QnY+juX0Pt4luoptzPeLC1F7toNvNAyoxOvcZYuPu7QXLhFAgqD33zvdTCGViokt8z NB8LqrF5CcuTf+FE1mYYRY4nUWRVWnjzmgEVHsQk= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 3B5676063F Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=kvalo@codeaurora.org From: Kalle Valo To: Victor Bravo <1905@spmblk.com> Cc: Hans de Goede , Arend Van Spriel , Franky Lin , Hante Meuleman , Chi-Hsien Lin , Wright Feng , "David S. Miller" , linux-wireless@vger.kernel.org, brcm80211-dev-list.pdl@broadcom.com, brcm80211-dev-list@cypress.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH RFC] brcmfmac: sanitize DMI strings v2 References: <20190504162633.ldrz2nqfocg55grb@localhost> <20190504194440.4zcxjrtj2aft3ka4@localhost> <16a87149068.2764.9b12b7fc0a3841636cfb5e919b41b954@broadcom.com> <20190505150355.3fbng4ny34x255vk@localhost> <0f75a3d4-94af-5503-94c3-e8af2364448d@redhat.com> <87o94gug81.fsf@codeaurora.org> <20190506091441.wqtccm4n6xxhxom2@localhost> Date: Mon, 06 May 2019 15:29:21 +0300 In-Reply-To: <20190506091441.wqtccm4n6xxhxom2@localhost> (Victor Bravo's message of "Mon, 6 May 2019 11:14:41 +0200") Message-ID: <878svjvk9q.fsf@codeaurora.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Victor Bravo <1905@spmblk.com> writes: > On Mon, May 06, 2019 at 11:42:06AM +0300, Kalle Valo wrote: >> Hans de Goede writes: >> >> >> @@ -99,6 +107,15 @@ static const struct dmi_system_id dmi_platform_data[] = { >> >> {} >> >> }; >> >> +void brcmf_dmi_sanitize(char *dst, const unsigned char *allowed, >> >> char safe) >> >> +{ >> >> + while (*dst) { >> >> + if ((*dst < 0) || !(allowed[*dst / 8] & (1 << (*dst % 8)))) >> > >> > At a first look I have no clue what this code is doing and I honestly do not feel >> > like figuring it out, this is clever, but IMHO not readable. >> > >> > Please just write this as if (*dst < 0x21 || (*dst > foo && < bar) || etc, >> > so that a human can actually see in one look what the code is doing. >> >> Is there an existing function for sanitising filenames so that we don't >> need to reinvent the wheel, maybe something like isalnum()? > > I would definitely prefer to use existing function, but I didn't find > any suitable one. Suggestions are welcome. I didn't find anything either, but hopefully someone knows. > As for implementation details, the one I posted was optimized for both > speed and size, and at least in my opinion this bit array driven > parametric implementation is exactly what is needed here (using a string > of allowed characters with strchr-style lookups would bring much worse > complexity, and checking the characters using series of hardcoded if > conditions could quickly grow to more than those 16 bytes used by the > array). But is this really something which should be optimised? This is driver initialisation, not in some hot path, right? Can you even measure the difference? -- Kalle Valo