From: Riku Voipio <riku.voipio@iki.fi>
To: Sven Wegener <sven.wegener@stealer.net>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] leds-pca9532: Fix memory leak and properly handle errors
Date: Tue, 12 Aug 2008 22:05:47 +0300 [thread overview]
Message-ID: <20080812190547.GA3616@kos.to> (raw)
In-Reply-To: <alpine.LNX.1.10.0808080047290.16201@titan.stealer.net>
On Fri, Aug 08, 2008 at 12:49:40AM +0200, Sven Wegener wrote:
> When the registration fails, we need to release the memory we allocated. Also
> we need to save the error from led_classdev_register and propagate it up, else
> we'll return success, even if we failed.
> Not-yet-signed-off-by: Sven Wegener <sven.wegener@stealer.net>
> Cc: Riku Voipio <riku.voipio@iki.fi>
Driver in general works after this, error path(s) not tested.
Acked-By: Riku Voipio <riku.voipio@iki.fi>
> ---
> drivers/leds/leds-pca9532.c | 22 +++++++++++++---------
> 1 files changed, 13 insertions(+), 9 deletions(-)
>
> I don't have the hardware. Riku, can you please test if it still works as
> expected.
>
> diff --git a/drivers/leds/leds-pca9532.c b/drivers/leds/leds-pca9532.c
> index 4064d4f..16af817 100644
> --- a/drivers/leds/leds-pca9532.c
> +++ b/drivers/leds/leds-pca9532.c
> @@ -204,8 +204,8 @@ static int pca9532_configure(struct i2c_client *client,
> led->ldev.brightness = LED_OFF;
> led->ldev.brightness_set = pca9532_set_brightness;
> led->ldev.blink_set = pca9532_set_blink;
> - if (led_classdev_register(&client->dev,
> - &led->ldev) < 0) {
> + err = led_classdev_register(&client->dev, &led->ldev);
> + if (err < 0) {
> dev_err(&client->dev,
> "couldn't register LED %s\n",
> led->name);
> @@ -263,7 +263,6 @@ exit:
> }
>
> return err;
> -
> }
>
> static int pca9532_probe(struct i2c_client *client,
> @@ -271,12 +270,16 @@ static int pca9532_probe(struct i2c_client *client,
> {
> struct pca9532_data *data = i2c_get_clientdata(client);
> struct pca9532_platform_data *pca9532_pdata = client->dev.platform_data;
> + int err;
> +
> + if (!pca9532_pdata)
> + return -EIO;
>
> if (!i2c_check_functionality(client->adapter,
> I2C_FUNC_SMBUS_BYTE_DATA))
> return -EIO;
>
> - data = kzalloc(sizeof(struct pca9532_data), GFP_KERNEL);
> + data = kzalloc(sizeof(*data), GFP_KERNEL);
> if (!data)
> return -ENOMEM;
>
> @@ -285,12 +288,13 @@ static int pca9532_probe(struct i2c_client *client,
> data->client = client;
> mutex_init(&data->update_lock);
>
> - if (pca9532_pdata == NULL)
> - return -EIO;
> -
> - pca9532_configure(client, data, pca9532_pdata);
> - return 0;
> + err = pca9532_configure(client, data, pca9532_pdata);
> + if (err) {
> + kfree(data);
> + i2c_set_clientdata(client, NULL);
> + }
>
> + return err;
> }
>
> static int pca9532_remove(struct i2c_client *client)
--
"rm -rf" only sounds scary if you don't have backups
prev parent reply other threads:[~2008-08-12 19:35 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-07 22:49 [PATCH] leds-pca9532: Fix memory leak and properly handle errors Sven Wegener
2008-08-12 19:05 ` Riku Voipio [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080812190547.GA3616@kos.to \
--to=riku.voipio@iki.fi \
--cc=linux-kernel@vger.kernel.org \
--cc=sven.wegener@stealer.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.