Input: mma8450 - convert to using managed resources
This simplifies error handling and device removal code. Also let's get rid of setting driver's owner since i2c core does it for us. Tested-by: Stefan Sauer <ensonic@google.com> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
This commit is contained in:
parent
a93ad65d37
commit
5037a17966
@ -174,12 +174,13 @@ static int mma8450_probe(struct i2c_client *c,
|
|||||||
struct mma8450 *m;
|
struct mma8450 *m;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
m = kzalloc(sizeof(struct mma8450), GFP_KERNEL);
|
m = devm_kzalloc(&c->dev, sizeof(*m), GFP_KERNEL);
|
||||||
idev = input_allocate_polled_device();
|
if (!m)
|
||||||
if (!m || !idev) {
|
return -ENOMEM;
|
||||||
err = -ENOMEM;
|
|
||||||
goto err_free_mem;
|
idev = devm_input_allocate_polled_device(&c->dev);
|
||||||
}
|
if (!idev)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
m->client = c;
|
m->client = c;
|
||||||
m->idev = idev;
|
m->idev = idev;
|
||||||
@ -187,7 +188,6 @@ static int mma8450_probe(struct i2c_client *c,
|
|||||||
idev->private = m;
|
idev->private = m;
|
||||||
idev->input->name = MMA8450_DRV_NAME;
|
idev->input->name = MMA8450_DRV_NAME;
|
||||||
idev->input->id.bustype = BUS_I2C;
|
idev->input->id.bustype = BUS_I2C;
|
||||||
idev->input->dev.parent = &c->dev;
|
|
||||||
idev->poll = mma8450_poll;
|
idev->poll = mma8450_poll;
|
||||||
idev->poll_interval = POLL_INTERVAL;
|
idev->poll_interval = POLL_INTERVAL;
|
||||||
idev->poll_interval_max = POLL_INTERVAL_MAX;
|
idev->poll_interval_max = POLL_INTERVAL_MAX;
|
||||||
@ -202,28 +202,11 @@ static int mma8450_probe(struct i2c_client *c,
|
|||||||
err = input_register_polled_device(idev);
|
err = input_register_polled_device(idev);
|
||||||
if (err) {
|
if (err) {
|
||||||
dev_err(&c->dev, "failed to register polled input device\n");
|
dev_err(&c->dev, "failed to register polled input device\n");
|
||||||
goto err_free_mem;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
i2c_set_clientdata(c, m);
|
i2c_set_clientdata(c, m);
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
err_free_mem:
|
|
||||||
input_free_polled_device(idev);
|
|
||||||
kfree(m);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int mma8450_remove(struct i2c_client *c)
|
|
||||||
{
|
|
||||||
struct mma8450 *m = i2c_get_clientdata(c);
|
|
||||||
struct input_polled_dev *idev = m->idev;
|
|
||||||
|
|
||||||
input_unregister_polled_device(idev);
|
|
||||||
input_free_polled_device(idev);
|
|
||||||
kfree(m);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,11 +225,9 @@ MODULE_DEVICE_TABLE(of, mma8450_dt_ids);
|
|||||||
static struct i2c_driver mma8450_driver = {
|
static struct i2c_driver mma8450_driver = {
|
||||||
.driver = {
|
.driver = {
|
||||||
.name = MMA8450_DRV_NAME,
|
.name = MMA8450_DRV_NAME,
|
||||||
.owner = THIS_MODULE,
|
|
||||||
.of_match_table = mma8450_dt_ids,
|
.of_match_table = mma8450_dt_ids,
|
||||||
},
|
},
|
||||||
.probe = mma8450_probe,
|
.probe = mma8450_probe,
|
||||||
.remove = mma8450_remove,
|
|
||||||
.id_table = mma8450_id,
|
.id_table = mma8450_id,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user