Received: by 10.213.65.68 with SMTP id h4csp1074357imn; Thu, 22 Mar 2018 14:45:05 -0700 (PDT) X-Google-Smtp-Source: AG47ELtYHw5CPoCeDDHBqkFWRxrjWrlVeBCn0N7Uhwi3i4EvZ7MgXzcn7u5by/BRtlQwV9z/6YaC X-Received: by 10.99.54.73 with SMTP id d70mr8168399pga.86.1521755105327; Thu, 22 Mar 2018 14:45:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521755105; cv=none; d=google.com; s=arc-20160816; b=eUs31NDKNHhtHvJ3+sGznFUI+Cy1F9ZmrknZVu68aU+h7ED7+BZQWIHX95iUauRObU Ks8bBqQGEZD2jqX//WIGuBnoIdrpBq75ZWp8gp5V9ktAm5d3n4AYiYJzr958FEEpib+z XrRe7FErSnyDD+ptjkUtoJHhY5OxLM1pnNDqyHWYWbGtNJNmyg+cKUCPvPx/c9r+7mPe Ca3k37tEZXlGutix2kTHe+YTbzEjet2T7Vp3zOwb0f7ecDP2jEIm4kvcekOOBg33S6Vb ByBpegMf3sNz6fy9lJPRYR+dvkr4XXGj+T1ZtB0bDdmA91xruEdDlrxtK6qvlnxAcxgi iE+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=WYPJwJ+VGR5QzPNH9TckmeyiBT5PXpFys3PWnv1QRtA=; b=kaNJzIJXVFZ5/+l4zplvoeoVwGTxL2nR69ys01sTwMYnAjHH+AYiwSdY1SC/cLpyQP ZkSerFO8cxprAj1oDXq9YGcg8SOJrSL+xo7mBIXLveN4VFD0Hs+BZ1q34JpH63g4eOSo bRJjtJTW3mUwdpgqcJJpxeM5q3JGi6q18sq6Yd4I3ohxrXdeM/sIysoHDsTEhyC0wdSe c0B/GwilPoDaE098EnJrxWpSxnbmWuB7nXz965eoXYkNdkg2VoazrQBpLLZu/DMa6Mur 5cCs53w+7MH4SRnE615mdbOhd8SoKQ2uFHR3BgmaMHC1lU6GU73QnGZ4/GD2uA0HkZeE XH3A== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y72-v6si7423821plh.72.2018.03.22.14.44.50; Thu, 22 Mar 2018 14:45:05 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751966AbeCVVnp (ORCPT + 99 others); Thu, 22 Mar 2018 17:43:45 -0400 Received: from mail-oi0-f67.google.com ([209.85.218.67]:34005 "EHLO mail-oi0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751625AbeCVVnm (ORCPT ); Thu, 22 Mar 2018 17:43:42 -0400 Received: by mail-oi0-f67.google.com with SMTP id u141-v6so8699909oif.1 for ; Thu, 22 Mar 2018 14:43:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=WYPJwJ+VGR5QzPNH9TckmeyiBT5PXpFys3PWnv1QRtA=; b=TPhzXHvFi2z/o2XY8JpXlh/J63ps152xfejPkHV+aQIZc9iLllQAODsUxIoax5fDiI jYecdFWPaTKRQgf4jAOJ+oZ+6gZ1UOM9dV/Oxo8AVojKeTlJHzqFi0fTXw3X47BkQijl bGhLDzpJMgAbyZAJ4hD1lRiS3rfEEBPgoLRdJ+XIbjngcsu7XFiK1ql/zlCf9LgSfrpe RcqCXvmHRd59ARQKtVC+Y6xV9eUQpg6zJS36aawxihIWQuLjJFxGIQuGuJBn1KkC5/bA Hfmp5+MIzTcNnKDLy72vcprdPumOmvfwBdNp2Uc/RWrGtuty5uyHProtrQnck6L3lCzk 0Xsw== X-Gm-Message-State: AElRT7Hk5iIxFMhT6U9nDFVlmmXuXu3JQCI5L+rubIxwrqXSxHTv1PP5 GORu6Y3Hg2C/rMLYxYbIKff4iQ== X-Received: by 10.202.71.68 with SMTP id u65mr9873442oia.258.1521755022439; Thu, 22 Mar 2018 14:43:42 -0700 (PDT) Received: from ?IPv6:2601:602:9802:a8dc::b761? ([2601:602:9802:a8dc::b761]) by smtp.gmail.com with ESMTPSA id s11-v6sm4623197ots.18.2018.03.22.14.43.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Mar 2018 14:43:41 -0700 (PDT) Subject: Re: [PATCHv2 4/4] gpio: Remove VLA from stmpe driver To: Phil Reid , Linus Walleij , Kees Cook , Patrice Chotard Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com References: <20180315180030.20001-1-labbott@redhat.com> <20180315180030.20001-5-labbott@redhat.com> <21a2e869-62fb-75ef-ae7b-a27e136696f7@electromag.com.au> From: Laura Abbott Message-ID: <90e40062-cedb-be32-ab17-56136c78dbad@redhat.com> Date: Thu, 22 Mar 2018 14:43:39 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <21a2e869-62fb-75ef-ae7b-a27e136696f7@electromag.com.au> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/18/2018 06:29 PM, Phil Reid wrote: > On 16/03/2018 02:00, Laura Abbott wrote: >> The new challenge is to remove VLAs from the kernel >> (see https://lkml.org/lkml/2018/3/7/621) >> >> This patch replaces a VLA with an appropriate call to kmalloc_array. >> >> Signed-off-by: Laura Abbott >> --- >> v2: Switch to GFP_KERNEL. There was some discussion about if we should >> be doing the allocation at all but given a) the allocation is pretty >> small and b) we can possibly take a mutex in a called function I think >> this is fine. > > I still think it's a bad idea. It's simple to preallocate the buffer. > But it's up to the maintainer. > I'd feel a lot more confident about doing the global buffer with guidance from the maintainer. But looking at the platform data, the maximum number of GPIOs is 24, or 3 banks. Maybe we should just always stack allocate the maximum since it's fairly small. Thanks, Laura > >> --- >>   drivers/gpio/gpio-stmpe.c | 7 ++++++- >>   1 file changed, 6 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/gpio/gpio-stmpe.c b/drivers/gpio/gpio-stmpe.c >> index f8d7d1cd8488..c2bb20ace6f5 100644 >> --- a/drivers/gpio/gpio-stmpe.c >> +++ b/drivers/gpio/gpio-stmpe.c >> @@ -369,10 +369,14 @@ static irqreturn_t stmpe_gpio_irq(int irq, void *dev) >>       struct stmpe *stmpe = stmpe_gpio->stmpe; >>       u8 statmsbreg; >>       int num_banks = DIV_ROUND_UP(stmpe->num_gpios, 8); >> -    u8 status[num_banks]; >> +    u8 *status; >>       int ret; >>       int i; >> +    status = kmalloc_array(num_banks, sizeof(*status), GFP_KERNEL); >> +    if (!status) >> +        return IRQ_NONE; >> + >>       /* >>        * the stmpe_block_read() call below, imposes to set statmsbreg >>        * with the register located at the lowest address. As STMPE1600 >> @@ -424,6 +428,7 @@ static irqreturn_t stmpe_gpio_irq(int irq, void *dev) >>           } >>       } >> +    kfree(status); >>       return IRQ_HANDLED; >>   } >> > >