Skip to content

Commit 3e4bb04

Browse files
bbkzzdtor
authored andcommitted
Input: qt2160 - 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] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent d675c9b commit 3e4bb04

File tree

1 file changed

+20
-57
lines changed

1 file changed

+20
-57
lines changed

drivers/input/keyboard/qt2160.c

Lines changed: 20 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ static int qt2160_write(struct i2c_client *client, u8 reg, u8 data)
239239
static int qt2160_register_leds(struct qt2160_data *qt2160)
240240
{
241241
struct i2c_client *client = qt2160->client;
242-
int ret;
242+
int error;
243243
int i;
244244

245245
for (i = 0; i < QT2160_NUM_LEDS_X; i++) {
@@ -252,9 +252,9 @@ static int qt2160_register_leds(struct qt2160_data *qt2160)
252252
led->id = i;
253253
led->qt2160 = qt2160;
254254

255-
ret = led_classdev_register(&client->dev, &led->cdev);
256-
if (ret < 0)
257-
return ret;
255+
error = devm_led_classdev_register(&client->dev, &led->cdev);
256+
if (error)
257+
return error;
258258
}
259259

260260
/* Tur off LEDs */
@@ -265,25 +265,13 @@ static int qt2160_register_leds(struct qt2160_data *qt2160)
265265
return 0;
266266
}
267267

268-
static void qt2160_unregister_leds(struct qt2160_data *qt2160)
269-
{
270-
int i;
271-
272-
for (i = 0; i < QT2160_NUM_LEDS_X; i++)
273-
led_classdev_unregister(&qt2160->leds[i].cdev);
274-
}
275-
276268
#else
277269

278270
static inline int qt2160_register_leds(struct qt2160_data *qt2160)
279271
{
280272
return 0;
281273
}
282274

283-
static inline void qt2160_unregister_leds(struct qt2160_data *qt2160)
284-
{
285-
}
286-
287275
#endif
288276

289277
static bool qt2160_identify(struct i2c_client *client)
@@ -334,13 +322,13 @@ static int qt2160_probe(struct i2c_client *client)
334322
return -ENODEV;
335323

336324
/* Chip is valid and active. Allocate structure */
337-
qt2160 = kzalloc(sizeof(struct qt2160_data), GFP_KERNEL);
338-
input = input_allocate_device();
339-
if (!qt2160 || !input) {
340-
dev_err(&client->dev, "insufficient memory\n");
341-
error = -ENOMEM;
342-
goto err_free_mem;
343-
}
325+
qt2160 = devm_kzalloc(&client->dev, sizeof(*qt2160), GFP_KERNEL);
326+
if (!qt2160)
327+
return -ENOMEM;
328+
329+
input = devm_input_allocate_device(&client->dev);
330+
if (!input)
331+
return -ENOMEM;
344332

345333
qt2160->client = client;
346334
qt2160->input = input;
@@ -366,66 +354,42 @@ static int qt2160_probe(struct i2c_client *client)
366354
error = qt2160_write(client, QT2160_CMD_CALIBRATE, 1);
367355
if (error) {
368356
dev_err(&client->dev, "failed to calibrate device\n");
369-
goto err_free_mem;
357+
return error;
370358
}
371359

372360
if (client->irq) {
373-
error = request_threaded_irq(client->irq, NULL, qt2160_irq,
374-
IRQF_ONESHOT, "qt2160", input);
361+
error = devm_request_threaded_irq(&client->dev, client->irq,
362+
NULL, qt2160_irq,
363+
IRQF_ONESHOT,
364+
"qt2160", input);
375365
if (error) {
376366
dev_err(&client->dev,
377367
"failed to allocate irq %d\n", client->irq);
378-
goto err_free_mem;
368+
return error;
379369
}
380370
} else {
381371
error = input_setup_polling(input, qt2160_get_key_matrix);
382372
if (error) {
383373
dev_err(&client->dev, "Failed to setup polling\n");
384-
goto err_free_mem;
374+
return error;
385375
}
386376
input_set_poll_interval(input, QT2160_CYCLE_INTERVAL);
387377
}
388378

389379
error = qt2160_register_leds(qt2160);
390380
if (error) {
391381
dev_err(&client->dev, "Failed to register leds\n");
392-
goto err_free_irq;
382+
return error;
393383
}
394384

395385
error = input_register_device(qt2160->input);
396386
if (error) {
397387
dev_err(&client->dev,
398388
"Failed to register input device\n");
399-
goto err_unregister_leds;
389+
return error;
400390
}
401391

402-
i2c_set_clientdata(client, qt2160);
403-
404392
return 0;
405-
406-
err_unregister_leds:
407-
qt2160_unregister_leds(qt2160);
408-
err_free_irq:
409-
if (client->irq)
410-
free_irq(client->irq, qt2160);
411-
err_free_mem:
412-
input_free_device(input);
413-
kfree(qt2160);
414-
return error;
415-
}
416-
417-
static void qt2160_remove(struct i2c_client *client)
418-
{
419-
struct qt2160_data *qt2160 = i2c_get_clientdata(client);
420-
421-
qt2160_unregister_leds(qt2160);
422-
423-
/* Release IRQ so no queue will be scheduled */
424-
if (client->irq)
425-
free_irq(client->irq, qt2160);
426-
427-
input_unregister_device(qt2160->input);
428-
kfree(qt2160);
429393
}
430394

431395
static const struct i2c_device_id qt2160_idtable[] = {
@@ -442,7 +406,6 @@ static struct i2c_driver qt2160_driver = {
442406

443407
.id_table = qt2160_idtable,
444408
.probe = qt2160_probe,
445-
.remove = qt2160_remove,
446409
};
447410

448411
module_i2c_driver(qt2160_driver);

0 commit comments

Comments
 (0)