aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorSven Wegener <sven.wegener@stealer.net>2008-12-03 03:12:53 -0500
committerRichard Purdie <rpurdie@linux.intel.com>2009-01-08 07:38:58 -0500
commitf785d022add53ec4d9625495b335bed40bd6c079 (patch)
tree99225d733708b6dbcc54ffa0a33f528eb756ee1e /drivers
parent12276efcc85f3108174893bff8878e0dc655b066 (diff)
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>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/leds/leds-pca9532.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/drivers/leds/leds-pca9532.c b/drivers/leds/leds-pca9532.c
index f0883e6ebc50..62b60a038e2c 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,
204 led->ldev.brightness = LED_OFF; 204 led->ldev.brightness = LED_OFF;
205 led->ldev.brightness_set = pca9532_set_brightness; 205 led->ldev.brightness_set = pca9532_set_brightness;
206 led->ldev.blink_set = pca9532_set_blink; 206 led->ldev.blink_set = pca9532_set_blink;
207 if (led_classdev_register(&client->dev, 207 err = led_classdev_register(&client->dev, &led->ldev);
208 &led->ldev) < 0) { 208 if (err < 0) {
209 dev_err(&client->dev, 209 dev_err(&client->dev,
210 "couldn't register LED %s\n", 210 "couldn't register LED %s\n",
211 led->name); 211 led->name);
@@ -263,7 +263,6 @@ exit:
263 } 263 }
264 264
265 return err; 265 return err;
266
267} 266}
268 267
269static int pca9532_probe(struct i2c_client *client, 268static int pca9532_probe(struct i2c_client *client,
@@ -271,12 +270,16 @@ static int pca9532_probe(struct i2c_client *client,
271{ 270{
272 struct pca9532_data *data = i2c_get_clientdata(client); 271 struct pca9532_data *data = i2c_get_clientdata(client);
273 struct pca9532_platform_data *pca9532_pdata = client->dev.platform_data; 272 struct pca9532_platform_data *pca9532_pdata = client->dev.platform_data;
273 int err;
274
275 if (!pca9532_pdata)
276 return -EIO;
274 277
275 if (!i2c_check_functionality(client->adapter, 278 if (!i2c_check_functionality(client->adapter,
276 I2C_FUNC_SMBUS_BYTE_DATA)) 279 I2C_FUNC_SMBUS_BYTE_DATA))
277 return -EIO; 280 return -EIO;
278 281
279 data = kzalloc(sizeof(struct pca9532_data), GFP_KERNEL); 282 data = kzalloc(sizeof(*data), GFP_KERNEL);
280 if (!data) 283 if (!data)
281 return -ENOMEM; 284 return -ENOMEM;
282 285
@@ -285,12 +288,13 @@ static int pca9532_probe(struct i2c_client *client,
285 data->client = client; 288 data->client = client;
286 mutex_init(&data->update_lock); 289 mutex_init(&data->update_lock);
287 290
288 if (pca9532_pdata == NULL) 291 err = pca9532_configure(client, data, pca9532_pdata);
289 return -EIO; 292 if (err) {
290 293 kfree(data);
291 pca9532_configure(client, data, pca9532_pdata); 294 i2c_set_clientdata(client, NULL);
292 return 0; 295 }
293 296
297 return err;
294} 298}
295 299
296static int pca9532_remove(struct i2c_client *client) 300static int pca9532_remove(struct i2c_client *client)