Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4976107imm; Fri, 18 May 2018 14:06:37 -0700 (PDT) X-Google-Smtp-Source: AB8JxZreg4w03n1ZkMUtyW8ktCihTopnqdaUqLiDnX9iLKTgX1Q8RJKYdSEeiq0OPLeGkv5jB3QH X-Received: by 2002:a63:7804:: with SMTP id t4-v6mr8881767pgc.323.1526677597096; Fri, 18 May 2018 14:06:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526677597; cv=none; d=google.com; s=arc-20160816; b=GgD9uTzjqcDf34Ot97W5UWtTDp5CiVyZcrJv3AD6eGEnjzW4Zj67YruHmsCkUfNLdN nAGyPOFFV9iU5tgSCSongKReg4gTyBauAbQq0fgCT1JgDd/uEzVB46XIYi7aQJr8RUFD E68hyNAfFqQDm9pNg8Vyg+Y9yPt4Ljj736RavgK+DxNd1OHNgocHj2+hgVLN2Y9hn5Pe qsFqC8qqr0+UA1+9oTJHM3K9YJymioee9F1eAmeijJN35eBtmugjdOeGS36RrIGSWfel Qbqv0DmWDpH6ncZHR+YU0Rh/PKZrp1DZ53yxJlMj05po77/+FP6tdJr2Mw3ND5gAiVJC 42+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=yxSt7Ttecu0OmyVMm8EFDB4GNtSc0RwvQAyAyyucOkU=; b=nvOtSnBke+iNtNxek7wtEOK4eg1YrFD3EV9qsOpE09Y99vkskUw8oFXs03FYhCeRx0 pFeystaOlSJ47ti8A6JHks5sUwsv3J1Hmi/qZTMsa/M9bfzmHrAkAXM4GqopgIOiPo0D ETCuQP1SuHTWSAND1Waj0uFEUf6a4Zlo+5rP78ze2pyUviH+9iH647ytCyoPBqsMV9cB 4V+bE2ZXJYkUDkTl3hRVqdfwN+tBH1qFqvbGJhsJDZfz7TD6c2JYi4+YfHP6lpJ+nHfK Bl7hGus32WifEFWttO9BswLYKWdIBf9E8rOGJpqdtArT9y8NQ2Znzz4ijqK9YE/njs3C t3zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=b0E9fTRK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 z18-v6si8116481pfd.357.2018.05.18.14.06.22; Fri, 18 May 2018 14:06:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=b0E9fTRK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751914AbeERVFU (ORCPT + 99 others); Fri, 18 May 2018 17:05:20 -0400 Received: from mail-ua0-f193.google.com ([209.85.217.193]:38020 "EHLO mail-ua0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751458AbeERVFT (ORCPT ); Fri, 18 May 2018 17:05:19 -0400 Received: by mail-ua0-f193.google.com with SMTP id y8-v6so6257556ual.5; Fri, 18 May 2018 14:05:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=yxSt7Ttecu0OmyVMm8EFDB4GNtSc0RwvQAyAyyucOkU=; b=b0E9fTRKy9djth3UFp90Ol1RnphY4WKSVb5AVAD49SG6NwnUFYn/ST6FzjTkEEBc4R ac/kKtw3WOuxF5h0N5mHUvFdNeTJFpRFrLi1R0mOBRs3ceZ/ZBKsOmms3TcNuzv7RmYa HB7RM1VtNWr3fX6YYouPqNsFdjPsBYonwjwZafZQPtQ3Bh6CpD4bagOp7KghNwdQj6tR Td22PCg466+jYI9BPya65wTc55oEzZ6ihgyc87PX0MSQ1Enj67DjiXDs4stA9UPa2Clz 7oxc9ceTvtKIXw1VvaohoJXvMGO9xlDaJaX42ZCk17tak56jh5Ri/opmlwumG1o9qsSg GOSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=yxSt7Ttecu0OmyVMm8EFDB4GNtSc0RwvQAyAyyucOkU=; b=GO92D/wcp1ysAkFBZPUEp+++OSTuQC7aKPkBbCtmWtWHP1KTxHnvp2rA/MWqT7Tirh xSwWfUsJ7vwDHjqVZRq01U7OwoizSVwxufNxvbQzCKBXaq2yU50FzOVTo1PKQqMWSdix peCGxE2dh7FmHUTZIyvw5pQlVIL62r4E3I8aVWUmaHqyWbyvPe0+xdhRkL2dLmaZbnpe w6YjSiECMvZD5++IxsO7KjT9+Nb5bq53O0QA1rDiJruPEqTU0gSVrY3ZABv59GooINwh 7jYCFs6e+Kb8D8bXwrWrqNzeqHXKOM/VG/Ufy7CzNfCI3eHd0uitWLQ+x+rJN1Bg/jvU E9Lw== X-Gm-Message-State: ALKqPwd0KoywK87KPpTWyiZstNpZlDGaO9A2QgdVrVR6s1XSxXz70Wq9 DmbcePZKusO2a0bnIDyAVtZthFbfO0riSkRM3d5zCN8X X-Received: by 2002:ab0:5106:: with SMTP id e6-v6mr9079365uaa.33.1526677518385; Fri, 18 May 2018 14:05:18 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.122.10 with HTTP; Fri, 18 May 2018 14:05:17 -0700 (PDT) In-Reply-To: References: <20180518175304.20414-1-labbott@redhat.com> From: Geert Uytterhoeven Date: Fri, 18 May 2018 23:05:17 +0200 X-Google-Sender-Auth: mulm4FPV0fIBYd5V2RvA32Qsl94 Message-ID: Subject: Re: [PATCHv8] gpio: Remove VLA from gpiolib To: Andy Shevchenko Cc: Laura Abbott , Linus Walleij , Kees Cook , Lukas Wunner , Rasmus Villemoes , "open list:GPIO SUBSYSTEM" , Linux Kernel Mailing List , kernel-hardening@lists.openwall.com, Phil Reid Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Andy, On Fri, May 18, 2018 at 10:07 PM, Andy Shevchenko wrote: > On Fri, May 18, 2018 at 8:53 PM, Laura Abbott wrote: >> The new challenge is to remove VLAs from the kernel >> (see https://lkml.org/lkml/2018/3/7/621) to eventually >> turn on -Wvla. >> >> Using a kmalloc array is the easy way to fix this but kmalloc is still >> more expensive than stack allocation. Introduce a fast path with a >> fixed size stack array to cover most chip with gpios below some fixed >> amount. The slow path dynamically allocates an array to cover those >> chips with a large number of gpios. > >> + unsigned long fastpath[2 * BITS_TO_LONGS(FASTPATH_NGPIO)]; >> + unsigned long *mask, *bits; >> int first, j, ret; >> >> + if (likely(chip->ngpio <= FASTPATH_NGPIO)) { >> + mask = fastpath; >> + } else { >> + mask = kmalloc_array(2 * BITS_TO_LONGS(chip->ngpio), >> + sizeof(*mask), >> + can_sleep ? GFP_KERNEL : GFP_ATOMIC); >> + if (!mask) >> + return -ENOMEM; >> + } >> + >> + bits = mask + BITS_TO_LONGS(chip->ngpio); >> + memset(mask, 0, BITS_TO_LONGS(chip->ngpio) * sizeof(*mask)); > > Wouldn't be better > > bitmap_zero(mask, chip->ngpio); > > ? chip->ngpio is never const, so bitmap_zero() would always fall back to plain memset(). Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds