Received: by 10.223.185.111 with SMTP id b44csp893407wrg; Fri, 9 Mar 2018 16:12:43 -0800 (PST) X-Google-Smtp-Source: AG47ELsxoAh51BsVKXE9gDK7T8VK6Ha4jhnGyorStNffoOGfJ5o4nqMgzBKwslJ9Q6VY1zF74ioR X-Received: by 2002:a17:902:983:: with SMTP id 3-v6mr310798pln.278.1520640763430; Fri, 09 Mar 2018 16:12:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520640763; cv=none; d=google.com; s=arc-20160816; b=D6RWXB/Cz4oDsXhZSeRHNqQ+w3lB8lCCcO2DBLhYftnA+ZBJAafRyuJedHB/0df97s KZC8M5LB2dTH4xTwAU2DfwOmSh6lDTXcWNjqqSqJW4TtBGr+6GPdTuQwKx3RW/IPn+aO h9WNVK+4/CEsLYeDFKDmWUVf6RuxXDQQXTwPcOJX7EN86U5L3CI1F9aJ1L+g7rWqB5Xr Utj5bSYcUDj0vByxVEmnSBZO7c3fwoVo6lVc/rC9lAJAXBpXytXTfn7dqFLsBxQn82An qKiGsyAaoAjtSLGYpdKiN5tAwH4iV2PdZCLXS5Fwm6UuSvTArMu38W400bKgLWnP8vsd gweA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=roQovXqc354fTff3XJfD8Mqu/kAFDMxTuYxokb4/mj8=; b=lXTpCVunmRbp2MohywzyFIfa3BF9J20+wrSpFzkY551RL8XVT4MJGXr4Fzf+YQVTcS crUc6MoK9RJOGe3gh+c3G2PX1EKCNzOTZQV89eIrWkX3FR1tIDjPmuqXNAiqs4fMbaPN 009OB4t1ed1ShNAzIFWupNLwZPJQ1L/UFu0aH8SHfhgIBFzqPETMe51afAG8Z6dLyJZj pEG4hz1IY+3AhArymyBTLqZSCpd+YRzbLxAk2g4Nn1Dbztgd19qZqXCAFaY3WVAw3j+K /W4SaODHQk1fwlcf+S4viF6huem82hmjHiSA9RE+TTzRhL/CrZnUztfat3EYO1l5IP04 Iifg== 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 i66si1476482pgc.445.2018.03.09.16.12.29; Fri, 09 Mar 2018 16:12:43 -0800 (PST) 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 S932727AbeCJAKh (ORCPT + 99 others); Fri, 9 Mar 2018 19:10:37 -0500 Received: from mail-ot0-f195.google.com ([74.125.82.195]:44870 "EHLO mail-ot0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932557AbeCJAKe (ORCPT ); Fri, 9 Mar 2018 19:10:34 -0500 Received: by mail-ot0-f195.google.com with SMTP id 79so10263932oth.11 for ; Fri, 09 Mar 2018 16:10:34 -0800 (PST) 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:in-reply-to :references; bh=roQovXqc354fTff3XJfD8Mqu/kAFDMxTuYxokb4/mj8=; b=sCGxzVQIMHiEkG1moSkSoqbmVykKwuOjdCpKnXn2yLWDvwkoXNABu+e/hPYsZkMZ9H aKMK5Zf/kDjMrHqhJ5egOxVvVYkDWUKs0ckr4kY2lpvVXZpcBLBulqP3nsgfof05gMOn w4vt0CFS17uRs8BxrCGSAI63Y41DR52DF2EzEdEm0gYzZkLdgrgusxzJqvhmOIKzTDzh 0EfqlOaxU8gbr8Myda0MuBPrh8CF9lTNOsmc6R7bmAi/258AU5frReqxpERBW6u/2ziy U6qjoXFszFOeNgZ10KpJMv/PkAcDBz7W8MyTu51IFzLkERXw1Lj+nXeFWUG/xyCTyM1M p0nQ== X-Gm-Message-State: AElRT7Ey1JWpNn9fMaenRt5/8/L+tsBZnn/8nBMEtN1X4BwR0t370TRz 2l7dX6upBpq/k2LKSw+h0Uh03Q== X-Received: by 10.157.83.9 with SMTP id g9mr207611oth.172.1520640634095; Fri, 09 Mar 2018 16:10:34 -0800 (PST) Received: from labbott-redhat.redhat.com ([2601:602:9802:a8dc:4eb2:6dae:ab32:e5b0]) by smtp.gmail.com with ESMTPSA id s12sm1007076oie.9.2018.03.09.16.10.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 09 Mar 2018 16:10:32 -0800 (PST) From: Laura Abbott To: Linus Walleij , Kees Cook Cc: Laura Abbott , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com, Lukas Wunner , Mathias Duckeck , Nandor Han , Semi Malinen , Patrice Chotard Subject: [PATCH 1/4] gpio: Remove VLA from gpiolib Date: Fri, 9 Mar 2018 16:10:18 -0800 Message-Id: <20180310001021.6437-2-labbott@redhat.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180310001021.6437-1-labbott@redhat.com> References: <20180310001021.6437-1-labbott@redhat.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The new challenge is to remove VLAs from the kernel (see https://lkml.org/lkml/2018/3/7/621) This patch replaces several VLAs with an appropriate call to kmalloc_array. Signed-off-by: Laura Abbott --- drivers/gpio/gpiolib.c | 55 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index d66de67ef307..124727c74931 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2662,16 +2662,33 @@ int gpiod_get_array_value_complex(bool raw, bool can_sleep, while (i < array_size) { struct gpio_chip *chip = desc_array[i]->gdev->chip; - unsigned long mask[BITS_TO_LONGS(chip->ngpio)]; - unsigned long bits[BITS_TO_LONGS(chip->ngpio)]; + unsigned long *mask; + unsigned long *bits; int first, j, ret; + mask = kmalloc_array(BITS_TO_LONGS(chip->ngpio), + sizeof(*mask), + can_sleep ? GFP_KERNEL : GFP_ATOMIC); + + if (!mask) + return -ENOMEM; + + bits = kmalloc_array(BITS_TO_LONGS(chip->ngpio), + sizeof(*bits), + can_sleep ? GFP_KERNEL : GFP_ATOMIC); + + if (!bits) { + kfree(mask); + return -ENOMEM; + } + + if (!can_sleep) WARN_ON(chip->can_sleep); /* collect all inputs belonging to the same chip */ first = i; - memset(mask, 0, sizeof(mask)); + memset(mask, 0, sizeof(*mask)); do { const struct gpio_desc *desc = desc_array[i]; int hwgpio = gpio_chip_hwgpio(desc); @@ -2682,8 +2699,11 @@ int gpiod_get_array_value_complex(bool raw, bool can_sleep, (desc_array[i]->gdev->chip == chip)); ret = gpio_chip_get_multiple(chip, mask, bits); - if (ret) + if (ret) { + kfree(bits); + kfree(mask); return ret; + } for (j = first; j < i; j++) { const struct gpio_desc *desc = desc_array[j]; @@ -2695,6 +2715,8 @@ int gpiod_get_array_value_complex(bool raw, bool can_sleep, value_array[j] = value; trace_gpio_value(desc_to_gpio(desc), 1, value); } + kfree(bits); + kfree(mask); } return 0; } @@ -2887,14 +2909,30 @@ void gpiod_set_array_value_complex(bool raw, bool can_sleep, while (i < array_size) { struct gpio_chip *chip = desc_array[i]->gdev->chip; - unsigned long mask[BITS_TO_LONGS(chip->ngpio)]; - unsigned long bits[BITS_TO_LONGS(chip->ngpio)]; + unsigned long *mask; + unsigned long *bits; int count = 0; + mask = kmalloc_array(BITS_TO_LONGS(chip->ngpio), + sizeof(*mask), + can_sleep ? GFP_KERNEL : GFP_ATOMIC); + + if (!mask) + return; + + bits = kmalloc_array(BITS_TO_LONGS(chip->ngpio), + sizeof(*bits), + can_sleep ? GFP_KERNEL : GFP_ATOMIC); + + if (!bits) { + kfree(mask); + return; + } + if (!can_sleep) WARN_ON(chip->can_sleep); - memset(mask, 0, sizeof(mask)); + memset(mask, 0, sizeof(*mask)); do { struct gpio_desc *desc = desc_array[i]; int hwgpio = gpio_chip_hwgpio(desc); @@ -2925,6 +2963,9 @@ void gpiod_set_array_value_complex(bool raw, bool can_sleep, /* push collected bits to outputs */ if (count != 0) gpio_chip_set_multiple(chip, mask, bits); + + kfree(mask); + kfree(bits); } } -- 2.14.3