From patchwork Wed May 30 20:48:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 923015 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="UeAjNBmA"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40x2kD1c5pz9s08 for ; Thu, 31 May 2018 06:48:36 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932255AbeE3Use (ORCPT ); Wed, 30 May 2018 16:48:34 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:41338 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932233AbeE3Usd (ORCPT ); Wed, 30 May 2018 16:48:33 -0400 Received: by mail-pf0-f194.google.com with SMTP id v63-v6so9603434pfk.8 for ; Wed, 30 May 2018 13:48:33 -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=tInhqptHFoSMiDQq/AqLXG6R79TuaEvcsqgsT9azLxE=; b=UeAjNBmABLkszepRpGzQ6Lr+sxOXnHUmqFYbY9j6aDgulWnE1/yq0KyH94Q0dpCjoj t+1NWSeyv1Dt/TakV33AMwFYD1SSwTQZSf2l2xBSCtU4axNesHQVEjmYrgoqHfe/3VVL aBITbC+T2xuClKyJPfyipOM4Vx7pVWMK1UChQ= 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=tInhqptHFoSMiDQq/AqLXG6R79TuaEvcsqgsT9azLxE=; b=ZabBaT3meSzZhyq+G/3XKJZ29fBCBni0F9IUT3iD7WZSygPlm8Mx+fILKAdbbmQL6y al5T8BcZ/8LWlV96ghW6ijTsZbkDUnHgQTSnP6KKawm7zS1rdVFX40l+CISPTzyPdhMK S/eJ2wdRrBEytaiv3E10MK0oSGyRbcW5njjWqHeQ3b3DY1g5qbZQWjJufoDEkZLeunVQ 4g81O9FLot6GSuQt+UGy3piT0DXrWXtz5M5CLd4E33nTdOcqrfi89J3fh2M7ByEV3hNV 4xukop9Pjm/dfVKubWRRJqU59yd7xOEb7Cow3QqfS8Pr5VWrArSU6m5fC9TY9CNpm5cH DJLA== X-Gm-Message-State: ALKqPwclyYhCZcJT95S9En5JrMBoTDnRngYzeZTuj9Ty8V8IrceYuQso nKyTNkAJLx665UA8ZXBNnnQ3rg== X-Google-Smtp-Source: ADUXVKJDQw9l7A+MylU1hnmM9c5FjW9xwXHh5QI5+DfY9eRmnqYQ+fOU0ABj/rMkfZeXAgq8kA9bcw== X-Received: by 2002:a62:428f:: with SMTP id h15-v6mr4167218pfd.156.1527713313422; Wed, 30 May 2018 13:48:33 -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 f4-v6sm50025948pgo.77.2018.05.30.13.48.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 May 2018 13:48:31 -0700 (PDT) Date: Wed, 30 May 2018 13:48:30 -0700 From: Kees Cook To: Andrew Lunn Cc: Linus Walleij , Pramod Kumar , Florian Fainelli , "David S. Miller" , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] mdio-mux-gpio: Remove VLA usage Message-ID: <20180530204830.GA24884@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 moves the allocation into struct mdio_mux_gpio_state during probe. [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com Signed-off-by: Kees Cook Reviewed-by: Andrew Lunn --- v2: allocate array as part of structure (Andrew Lunn) --- drivers/net/phy/mdio-mux-gpio.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/drivers/net/phy/mdio-mux-gpio.c b/drivers/net/phy/mdio-mux-gpio.c index 082ffef0dec4..6b55e0ddef63 100644 --- a/drivers/net/phy/mdio-mux-gpio.c +++ b/drivers/net/phy/mdio-mux-gpio.c @@ -20,23 +20,23 @@ struct mdio_mux_gpio_state { struct gpio_descs *gpios; void *mux_handle; + int values[]; }; 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]; unsigned int n; if (current_child == desired_child) return 0; for (n = 0; n < s->gpios->ndescs; n++) - values[n] = (desired_child >> n) & 1; + s->values[n] = (desired_child >> n) & 1; gpiod_set_array_value_cansleep(s->gpios->ndescs, s->gpios->desc, - values); + s->values); return 0; } @@ -44,15 +44,21 @@ static int mdio_mux_gpio_switch_fn(int current_child, int desired_child, static int mdio_mux_gpio_probe(struct platform_device *pdev) { struct mdio_mux_gpio_state *s; + struct gpio_descs *gpios; int r; - s = devm_kzalloc(&pdev->dev, sizeof(*s), GFP_KERNEL); - if (!s) + gpios = gpiod_get_array(&pdev->dev, NULL, GPIOD_OUT_LOW); + if (IS_ERR(gpios)) + return PTR_ERR(gpios); + + s = devm_kzalloc(&pdev->dev, sizeof(*s->values) * gpios->ndescs + + sizeof(*s), GFP_KERNEL); + if (!s) { + gpiod_put_array(gpios); return -ENOMEM; + } - s->gpios = gpiod_get_array(&pdev->dev, NULL, GPIOD_OUT_LOW); - if (IS_ERR(s->gpios)) - return PTR_ERR(s->gpios); + s->gpios = gpios; r = mdio_mux_init(&pdev->dev, pdev->dev.of_node, mdio_mux_gpio_switch_fn, &s->mux_handle, s, NULL);