Commit 17d01f28 authored by Dan Carpenter's avatar Dan Carpenter Committed by Dmitry Torokhov

Input: pcf8574_keypad - fix error handling in pcf8574_kp_probe

It is not allowed to call input_free_device() after calling
input_unregister_device() because input devices are refcounted and
unregister will free the device if we were holding he last referenc.

The preferred style in input/ is to make input_register_device() the
last function in the probe which can fail.  That way we don't need to
call input_unregister_device().

Also do not need to call input_set_drvdata() as nothing in the driver
uses the data.
Signed-off-by: default avatarDan Carpenter <error27@gmail.com>
Signed-off-by: default avatarDmitry Torokhov <dtor@mail.ru>
parent a4503199
...@@ -127,14 +127,6 @@ static int __devinit pcf8574_kp_probe(struct i2c_client *client, const struct i2 ...@@ -127,14 +127,6 @@ static int __devinit pcf8574_kp_probe(struct i2c_client *client, const struct i2
idev->id.product = 0x0001; idev->id.product = 0x0001;
idev->id.version = 0x0100; idev->id.version = 0x0100;
input_set_drvdata(idev, lp);
ret = input_register_device(idev);
if (ret) {
dev_err(&client->dev, "input_register_device() failed\n");
goto fail_register;
}
lp->laststate = read_state(lp); lp->laststate = read_state(lp);
ret = request_threaded_irq(client->irq, NULL, pcf8574_kp_irq_handler, ret = request_threaded_irq(client->irq, NULL, pcf8574_kp_irq_handler,
...@@ -142,16 +134,21 @@ static int __devinit pcf8574_kp_probe(struct i2c_client *client, const struct i2 ...@@ -142,16 +134,21 @@ static int __devinit pcf8574_kp_probe(struct i2c_client *client, const struct i2
DRV_NAME, lp); DRV_NAME, lp);
if (ret) { if (ret) {
dev_err(&client->dev, "IRQ %d is not free\n", client->irq); dev_err(&client->dev, "IRQ %d is not free\n", client->irq);
goto fail_irq; goto fail_free_device;
}
ret = input_register_device(idev);
if (ret) {
dev_err(&client->dev, "input_register_device() failed\n");
goto fail_free_irq;
} }
i2c_set_clientdata(client, lp); i2c_set_clientdata(client, lp);
return 0; return 0;
fail_irq: fail_free_irq:
input_unregister_device(idev); free_irq(client->irq, lp);
fail_register: fail_free_device:
input_set_drvdata(idev, NULL);
input_free_device(idev); input_free_device(idev);
fail_allocate: fail_allocate:
kfree(lp); kfree(lp);
......
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