Skip to content

Commit 91a4c69

Browse files
bbkzzdtor
authored andcommitted
Input: tca6416-keypad - 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 cc141c3 commit 91a4c69

File tree

1 file changed

+18
-35
lines changed

1 file changed

+18
-35
lines changed

drivers/input/keyboard/tca6416-keypad.c

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,15 @@ static int tca6416_keypad_probe(struct i2c_client *client)
216216
return -EINVAL;
217217
}
218218

219-
chip = kzalloc(struct_size(chip, buttons, pdata->nbuttons), GFP_KERNEL);
220-
input = input_allocate_device();
221-
if (!chip || !input) {
222-
error = -ENOMEM;
223-
goto fail1;
224-
}
219+
chip = devm_kzalloc(&client->dev,
220+
struct_size(chip, buttons, pdata->nbuttons),
221+
GFP_KERNEL);
222+
if (!chip)
223+
return -ENOMEM;
224+
225+
input = devm_input_allocate_device(&client->dev);
226+
if (!input)
227+
return -ENOMEM;
225228

226229
chip->client = client;
227230
chip->input = input;
@@ -233,7 +236,6 @@ static int tca6416_keypad_probe(struct i2c_client *client)
233236

234237
input->phys = "tca6416-keys/input0";
235238
input->name = client->name;
236-
input->dev.parent = &client->dev;
237239

238240
input->open = tca6416_keys_open;
239241
input->close = tca6416_keys_close;
@@ -263,59 +265,40 @@ static int tca6416_keypad_probe(struct i2c_client *client)
263265
*/
264266
error = tca6416_setup_registers(chip);
265267
if (error)
266-
goto fail1;
268+
return error;
267269

268270
if (!chip->use_polling) {
269-
error = request_threaded_irq(client->irq, NULL,
270-
tca6416_keys_isr,
271-
IRQF_TRIGGER_FALLING |
272-
IRQF_ONESHOT | IRQF_NO_AUTOEN,
273-
"tca6416-keypad", chip);
271+
error = devm_request_threaded_irq(&client->dev, client->irq,
272+
NULL, tca6416_keys_isr,
273+
IRQF_TRIGGER_FALLING |
274+
IRQF_ONESHOT |
275+
IRQF_NO_AUTOEN,
276+
"tca6416-keypad", chip);
274277
if (error) {
275278
dev_dbg(&client->dev,
276279
"Unable to claim irq %d; error %d\n",
277280
client->irq, error);
278-
goto fail1;
281+
return error;
279282
}
280283
}
281284

282285
error = input_register_device(input);
283286
if (error) {
284287
dev_dbg(&client->dev,
285288
"Unable to register input device, error: %d\n", error);
286-
goto fail2;
289+
return error;
287290
}
288291

289292
i2c_set_clientdata(client, chip);
290293

291294
return 0;
292-
293-
fail2:
294-
if (!chip->use_polling)
295-
free_irq(client->irq, chip);
296-
fail1:
297-
input_free_device(input);
298-
kfree(chip);
299-
return error;
300-
}
301-
302-
static void tca6416_keypad_remove(struct i2c_client *client)
303-
{
304-
struct tca6416_keypad_chip *chip = i2c_get_clientdata(client);
305-
306-
if (!chip->use_polling)
307-
free_irq(client->irq, chip);
308-
309-
input_unregister_device(chip->input);
310-
kfree(chip);
311295
}
312296

313297
static struct i2c_driver tca6416_keypad_driver = {
314298
.driver = {
315299
.name = "tca6416-keypad",
316300
},
317301
.probe = tca6416_keypad_probe,
318-
.remove = tca6416_keypad_remove,
319302
.id_table = tca6416_id,
320303
};
321304

0 commit comments

Comments
 (0)