Commit 8a0b6c5d authored by Sachin Kamat's avatar Sachin Kamat Committed by Dmitry Torokhov

Input: mms114 - switch to using managed resources

devm_* APIs are device managed and make the exit and clean up code
simpler.
Signed-off-by: default avatarSachin Kamat <sachin.kamat@linaro.org>
Acked-by: Laxman Dewangan<ldewangan@nvidia.com>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent 914e5976
...@@ -429,12 +429,12 @@ static int mms114_probe(struct i2c_client *client, ...@@ -429,12 +429,12 @@ static int mms114_probe(struct i2c_client *client,
return -ENODEV; return -ENODEV;
} }
data = kzalloc(sizeof(struct mms114_data), GFP_KERNEL); data = devm_kzalloc(&client->dev, sizeof(struct mms114_data),
input_dev = input_allocate_device(); GFP_KERNEL);
input_dev = devm_input_allocate_device(&client->dev);
if (!data || !input_dev) { if (!data || !input_dev) {
dev_err(&client->dev, "Failed to allocate memory\n"); dev_err(&client->dev, "Failed to allocate memory\n");
error = -ENOMEM; return -ENOMEM;
goto err_free_mem;
} }
data->client = client; data->client = client;
...@@ -466,57 +466,36 @@ static int mms114_probe(struct i2c_client *client, ...@@ -466,57 +466,36 @@ static int mms114_probe(struct i2c_client *client,
input_set_drvdata(input_dev, data); input_set_drvdata(input_dev, data);
i2c_set_clientdata(client, data); i2c_set_clientdata(client, data);
data->core_reg = regulator_get(&client->dev, "avdd"); data->core_reg = devm_regulator_get(&client->dev, "avdd");
if (IS_ERR(data->core_reg)) { if (IS_ERR(data->core_reg)) {
error = PTR_ERR(data->core_reg); error = PTR_ERR(data->core_reg);
dev_err(&client->dev, dev_err(&client->dev,
"Unable to get the Core regulator (%d)\n", error); "Unable to get the Core regulator (%d)\n", error);
goto err_free_mem; return error;
} }
data->io_reg = regulator_get(&client->dev, "vdd"); data->io_reg = devm_regulator_get(&client->dev, "vdd");
if (IS_ERR(data->io_reg)) { if (IS_ERR(data->io_reg)) {
error = PTR_ERR(data->io_reg); error = PTR_ERR(data->io_reg);
dev_err(&client->dev, dev_err(&client->dev,
"Unable to get the IO regulator (%d)\n", error); "Unable to get the IO regulator (%d)\n", error);
goto err_core_reg; return error;
} }
error = request_threaded_irq(client->irq, NULL, mms114_interrupt, error = devm_request_threaded_irq(&client->dev, client->irq, NULL,
IRQF_TRIGGER_FALLING | IRQF_ONESHOT, "mms114", data); mms114_interrupt, IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
dev_name(&client->dev), data);
if (error) { if (error) {
dev_err(&client->dev, "Failed to register interrupt\n"); dev_err(&client->dev, "Failed to register interrupt\n");
goto err_io_reg; return error;
} }
disable_irq(client->irq); disable_irq(client->irq);
error = input_register_device(data->input_dev); error = input_register_device(data->input_dev);
if (error) if (error) {
goto err_free_irq; dev_err(&client->dev, "Failed to register input device\n");
return 0;
err_free_irq:
free_irq(client->irq, data);
err_io_reg:
regulator_put(data->io_reg);
err_core_reg:
regulator_put(data->core_reg);
err_free_mem:
input_free_device(input_dev);
kfree(data);
return error; return error;
} }
static int mms114_remove(struct i2c_client *client)
{
struct mms114_data *data = i2c_get_clientdata(client);
free_irq(client->irq, data);
regulator_put(data->io_reg);
regulator_put(data->core_reg);
input_unregister_device(data->input_dev);
kfree(data);
return 0; return 0;
} }
...@@ -590,7 +569,6 @@ static struct i2c_driver mms114_driver = { ...@@ -590,7 +569,6 @@ static struct i2c_driver mms114_driver = {
.of_match_table = of_match_ptr(mms114_dt_match), .of_match_table = of_match_ptr(mms114_dt_match),
}, },
.probe = mms114_probe, .probe = mms114_probe,
.remove = mms114_remove,
.id_table = mms114_id, .id_table = mms114_id,
}; };
......
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