Received: by 10.213.65.68 with SMTP id h4csp1199497imn; Thu, 22 Mar 2018 18:31:58 -0700 (PDT) X-Google-Smtp-Source: AG47ELu7iwXR+O7lsP5TBRSBNA/7O2W8LZKWx6lOOiHVeAhPy5aJ+JrlGJiLGOzV3Xz3S5eaSMYX X-Received: by 10.167.128.2 with SMTP id j2mr22414493pfi.179.1521768718787; Thu, 22 Mar 2018 18:31:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521768718; cv=none; d=google.com; s=arc-20160816; b=DS0SnCyytGFrXFWt+GcjmXxjquiITZEQ+WAWUgDm+MUQ4B//d8lOXCmQeKc18AeSpW 4swe2RO2gsvUhjsBB0g9+fLSWiZzP+rJlMR8NHgme/QRpH4VT9zgV7SS/qBsFnFwhbw/ ZzKDHpIo4P4J7uJ+YQpPXi+qwlDnW/1TRwpXbLXb059iCb1QcjDBzwt3ox3OENsEO411 Cspg2ST+mKIIicnSiAZWGbGX9EMV9CnfFNDABsCd57hiNzP8uYg8dukfXx0k3WZ0JYvk Yt7WiSwkWQqcst10RS2+ZCkk4cn4W8GjdE5HCRGUhWIoz3wPC5FquI8R+DlCOuDrb0LZ 5qvg== 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=bu/vGcmtz2BzNvc/oePdF0NzpE7Sbt+L55B+gubagyo=; b=mgVB8+ZfVAXtm6BvEY/BZ1LL5Kw6A1FZwYeY8ppBfRWDVYrXszysMs/+kzV1dArm+A rY+ELux0hZQOyF/A5zTLSRm6Q3QfAeDa2dbeYPtU0Bm2G6E2F0/2zxI8pDK3ot7N62d/ cHpdpKXA4FHqDRw2gBc5iDjYHENiJOACQy1nwjO3yrvMfecCt0bwSBD3rYkGstPskwtc h59/+LnWmMuNIZe69nw245WrnrJoTxUHemqtgyqTiDmdCyJkzFWJrQptXD9bA7VCy0fV kymjDIQYTkp5cK7K795ahpPpQEl77n1dKnVm6Zq5O1vVoLPcxNJl4oEuz+dA19rV8bTh SESw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d37-v6si2256622plb.566.2018.03.22.18.31.14; Thu, 22 Mar 2018 18:31:58 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751840AbeCWB2V (ORCPT + 99 others); Thu, 22 Mar 2018 21:28:21 -0400 Received: from anchovy1.45ru.net.au ([203.30.46.145]:59284 "EHLO anchovy1.45ru.net.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751714AbeCWB2T (ORCPT ); Thu, 22 Mar 2018 21:28:19 -0400 Received: (qmail 6827 invoked by uid 5089); 23 Mar 2018 01:28:16 -0000 Received: by simscan 1.2.0 ppid: 6751, pid: 6752, t: 0.0386s scanners: regex: 1.2.0 attach: 1.2.0 clamav: 0.88.3/m:40/d:1950 Received: from unknown (HELO ?192.168.0.122?) (preid@electromag.com.au@203.59.235.95) by anchovy1.45ru.net.au with ESMTPA; 23 Mar 2018 01:28:16 -0000 Subject: Re: [PATCHv2 4/4] gpio: Remove VLA from stmpe driver To: Laura Abbott , 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> <90e40062-cedb-be32-ab17-56136c78dbad@redhat.com> From: Phil Reid Message-ID: Date: Fri, 23 Mar 2018 09:28:07 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <90e40062-cedb-be32-ab17-56136c78dbad@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-AU Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 23/03/2018 05:43, Laura Abbott wrote: > 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. That's the other way to go. >>> --- >>>   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; >>>   } >>> >> >> > > > -- Regards Phil Reid