linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] mdio-mux-gpio: Remove VLA usage
@ 2018-05-30 20:48 Kees Cook
  2018-05-30 20:57 ` Andrew Lunn
  0 siblings, 1 reply; 5+ messages in thread
From: Kees Cook @ 2018-05-30 20:48 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: Linus Walleij, Pramod Kumar, Florian Fainelli, David S. Miller,
	linux-gpio, linux-kernel

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 <keescook@chromium.org>
---
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);
-- 
2.17.0


-- 
Kees Cook
Pixel Security

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] mdio-mux-gpio: Remove VLA usage
  2018-05-30 20:48 [PATCH v2] mdio-mux-gpio: Remove VLA usage Kees Cook
@ 2018-05-30 20:57 ` Andrew Lunn
  2018-06-20  4:44   ` Kees Cook
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Lunn @ 2018-05-30 20:57 UTC (permalink / raw)
  To: Kees Cook
  Cc: Linus Walleij, Pramod Kumar, Florian Fainelli, David S. Miller,
	linux-gpio, linux-kernel

On Wed, May 30, 2018 at 01:48:30PM -0700, Kees Cook wrote:
> 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 <keescook@chromium.org>
> ---
> v2: allocate array as part of structure (Andrew Lunn)

Hi Kees

This looks much better, thanks.

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] mdio-mux-gpio: Remove VLA usage
  2018-05-30 20:57 ` Andrew Lunn
@ 2018-06-20  4:44   ` Kees Cook
  2018-06-20  6:32     ` Andrew Lunn
  0 siblings, 1 reply; 5+ messages in thread
From: Kees Cook @ 2018-06-20  4:44 UTC (permalink / raw)
  To: Andrew Lunn, Linus Walleij
  Cc: Pramod Kumar, Florian Fainelli, David S. Miller, linux-gpio, LKML

On Wed, May 30, 2018 at 1:57 PM, Andrew Lunn <andrew@lunn.ch> wrote:
> On Wed, May 30, 2018 at 01:48:30PM -0700, Kees Cook wrote:
>> 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 <keescook@chromium.org>
>> ---
>> v2: allocate array as part of structure (Andrew Lunn)
>
> Hi Kees
>
> This looks much better, thanks.
>
> Reviewed-by: Andrew Lunn <andrew@lunn.ch>

Thanks! Who can take this patch? Linus?

-Kees

-- 
Kees Cook
Pixel Security

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] mdio-mux-gpio: Remove VLA usage
  2018-06-20  4:44   ` Kees Cook
@ 2018-06-20  6:32     ` Andrew Lunn
  2018-06-20  6:37       ` David Miller
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Lunn @ 2018-06-20  6:32 UTC (permalink / raw)
  To: Kees Cook
  Cc: Linus Walleij, Pramod Kumar, Florian Fainelli, David S. Miller,
	linux-gpio, LKML

On Tue, Jun 19, 2018 at 09:44:27PM -0700, Kees Cook wrote:
> On Wed, May 30, 2018 at 1:57 PM, Andrew Lunn <andrew@lunn.ch> wrote:
> > On Wed, May 30, 2018 at 01:48:30PM -0700, Kees Cook wrote:
> >> 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 <keescook@chromium.org>
> >> ---
> >> v2: allocate array as part of structure (Andrew Lunn)
> >
> > Hi Kees
> >
> > This looks much better, thanks.
> >
> > Reviewed-by: Andrew Lunn <andrew@lunn.ch>
> 
> Thanks! Who can take this patch? Linus?

David Miller.

Does it cleanly apply to net-next?

     Andrew
 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] mdio-mux-gpio: Remove VLA usage
  2018-06-20  6:32     ` Andrew Lunn
@ 2018-06-20  6:37       ` David Miller
  0 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2018-06-20  6:37 UTC (permalink / raw)
  To: andrew
  Cc: keescook, linus.walleij, pramod.kumar, f.fainelli, linux-gpio,
	linux-kernel

From: Andrew Lunn <andrew@lunn.ch>
Date: Wed, 20 Jun 2018 08:32:48 +0200

> Does it cleanly apply to net-next?

net-next is closed, so net-next submissions should be sent when it
opens back up which should be some time this weekend.

Anything not in "Under Review" state in patchwork always must
be resubmitted at the appropriate time.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-06-20  6:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-30 20:48 [PATCH v2] mdio-mux-gpio: Remove VLA usage Kees Cook
2018-05-30 20:57 ` Andrew Lunn
2018-06-20  4:44   ` Kees Cook
2018-06-20  6:32     ` Andrew Lunn
2018-06-20  6:37       ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).