Received: by 10.213.65.68 with SMTP id h4csp395488imn; Fri, 30 Mar 2018 07:35:19 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/bJ8HKP99vemBeI41bqk/T/aKo86Ev+qDuGFH/zNQTyGyvC9PY0+oPETZws13R8G/4tiPe X-Received: by 10.99.123.80 with SMTP id k16mr8712616pgn.173.1522420519295; Fri, 30 Mar 2018 07:35:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522420519; cv=none; d=google.com; s=arc-20160816; b=OUaAHbTjxUwT7ZQ3UfIZ9mu0L9Gf03J7/qN8fQDaMGrAuWj7yIeoZTA/zQ91VB45a8 n+9EwDEz7TX73ibm38I5oH9LDLeYlYIJsjmmE0ZDysQkgk9/OrUC4HoIAsvRn5IAy5J1 juyrWIF1DdmRXo6EjaDit7Rw9QovOyTyF3SAlVpxgDBqjGtecR7xTjMEzostrWAdb0WV /qHcN6wh9L9IURvR6AJB63szFDktNkeuVEllKLuKiODjJVlNaRzESHVaFGfvV8nPcl/f oWZWD23hpX/58v2uRC8NvDav7aey41akMG4JqiaZEyBT0YxabARmCzacjHrVkhikzcgq 6/TQ== 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=/HZVPAaSaPNPDRPjYKQ71qhIU20IEgB9M8FYbMdSmmA=; b=z5FaH6XYS7xpCs17ZgYZtnRL+ocPiQcb4NEnh9NjObFwtVUBsgRW7k3KSH8JPboDNx H51zOb1+nE10Z7msguL0mHGmyOL5Mb+kJcPKjRm88MObgHICvIub2vIfbaRWyp/YU7A2 ntkvpkYtdMiwA+C+99hjhnUB2wI0VrpboMg+fHn7NmmVeMUadForJY4tpCboJxltGEcY AXXOH1y40yiDtEpsVjO9ZMpH08mh+eLuAzbpBgwor1NWXzC4yvG6ArqzMB0VP4Tg6yg/ bDAG+GFLek97wbu3sm+8RdG684wf0peNGou+nOBXWHNNJXVl15FhvZuHEdBLJevYt0vf YqKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=oL3CVSuZ; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a84si6508751pfl.154.2018.03.30.07.35.04; Fri, 30 Mar 2018 07:35:19 -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=pass header.i=@gmail.com header.s=20161025 header.b=oL3CVSuZ; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751361AbeC3Od6 (ORCPT + 99 others); Fri, 30 Mar 2018 10:33:58 -0400 Received: from mail-qt0-f193.google.com ([209.85.216.193]:36882 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751163AbeC3Od4 (ORCPT ); Fri, 30 Mar 2018 10:33:56 -0400 Received: by mail-qt0-f193.google.com with SMTP id w12so9549275qti.4; Fri, 30 Mar 2018 07:33:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=/HZVPAaSaPNPDRPjYKQ71qhIU20IEgB9M8FYbMdSmmA=; b=oL3CVSuZlTBcIALUgvMXt8nYl+EF7XhNa7Qsvg55omRGad4Z447fmuMrr9zxZMBqoh 9GtdwV5M2tKqwoEi4dHfKK4RspV/fEot+Z1rAvXFuGsF4/HikGE4B1k0bytJkxXZOhS3 FNGWfxI2IP2ji2JV0sYtVGRjIPM5s+EJ31jMJWbP2xTcCFcqJf5I4wEsyq4bApR4QSGR 8k7kXLu+/KAbd1FT7AXxo5Ax3n4oxYPuQwInzIfMbJX+/r/7qcnjblI0WHkZ2RBb1y6B mNbxxy/btJK/GK0aL0oaSMjXx2pfAjfULyVMkzdOwDfg5W7NnAiBj6zmGxr4bQBo/9R5 Slvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=/HZVPAaSaPNPDRPjYKQ71qhIU20IEgB9M8FYbMdSmmA=; b=G6D31b0xpgv99cqBFher10q86zo5HWIs1PG0rYDsyRk00mzZHJHxuflnlNJEvOQSBS 4ZyMVH7J7/+0wFCci5L/oV7Kjm5yoKrE4Y831IPoRJhXhGV0Wxpmebc4rniRKLWl8dJV 1NNAkkZinCgU5r9xJKjkN/88Bj0a5GweWbjmEeJTPkg+D12ZfgZNNmS0J4QkfOAz2UK+ We/xp05/T0OLnHOGBD0PNFXQTdA1PTTxomCN5WdJmzYGL85QRQgE9CBMs66eksdZMUlf 12z3hNG7YaErTWfb/uvFvAgWVF06/WIh4veU4FM9t0wsoM6M2mPyXvnY70emEtGGs6T8 HRhw== X-Gm-Message-State: AElRT7FAfpeS1kayG4VGNKCoWDjuP7SyfZxhXqwIB7R7UG4irKN0Sl0i juDmrOoD5XRFoOzBFgmgc5bN4plcI/0Yd8pV9b8= X-Received: by 10.237.48.229 with SMTP id 92mr17774627qtf.39.1522420435873; Fri, 30 Mar 2018 07:33:55 -0700 (PDT) MIME-Version: 1.0 Received: by 10.12.137.74 with HTTP; Fri, 30 Mar 2018 07:33:55 -0700 (PDT) In-Reply-To: <20180328181809.24505-1-labbott@redhat.com> References: <20180328181809.24505-1-labbott@redhat.com> From: Andy Shevchenko Date: Fri, 30 Mar 2018 17:33:55 +0300 Message-ID: Subject: Re: [PATCHv3] gpio: Remove VLA from gpiolib To: Laura Abbott Cc: Linus Walleij , Kees Cook , Lukas Wunner , "open list:GPIO SUBSYSTEM" , Linux Kernel Mailing List , kernel-hardening@lists.openwall.com, Rasmus Villemoes 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 On Wed, Mar 28, 2018 at 9:18 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. > + ret = gpiod_set_array_value_complex(false, > true, > lh->numdescs, > lh->descs, > vals); > + if (ret) > + return ret; > + > return 0; Can't we return gpiod_set_array_value_complex(); ? > + slowpath = kcalloc(2 * BITS_TO_LONGS(chip->ngpio), > + sizeof(*slowpath), > + can_sleep ? GFP_KERNEL : GFP_ATOMIC); > + if (slowpath) > + kfree(slowpath); > + if (slowpath) > + kfree(slowpath); Since slowpath is a pointer, conditionals above are redundant. > + slowpath = kcalloc(2 * BITS_TO_LONGS(chip->ngpio), > + sizeof(*slowpath), > + can_sleep ? GFP_KERNEL : GFP_ATOMIC); > + if (slowpath) > + kfree(slowpath); Ditto. -- With Best Regards, Andy Shevchenko