Input: migor-ts - rework probe() to simplify error path
Register input device last so that we do not have to reset input device pointer after calling input_unregister_device(). Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
This commit is contained in:
@@ -137,21 +137,20 @@ static int migor_ts_probe(struct i2c_client *client,
|
|||||||
int error;
|
int error;
|
||||||
|
|
||||||
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
|
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
|
||||||
if (!priv) {
|
input = input_allocate_device();
|
||||||
dev_err(&client->dev, "failed to allocate driver data\n");
|
if (!priv || !input) {
|
||||||
|
dev_err(&client->dev, "failed to allocate memory\n");
|
||||||
error = -ENOMEM;
|
error = -ENOMEM;
|
||||||
goto err0;
|
goto err_free_mem;
|
||||||
}
|
}
|
||||||
|
|
||||||
input = input_allocate_device();
|
priv->client = client;
|
||||||
if (!input) {
|
priv->input = input;
|
||||||
dev_err(&client->dev, "Failed to allocate input device.\n");
|
priv->irq = client->irq;
|
||||||
error = -ENOMEM;
|
|
||||||
goto err1;
|
|
||||||
}
|
|
||||||
|
|
||||||
input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
|
input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
|
||||||
input->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
|
|
||||||
|
__set_bit(BTN_TOUCH, input->keybit);
|
||||||
|
|
||||||
input_set_abs_params(input, ABS_X, 95, 955, 0, 0);
|
input_set_abs_params(input, ABS_X, 95, 955, 0, 0);
|
||||||
input_set_abs_params(input, ABS_Y, 85, 935, 0, 0);
|
input_set_abs_params(input, ABS_Y, 85, 935, 0, 0);
|
||||||
@@ -165,34 +164,28 @@ static int migor_ts_probe(struct i2c_client *client,
|
|||||||
|
|
||||||
input_set_drvdata(input, priv);
|
input_set_drvdata(input, priv);
|
||||||
|
|
||||||
priv->client = client;
|
|
||||||
priv->input = input;
|
|
||||||
priv->irq = client->irq;
|
|
||||||
|
|
||||||
error = input_register_device(input);
|
|
||||||
if (error)
|
|
||||||
goto err1;
|
|
||||||
|
|
||||||
error = request_threaded_irq(priv->irq, NULL, migor_ts_isr,
|
error = request_threaded_irq(priv->irq, NULL, migor_ts_isr,
|
||||||
IRQF_TRIGGER_LOW | IRQF_ONESHOT,
|
IRQF_TRIGGER_LOW | IRQF_ONESHOT,
|
||||||
client->name, priv);
|
client->name, priv);
|
||||||
if (error) {
|
if (error) {
|
||||||
dev_err(&client->dev, "Unable to request touchscreen IRQ.\n");
|
dev_err(&client->dev, "Unable to request touchscreen IRQ.\n");
|
||||||
goto err2;
|
goto err_free_mem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error = input_register_device(input);
|
||||||
|
if (error)
|
||||||
|
goto err_free_irq;
|
||||||
|
|
||||||
i2c_set_clientdata(client, priv);
|
i2c_set_clientdata(client, priv);
|
||||||
device_init_wakeup(&client->dev, 1);
|
device_init_wakeup(&client->dev, 1);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err2:
|
err_free_irq:
|
||||||
input_unregister_device(input);
|
free_irq(priv->irq, priv);
|
||||||
input = NULL; /* so we dont try to free it below */
|
err_free_mem:
|
||||||
err1:
|
|
||||||
input_free_device(input);
|
input_free_device(input);
|
||||||
kfree(priv);
|
kfree(priv);
|
||||||
err0:
|
|
||||||
dev_set_drvdata(&client->dev, NULL);
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user