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: Dan Carpenter <error27@gmail.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>

authored by Dan Carpenter and committed by Dmitry Torokhov 17d01f28 a4503199

+10 -13
+10 -13
drivers/input/misc/pcf8574_keypad.c
··· 127 127 idev->id.product = 0x0001; 128 128 idev->id.version = 0x0100; 129 129 130 - input_set_drvdata(idev, lp); 131 - 132 - ret = input_register_device(idev); 133 - if (ret) { 134 - dev_err(&client->dev, "input_register_device() failed\n"); 135 - goto fail_register; 136 - } 137 - 138 130 lp->laststate = read_state(lp); 139 131 140 132 ret = request_threaded_irq(client->irq, NULL, pcf8574_kp_irq_handler, ··· 134 142 DRV_NAME, lp); 135 143 if (ret) { 136 144 dev_err(&client->dev, "IRQ %d is not free\n", client->irq); 137 - goto fail_irq; 145 + goto fail_free_device; 146 + } 147 + 148 + ret = input_register_device(idev); 149 + if (ret) { 150 + dev_err(&client->dev, "input_register_device() failed\n"); 151 + goto fail_free_irq; 138 152 } 139 153 140 154 i2c_set_clientdata(client, lp); 141 155 return 0; 142 156 143 - fail_irq: 144 - input_unregister_device(idev); 145 - fail_register: 146 - input_set_drvdata(idev, NULL); 157 + fail_free_irq: 158 + free_irq(client->irq, lp); 159 + fail_free_device: 147 160 input_free_device(idev); 148 161 fail_allocate: 149 162 kfree(lp);