From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753121AbbCZO4L (ORCPT ); Thu, 26 Mar 2015 10:56:11 -0400 Received: from mail-ob0-f179.google.com ([209.85.214.179]:33309 "EHLO mail-ob0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751382AbbCZO4H (ORCPT ); Thu, 26 Mar 2015 10:56:07 -0400 Message-ID: <55141DFF.5020905@mvista.com> Date: Thu, 26 Mar 2015 09:55:59 -0500 From: Corey Minyard User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: minyard@acm.org, Raphael Assenat CC: linux-leds@vger.kernel.org, Linux Kernel Subject: Re: [PATCH] leds-gpio: Fix error handling and memory leak References: <1425948222-7925-1-git-send-email-minyard@acm.org> In-Reply-To: <1425948222-7925-1-git-send-email-minyard@acm.org> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Ping. This is a rather obvious fix and can result in an oops. -corey On 03/09/2015 07:43 PM, minyard@acm.org wrote: > From: Corey Minyard > > The leds-gpio driver would not clean up properly if it failed in some > places, and it wasn't freeing its private data. > > Signed-off-by: Corey Minyard > --- > drivers/leds/leds-gpio.c | 13 +++++++++---- > 1 file changed, 9 insertions(+), 4 deletions(-) > > diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c > index d26af0a..32f7642 100644 > --- a/drivers/leds/leds-gpio.c > +++ b/drivers/leds/leds-gpio.c > @@ -198,8 +198,10 @@ static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev) > } else { > if (IS_ENABLED(CONFIG_OF) && !led.name && np) > led.name = np->name; > - if (!led.name) > - return ERR_PTR(-EINVAL); > + if (!led.name) { > + ret = -EINVAL; > + goto err; > + } > } > fwnode_property_read_string(child, "linux,default-trigger", > &led.default_trigger); > @@ -217,19 +219,21 @@ static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev) > if (fwnode_property_present(child, "retain-state-suspended")) > led.retain_state_suspended = 1; > > - ret = create_gpio_led(&led, &priv->leds[priv->num_leds++], > + ret = create_gpio_led(&led, &priv->leds[priv->num_leds], > dev, NULL); > if (ret < 0) { > fwnode_handle_put(child); > goto err; > } > + priv->num_leds++; > } > > return priv; > > err: > - for (count = priv->num_leds - 2; count >= 0; count--) > + for (count = priv->num_leds - 1; count >= 0; count--) > delete_gpio_led(&priv->leds[count]); > + devm_kfree(dev, priv); > return ERR_PTR(ret); > } > > @@ -283,6 +287,7 @@ static int gpio_led_remove(struct platform_device *pdev) > > for (i = 0; i < priv->num_leds; i++) > delete_gpio_led(&priv->leds[i]); > + devm_kfree(&pdev->dev, priv); > > return 0; > }