leds-lp3944: properly handle lp3944_configure fail in lp3944_probe
PATCH 1/1 leds-lp3944: properly handle lp3944_configure fail in lp3944_probe
In current implementation, lp3944_probe return 0 even if lp3944_configure fail.
Therefore, led_classdev_unregister will be executed twice ( in error handling of lp3944_configure and lp3944_remove ). This patch properly handles lp3944_configure fail in lp3944_probe.
--- drivers/leds/leds-lp3944.c | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-)
drivers/leds/leds-lp3944.c +9 -1
@@ -379,6 +379,7 @@ static int __devinit lp3944_probe(struct i2c_client *client, {struct lp3944_platform_data *lp3944_pdata = client->dev.platform_data;struct lp3944_data *data; +int err;if (lp3944_pdata ==NULL ) {dev_err (&client->dev,"no platform data\n" );
@@ -403,8 +404,15 @@ static int __devinit lp3944_probe(struct i2c_client *client,dev_info (&client->dev,"lp3944 enabled\n" ); -lp3944_configure (client, data, lp3944_pdata); + err =lp3944_configure (client, data, lp3944_pdata); +if (err <0 ) + goto err_configure; +return 0 ; + +err_configure: +kfree (data); +return err; } static int __devexit lp3944_remove(struct i2c_client *client)
Signature · 1 line
1.5.4.3
Quoted 4 lines · On Mon, 17 May 2010 09:34:02 +0800 Axel Lin <[email protected]> wrote:
In current implementation,
lp3944_probereturn 0 even iflp3944_configurefail.
Therefore,led_classdev_unregisterwill be executed twice ( in error handling oflp3944_configureandlp3944_remove). This patch properly handleslp3944_configurefail inlp3944_probe.
Hi Axel, thanks for the fix, I agree it's needed.
There are some minor comments inlined below.
Plus, when possible, I prefer commit messages to be wrapped to 72/80 characters per line. Please, consider this if you are sending a v2.
Ah, may I ask where you are using this driver? Just curious.
Quoted 18 lines
Signed-off-by Axel Lin <[email protected]>--- drivers/leds/leds-lp3944.c | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-)drivers/leds/leds-lp3944.c +1
-0@@ -379,6 +379,7 @@ static int __devinit lp3944_probe(struct i2c_client *client, {struct lp3944_platform_data *lp3944_pdata = client->dev.platform_data;struct lp3944_data *data; +int err;if (lp3944_pdata ==NULL ) {dev_err (&client->dev,"no platform data\n" );
drivers/leds/leds-lp3944.c static int __devinit lp3944_probe(struct i2c_client *client, · line 410
Quoted 8 lines
drivers/leds/leds-lp3944.c +4
-1@@ -403,8 +404,15 @@ static int __devinit lp3944_probe(struct i2c_client *client,dev_info (&client->dev,"lp3944 enabled\n" ); -lp3944_configure (client, data, lp3944_pdata); + err =lp3944_configure (client, data, lp3944_pdata); +if (err <0 ) + goto err_configure; +
The dev_info(&client->dev, "lp3944 enabled\n"); could now go right here, before the return 0, so we don't report the driver as enabled even in the case its probe fails.
drivers/leds/leds-lp3944.c static int __devinit lp3944_probe(struct i2c_client *client, · line 414
Quoted 4 lines
drivers/leds/leds-lp3944.c +3
-0return 0 ; + +err_configure: +kfree (data);
add i2c_set_clientdata(client, NULL) here just like in lp3944_remove()
Quoted 7 lines
drivers/leds/leds-lp3944.c +1
-0+return err; } static int __devexit lp3944_remove(struct i2c_client *client)Signature · 1 line
1.5.4.3
Regards,
Antonio
Signature · 10 lines
Antonio Ospite http://ao2.it PGP public key ID: 0x4553B001 A: Because it messes up the order in which people normally read text. See http://en.wikipedia.org/wiki/Posting_style Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing in e-mail?
Quoted 47 lines · Antonio Ospite
Quoted 4 lines · On Mon, 17 May 2010 09:34:02 +0800 Axel Lin <[email protected]> wrote:
In current implementation,
lp3944_probereturn 0 even iflp3944_configurefail.
Therefore,led_classdev_unregisterwill be executed twice ( in error handling oflp3944_configureandlp3944_remove). This patch properly handleslp3944_configurefail inlp3944_probe.Hi Axel, thanks for the fix, I agree it's needed.
There are some minor comments inlined below.Plus, when possible, I prefer commit messages to be wrapped to 72/80 characters per line. Please, consider this if you are sending a v2.
Ah, may I ask where you are using this driver? Just curious.
Quoted 18 lines
Signed-off-by Axel Lin <[email protected]>--- drivers/leds/leds-lp3944.c | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-)drivers/leds/leds-lp3944.c +1
-0@@ -379,6 +379,7 @@ static int __devinit lp3944_probe(struct i2c_client *client, {struct lp3944_platform_data *lp3944_pdata = client->dev.platform_data;struct lp3944_data *data; +int err;if (lp3944_pdata ==NULL ) {dev_err (&client->dev,"no platform data\n" );drivers/leds/leds-lp3944.c static int __devinit lp3944_probe(struct i2c_client *client, · line 410
Quoted 8 lines
drivers/leds/leds-lp3944.c +4
-1@@ -403,8 +404,15 @@ static int __devinit lp3944_probe(struct i2c_client *client,dev_info (&client->dev,"lp3944 enabled\n" ); -lp3944_configure (client, data, lp3944_pdata); + err =lp3944_configure (client, data, lp3944_pdata); +if (err <0 ) + goto err_configure; +The
dev_info(&client->dev, "lp3944 enabled\n"); could now go right here, before the return 0, so we don't report the driver as enabled even in the case its probe fails.
Quoted 6 lines
drivers/leds/leds-lp3944.c static int __devinit lp3944_probe(struct i2c_client *client, · line 414
Quoted 4 lines
drivers/leds/leds-lp3944.c +3
-0return 0 ; + +err_configure: +kfree (data);add
i2c_set_clientdata(client, NULL)here just like inlp3944_remove()
Just to note:
This is not needed anymore, the i2c-core does this meanwhile for the drivers. I am preparing a cleanup patch fixing this in all drivers for -rc1.
Signature · 2 lines
Pengutronix e.K. | Wolfram Sang | Industrial Linux Solutions | http://www.pengutronix.de/ |
2010/5/17 Antonio Ospite <[email protected]>:
Quoted 8 lines
Quoted 4 lines · On Mon, 17 May 2010 09:34:02 +0800 Axel Lin <[email protected]> wrote:
In current implementation,
lp3944_probereturn 0 even iflp3944_configurefail.
Therefore,led_classdev_unregisterwill be executed twice ( in error handling oflp3944_configureandlp3944_remove). This patch properly handleslp3944_configurefail inlp3944_probe.
Quoted 5 lines
Hi Axel, thanks for the fix, I agree it's needed.
There are some minor comments inlined below.Plus, when possible, I prefer commit messages to be wrapped to 72/80 characters per line. Please, consider this if you are sending a v2.
ok. done in v2.
Quoted 24 lines
Ah, may I ask where you are using this driver? Just curious.
Quoted 21 lines
Signed-off-by Axel Lin <[email protected]>---
drivers/leds/leds-lp3944.c | 10 +++++++++-1 files changed, 9 insertions(+), 1 deletions(-)drivers/leds/leds-lp3944.c +1
-0@@ -379,6 +379,7 @@ static int __devinit lp3944_probe(struct i2c_client *client, { struct lp3944_platform_data *lp3944_pdata = client->dev.platform_data; struct lp3944_data *data; + int err; if (lp3944_pdata == NULL) { dev_err(&client->dev, "no platform data\n");@@ -403,8 +404,15 @@ static int __devinit lp3944_probe(struct i2c_client *client, dev_info(&client->dev, "lp3944 enabled\n");
Quoted 9 lines
drivers/leds/leds-lp3944.c static int __devinit lp3944_probe(struct i2c_client *client, · line 410
Quoted 5 lines
drivers/leds/leds-lp3944.c +4
-1- lp3944_configure(client, data, lp3944_pdata); + err = lp3944_configure(client, data, lp3944_pdata); + if (err < 0) + goto err_configure; +The
dev_info(&client->dev, "lp3944 enabled\n"); could now go right here, before the return 0, so we don't report the driver as enabled even in the case its probe fails.
done in v2.
Quoted 7 lines
drivers/leds/leds-lp3944.c static int __devinit lp3944_probe(struct i2c_client *client, · line 414
Quoted 5 lines
drivers/leds/leds-lp3944.c +3
-0return 0; + +err_configure: + kfree(data);add
i2c_set_clientdata(client, NULL)here just like inlp3944_remove()
per Wolfram Sang's comment, I skip this part in v2.
Quoted 24 lines
Quoted 8 lines
drivers/leds/leds-lp3944.c +1
-1+ return err; } static int __devexit lp3944_remove(struct i2c_client *client) --1.5.4.3
Regards,
Antonio--
Antonio Ospite
http://ao2.itPGP public key ID:
0x4553B001A: Because it messes up the order in which people normally read text. See http://en.wikipedia.org/wiki/Posting_style
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?