Skip to content

Commit 447c095

Browse files
bbkzzdtor
authored andcommitted
Input: qt1070 - convert to use devm_* api
Use devm_* api to simplify code, this makes it unnecessary to explicitly release resources. Signed-off-by: Yangtao Li <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent e175eae commit 447c095

File tree

1 file changed

+14
-32
lines changed

1 file changed

+14
-32
lines changed

drivers/input/keyboard/qt1070.c

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -149,20 +149,20 @@ static int qt1070_probe(struct i2c_client *client)
149149
if (!qt1070_identify(client))
150150
return -ENODEV;
151151

152-
data = kzalloc(sizeof(struct qt1070_data), GFP_KERNEL);
153-
input = input_allocate_device();
154-
if (!data || !input) {
155-
dev_err(&client->dev, "insufficient memory\n");
156-
err = -ENOMEM;
157-
goto err_free_mem;
158-
}
152+
data = devm_kzalloc(&client->dev, sizeof(struct qt1070_data),
153+
GFP_KERNEL);
154+
if (!data)
155+
return -ENOMEM;
156+
157+
input = devm_input_allocate_device(&client->dev);
158+
if (!input)
159+
return -ENOMEM;
159160

160161
data->client = client;
161162
data->input = input;
162163
data->irq = client->irq;
163164

164165
input->name = "AT42QT1070 QTouch Sensor";
165-
input->dev.parent = &client->dev;
166166
input->id.bustype = BUS_I2C;
167167

168168
/* Add the keycode */
@@ -185,19 +185,20 @@ static int qt1070_probe(struct i2c_client *client)
185185
qt1070_write(client, RESET, 1);
186186
msleep(QT1070_RESET_TIME);
187187

188-
err = request_threaded_irq(client->irq, NULL, qt1070_interrupt,
189-
IRQF_TRIGGER_NONE | IRQF_ONESHOT,
190-
client->dev.driver->name, data);
188+
err = devm_request_threaded_irq(&client->dev, client->irq,
189+
NULL, qt1070_interrupt,
190+
IRQF_TRIGGER_NONE | IRQF_ONESHOT,
191+
client->dev.driver->name, data);
191192
if (err) {
192193
dev_err(&client->dev, "fail to request irq\n");
193-
goto err_free_mem;
194+
return err;
194195
}
195196

196197
/* Register the input device */
197198
err = input_register_device(data->input);
198199
if (err) {
199200
dev_err(&client->dev, "Failed to register input device\n");
200-
goto err_free_irq;
201+
return err;
201202
}
202203

203204
i2c_set_clientdata(client, data);
@@ -206,24 +207,6 @@ static int qt1070_probe(struct i2c_client *client)
206207
qt1070_read(client, DET_STATUS);
207208

208209
return 0;
209-
210-
err_free_irq:
211-
free_irq(client->irq, data);
212-
err_free_mem:
213-
input_free_device(input);
214-
kfree(data);
215-
return err;
216-
}
217-
218-
static void qt1070_remove(struct i2c_client *client)
219-
{
220-
struct qt1070_data *data = i2c_get_clientdata(client);
221-
222-
/* Release IRQ */
223-
free_irq(client->irq, data);
224-
225-
input_unregister_device(data->input);
226-
kfree(data);
227210
}
228211

229212
static int qt1070_suspend(struct device *dev)
@@ -272,7 +255,6 @@ static struct i2c_driver qt1070_driver = {
272255
},
273256
.id_table = qt1070_id,
274257
.probe = qt1070_probe,
275-
.remove = qt1070_remove,
276258
};
277259

278260
module_i2c_driver(qt1070_driver);

0 commit comments

Comments
 (0)