Commit e430dc00 authored by Bryan Wu's avatar Bryan Wu

leds: convert LP5521 LED driver to devm_kzalloc() and cleanup error exit path

Signed-off-by: default avatarBryan Wu <bryan.wu@canonical.com>
parent bad1c898
...@@ -744,7 +744,7 @@ static int __devinit lp5521_probe(struct i2c_client *client, ...@@ -744,7 +744,7 @@ static int __devinit lp5521_probe(struct i2c_client *client,
int ret, i, led; int ret, i, led;
u8 buf; u8 buf;
chip = kzalloc(sizeof(*chip), GFP_KERNEL); chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
if (!chip) if (!chip)
return -ENOMEM; return -ENOMEM;
...@@ -755,8 +755,7 @@ static int __devinit lp5521_probe(struct i2c_client *client, ...@@ -755,8 +755,7 @@ static int __devinit lp5521_probe(struct i2c_client *client,
if (!pdata) { if (!pdata) {
dev_err(&client->dev, "no platform data\n"); dev_err(&client->dev, "no platform data\n");
ret = -EINVAL; return -EINVAL;
goto fail1;
} }
mutex_init(&chip->lock); mutex_init(&chip->lock);
...@@ -766,7 +765,7 @@ static int __devinit lp5521_probe(struct i2c_client *client, ...@@ -766,7 +765,7 @@ static int __devinit lp5521_probe(struct i2c_client *client,
if (pdata->setup_resources) { if (pdata->setup_resources) {
ret = pdata->setup_resources(); ret = pdata->setup_resources();
if (ret < 0) if (ret < 0)
goto fail1; return ret;
} }
if (pdata->enable) { if (pdata->enable) {
...@@ -807,7 +806,7 @@ static int __devinit lp5521_probe(struct i2c_client *client, ...@@ -807,7 +806,7 @@ static int __devinit lp5521_probe(struct i2c_client *client,
ret = lp5521_configure(client); ret = lp5521_configure(client);
if (ret < 0) { if (ret < 0) {
dev_err(&client->dev, "error configuring chip\n"); dev_err(&client->dev, "error configuring chip\n");
goto fail2; goto fail1;
} }
/* Initialize leds */ /* Initialize leds */
...@@ -822,7 +821,7 @@ static int __devinit lp5521_probe(struct i2c_client *client, ...@@ -822,7 +821,7 @@ static int __devinit lp5521_probe(struct i2c_client *client,
ret = lp5521_init_led(&chip->leds[led], client, i, pdata); ret = lp5521_init_led(&chip->leds[led], client, i, pdata);
if (ret) { if (ret) {
dev_err(&client->dev, "error initializing leds\n"); dev_err(&client->dev, "error initializing leds\n");
goto fail3; goto fail2;
} }
chip->num_leds++; chip->num_leds++;
...@@ -840,21 +839,19 @@ static int __devinit lp5521_probe(struct i2c_client *client, ...@@ -840,21 +839,19 @@ static int __devinit lp5521_probe(struct i2c_client *client,
ret = lp5521_register_sysfs(client); ret = lp5521_register_sysfs(client);
if (ret) { if (ret) {
dev_err(&client->dev, "registering sysfs failed\n"); dev_err(&client->dev, "registering sysfs failed\n");
goto fail3; goto fail2;
} }
return ret; return ret;
fail3: fail2:
for (i = 0; i < chip->num_leds; i++) { for (i = 0; i < chip->num_leds; i++) {
led_classdev_unregister(&chip->leds[i].cdev); led_classdev_unregister(&chip->leds[i].cdev);
cancel_work_sync(&chip->leds[i].brightness_work); cancel_work_sync(&chip->leds[i].brightness_work);
} }
fail2: fail1:
if (pdata->enable) if (pdata->enable)
pdata->enable(0); pdata->enable(0);
if (pdata->release_resources) if (pdata->release_resources)
pdata->release_resources(); pdata->release_resources();
fail1:
kfree(chip);
return ret; return ret;
} }
...@@ -875,7 +872,6 @@ static int __devexit lp5521_remove(struct i2c_client *client) ...@@ -875,7 +872,6 @@ static int __devexit lp5521_remove(struct i2c_client *client)
chip->pdata->enable(0); chip->pdata->enable(0);
if (chip->pdata->release_resources) if (chip->pdata->release_resources)
chip->pdata->release_resources(); chip->pdata->release_resources();
kfree(chip);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment