From patchwork Tue May 29 22:59:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 922468 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=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="gxtbxYY5"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40wTgW4CPrz9s16 for ; Wed, 30 May 2018 08:59:19 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S968009AbeE2W7H (ORCPT ); Tue, 29 May 2018 18:59:07 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:45190 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967857AbeE2W7E (ORCPT ); Tue, 29 May 2018 18:59:04 -0400 Received: by mail-pg0-f66.google.com with SMTP id z1-v6so301028pgv.12 for ; Tue, 29 May 2018 15:59:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=a2tFgVqLKYuk+yVVU0ppr+LfZDHu8K+bIGccp1aN3H0=; b=gxtbxYY5tCQz6ZwpkWBajZi8haxS3FsihWcJ2PkSL9nrFykihHrxhM9mOohSNrIdVy Df/ium6f9UcQP8vuNuzXHAP5eSLfMhocQ9nyKhJdMNoydfwMzztwrSUqhDCk5sc7s1p5 Qj1qdwAKuHlPhvcIVvFW3k+qurpCN1mW51Qbk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=a2tFgVqLKYuk+yVVU0ppr+LfZDHu8K+bIGccp1aN3H0=; b=lBcQNQhmUgiKzrWn9qoqIf6Qu5brPc7B6f6537oiuK4SIOm44fMnPX3JP6yIFsqcwa lMeUp2Kg63TvgrdHyu5LEUYobTtcdU3XUOKORzMm+4O//CjTB3HiHdwXcOhClU278pPu YtOIiAI6sjFWARLc0hB5tVkYZ/tzpGavvd+IAhfsJY9xdW/8RDN8IQssjpbJifsC0qUj Jr0VOjD0FHETilVlKJzn6nuQPA9XPUs/gMPd5ZuRTPv5fAgoTlShcXeO2y3eX7Hezmt0 HTh3F0Dk2kxs7KoLCHvQaeeuufNPOoF3tkp55yug9oP5yaC4lGakbKuxjvjloODQ1ku4 qk2A== X-Gm-Message-State: ALKqPwdXJdptqdIbyl1c77jRqEji+Ks09ZrfFBf9xMbf5xwhgwPg40iB CdnSzZbfB5GcUgfCE4ttEEfCnw== X-Google-Smtp-Source: ADUXVKK4xRc3G/gNg0UMtXwCZcMrTOZIOLEgzZFAeSQIDV1xrN4e6/WyZ3oA1jtBHs0pxZfhhRkP5Q== X-Received: by 2002:a65:44c3:: with SMTP id g3-v6mr256021pgs.428.1527634743830; Tue, 29 May 2018 15:59:03 -0700 (PDT) Received: from www.outflux.net (173-164-112-133-Oregon.hfc.comcastbusiness.net. [173.164.112.133]) by smtp.gmail.com with ESMTPSA id c17-v6sm26295975pgw.11.2018.05.29.15.59.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 May 2018 15:59:02 -0700 (PDT) Date: Tue, 29 May 2018 15:59:01 -0700 From: Kees Cook To: Linus Walleij Cc: Pramod Kumar , Andrew Lunn , Florian Fainelli , "David S. Miller" , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] mdio-mux-gpio: Remove VLA usage Message-ID: <20180529225901.GA30464@beast> MIME-Version: 1.0 Content-Disposition: inline Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org In the quest to remove all stack VLA usage from the kernel[1], this allocates the values buffer during the callback instead of putting it on the stack. [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com Signed-off-by: Kees Cook --- drivers/net/phy/mdio-mux-gpio.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/net/phy/mdio-mux-gpio.c b/drivers/net/phy/mdio-mux-gpio.c index 082ffef0dec4..e99994f4ed50 100644 --- a/drivers/net/phy/mdio-mux-gpio.c +++ b/drivers/net/phy/mdio-mux-gpio.c @@ -26,18 +26,23 @@ static int mdio_mux_gpio_switch_fn(int current_child, int desired_child, void *data) { struct mdio_mux_gpio_state *s = data; - int values[s->gpios->ndescs]; + int *values; unsigned int n; if (current_child == desired_child) return 0; + values = kmalloc_array(s->gpios->ndescs, sizeof(*values), GFP_KERNEL); + if (!values) + return -ENOMEM; + for (n = 0; n < s->gpios->ndescs; n++) values[n] = (desired_child >> n) & 1; gpiod_set_array_value_cansleep(s->gpios->ndescs, s->gpios->desc, values); + kfree(values); return 0; }