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: 10313757 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 439C560212 for ; Wed, 28 Mar 2018 18:00:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 33D4325D9E for ; Wed, 28 Mar 2018 18:00:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 26C7829103; Wed, 28 Mar 2018 18:00:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 3AFCD25D9E for ; Wed, 28 Mar 2018 18:00:33 +0000 (UTC) Received: (qmail 13782 invoked by uid 550); 28 Mar 2018 18:00:28 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 13732 invoked from network); 28 Mar 2018 18:00:27 -0000 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=BefY5ZCAqELT2b52Uj4jrwQqDFfr1hxiSDV+yzHF+4ZfLqXJ570cVWK+QSqWNCPPJg ktjXBVeTOhwE1viE1WmTHzHbPxg/wK3l3MKZ2gsrwnUiTw0eXCEpCl+RzVcRt3ruuToV emy5an50p2mhXLU7e2J66dj40flI8eOkx2Ej/pz/yAyD0LnNjFgqykKlQKZ3qL6Nj0R2 oWit+Mu4lBni1rhnJ/kzKOr89gXBxSq0I6XKN3dy9GkraoVWcl0ju0fQlEz8lMkBQpib O+R9jLU2P+9sQfLf5LzSZH8Ks8+XaFRGRK/pdQF0IPBi1UbZGn7v58tVnKLLVNOmsTTa GyEA== X-Gm-Message-State: AElRT7EL+hM5qJHP6A34tK5mGvwy/UgdwJvTik5SVpt8oUzlD0hdH8/3 UMUzouvxFkbsB5Olbgcx1CEnDw== 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) 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 X-Virus-Scanned: ClamAV using ClamSMTP 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;