From patchwork Wed Mar 28 17:59:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laura Abbott X-Patchwork-Id: 892410 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40BFz63LmRz9s0p for ; Thu, 29 Mar 2018 05:00:18 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753376AbeC1SAR (ORCPT ); Wed, 28 Mar 2018 14:00:17 -0400 Received: from mail-ot0-f195.google.com ([74.125.82.195]:33480 "EHLO mail-ot0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753079AbeC1SAQ (ORCPT ); Wed, 28 Mar 2018 14:00:16 -0400 Received: by mail-ot0-f195.google.com with SMTP id 23-v6so3635932otj.0 for ; Wed, 28 Mar 2018 11:00:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=NHdieeeSjaiY6HtBJW1vciGM6wbi5+/JgzJYPQWlW60=; b=ZXdnDBGwUhitBXLY8CfvNQg8XZjZlo+fv1m0Yt5TCqGEgBEVTvgHPJZBec7lhkz0+E EuBU3sS1fWS5VsV0ByKCp9hW7aGlsN6ZwAy/+0uYJLIuaEfq4FW85ZTw5xOUOUt4dObI PqcsNnpaNP5wdUAElX21XkRMIIkt3T5w6suZozJTtkEbiOEPnkNZ4k2Imq01amYFwV9W 0HeTIz4WO68ZZ/2jHrQWPvrGh9krme3aFxfMeoUy2WdGYGsp/YXhEQA9jaBJ3IOdYCkI 9lGri4TSXNGQPyVOxXx1ZYeZlWvKhjBgVHnvVMMvKTujzE6NKxH2YNUxmAfHT+oehYTO gDig== X-Gm-Message-State: AElRT7H6QR2F9RuMF5HukhBU/H1X47sFzvZIa5TkjeK/RCoVUn/QngOM JkWanGFNTHpBd6pMXHdYcV/mLQ== X-Google-Smtp-Source: AIpwx48HnUbDcJ5fYlBQ2uEotJW5AnuXCV5eSpEs3iSjkmpykMGZ7r/PFUmi0BEDh3A+ym3Gihsgqw== X-Received: by 2002:a9d:5a15:: with SMTP id v21-v6mr3054557oth.301.1522260016086; Wed, 28 Mar 2018 11:00:16 -0700 (PDT) Received: from labbott-redhat.redhat.com ([2601:602:9802:a8dc:4eb2:6dae:ab32:e5b0]) by smtp.gmail.com with ESMTPSA id g21-v6sm2418147ote.58.2018.03.28.11.00.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 28 Mar 2018 11:00:14 -0700 (PDT) From: Laura Abbott To: Linus Walleij , Kees Cook , Patrice Chotard Cc: Laura Abbott , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com Subject: [PATCH v3] gpio: Remove VLA from stmpe driver Date: Wed, 28 Mar 2018 10:59:57 -0700 Message-Id: <20180328175957.23904-1-labbott@redhat.com> X-Mailer: git-send-email 2.14.3 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org The new challenge is to remove VLAs from the kernel (see https://lkml.org/lkml/2018/3/7/621) The number of GPIOs on the supported chips is fairly small so stack allocate to a known upper bound and spit out a warning if any new chips have more gpios. Signed-off-by: Laura Abbott Reviewed-by: Phil Reid Reviewed-by: Kees Cook --- v3: Split this off from the rest of the series since some of the patches had been picked up. Switched to just hardcoding an upper bound for the stack array since it's only a few extra bytes of stack space. --- drivers/gpio/gpio-stmpe.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpio-stmpe.c b/drivers/gpio/gpio-stmpe.c index f8d7d1cd8488..8d6a5a7e612d 100644 --- a/drivers/gpio/gpio-stmpe.c +++ b/drivers/gpio/gpio-stmpe.c @@ -363,13 +363,15 @@ static struct irq_chip stmpe_gpio_irq_chip = { .irq_set_type = stmpe_gpio_irq_set_type, }; +#define MAX_GPIOS 24 + static irqreturn_t stmpe_gpio_irq(int irq, void *dev) { struct stmpe_gpio *stmpe_gpio = 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[DIV_ROUND_UP(MAX_GPIOS, 8)]; int ret; int i; @@ -434,6 +436,11 @@ static int stmpe_gpio_probe(struct platform_device *pdev) struct stmpe_gpio *stmpe_gpio; int ret, irq; + if (stmpe->num_gpios > MAX_GPIOS) { + dev_err(&pdev->dev, "Need to increase maximum GPIO number\n"); + return -EINVAL; + } + stmpe_gpio = kzalloc(sizeof(*stmpe_gpio), GFP_KERNEL); if (!stmpe_gpio) return -ENOMEM;