leds: leds-pca9532 - fix memory leak and properly handle errors

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.

Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
This commit is contained in:
Sven Wegener 2008-12-03 08:12:53 +00:00 committed by Richard Purdie
parent 12276efcc8
commit f785d022ad
1 changed files with 13 additions and 9 deletions

View File

@ -204,8 +204,8 @@ static int pca9532_configure(struct i2c_client *client,
led->ldev.brightness = LED_OFF; led->ldev.brightness = LED_OFF;
led->ldev.brightness_set = pca9532_set_brightness; led->ldev.brightness_set = pca9532_set_brightness;
led->ldev.blink_set = pca9532_set_blink; led->ldev.blink_set = pca9532_set_blink;
if (led_classdev_register(&client->dev, err = led_classdev_register(&client->dev, &led->ldev);
&led->ldev) < 0) { if (err < 0) {
dev_err(&client->dev, dev_err(&client->dev,
"couldn't register LED %s\n", "couldn't register LED %s\n",
led->name); led->name);
@ -263,7 +263,6 @@ exit:
} }
return err; return err;
} }
static int pca9532_probe(struct i2c_client *client, 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_data *data = i2c_get_clientdata(client);
struct pca9532_platform_data *pca9532_pdata = client->dev.platform_data; struct pca9532_platform_data *pca9532_pdata = client->dev.platform_data;
int err;
if (!pca9532_pdata)
return -EIO;
if (!i2c_check_functionality(client->adapter, if (!i2c_check_functionality(client->adapter,
I2C_FUNC_SMBUS_BYTE_DATA)) I2C_FUNC_SMBUS_BYTE_DATA))
return -EIO; return -EIO;
data = kzalloc(sizeof(struct pca9532_data), GFP_KERNEL); data = kzalloc(sizeof(*data), GFP_KERNEL);
if (!data) if (!data)
return -ENOMEM; return -ENOMEM;
@ -285,12 +288,13 @@ static int pca9532_probe(struct i2c_client *client,
data->client = client; data->client = client;
mutex_init(&data->update_lock); mutex_init(&data->update_lock);
if (pca9532_pdata == NULL) err = pca9532_configure(client, data, pca9532_pdata);
return -EIO; if (err) {
kfree(data);
pca9532_configure(client, data, pca9532_pdata); i2c_set_clientdata(client, NULL);
return 0; }
return err;
} }
static int pca9532_remove(struct i2c_client *client) static int pca9532_remove(struct i2c_client *client)