Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: auo-pixcir-ts - switch to using managed resources

This simplifies error unwinding and device teardown.

Tested-by: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+73 -98
+73 -98
drivers/input/touchscreen/auo-pixcir-ts.c
··· 533 533 } 534 534 #endif 535 535 536 + static void auo_pixcir_reset(void *data) 537 + { 538 + struct auo_pixcir_ts *ts = data; 539 + 540 + gpio_set_value(ts->pdata->gpio_rst, 0); 541 + } 542 + 536 543 static int auo_pixcir_probe(struct i2c_client *client, 537 - const struct i2c_device_id *id) 544 + const struct i2c_device_id *id) 538 545 { 539 546 const struct auo_pixcir_ts_platdata *pdata; 540 547 struct auo_pixcir_ts *ts; 541 548 struct input_dev *input_dev; 542 - int ret; 549 + int version; 550 + int error; 543 551 544 552 pdata = dev_get_platdata(&client->dev); 545 553 if (!pdata) { ··· 556 548 return PTR_ERR(pdata); 557 549 } 558 550 559 - ts = kzalloc(sizeof(struct auo_pixcir_ts), GFP_KERNEL); 551 + ts = devm_kzalloc(&client->dev, 552 + sizeof(struct auo_pixcir_ts), GFP_KERNEL); 560 553 if (!ts) 561 554 return -ENOMEM; 562 555 563 - ret = gpio_request(pdata->gpio_int, "auo_pixcir_ts_int"); 564 - if (ret) { 565 - dev_err(&client->dev, "request of gpio %d failed, %d\n", 566 - pdata->gpio_int, ret); 567 - goto err_gpio_int; 556 + input_dev = devm_input_allocate_device(&client->dev); 557 + if (!input_dev) { 558 + dev_err(&client->dev, "could not allocate input device\n"); 559 + return -ENOMEM; 568 560 } 569 - 570 - ret = gpio_direction_input(pdata->gpio_int); 571 - if (ret) { 572 - dev_err(&client->dev, "setting direction of gpio %d failed %d\n", 573 - pdata->gpio_int, ret); 574 - goto err_gpio_dir; 575 - } 576 - 577 - ret = gpio_request(pdata->gpio_rst, "auo_pixcir_ts_rst"); 578 - if (ret) { 579 - dev_err(&client->dev, "request of gpio %d failed, %d\n", 580 - pdata->gpio_rst, ret); 581 - goto err_gpio_dir; 582 - } 583 - 584 - ret = gpio_direction_output(pdata->gpio_rst, 1); 585 - if (ret) { 586 - dev_err(&client->dev, "setting direction of gpio %d failed %d\n", 587 - pdata->gpio_rst, ret); 588 - goto err_gpio_rst; 589 - } 590 - 591 - msleep(200); 592 561 593 562 ts->pdata = pdata; 594 563 ts->client = client; 564 + ts->input = input_dev; 595 565 ts->touch_ind_mode = 0; 566 + ts->stopped = true; 596 567 init_waitqueue_head(&ts->wait); 597 568 598 569 snprintf(ts->phys, sizeof(ts->phys), 599 570 "%s/input0", dev_name(&client->dev)); 600 571 601 - input_dev = input_allocate_device(); 602 - if (!input_dev) { 603 - dev_err(&client->dev, "could not allocate input device\n"); 604 - goto err_input_alloc; 605 - } 606 - 607 - ts->input = input_dev; 608 - 609 572 input_dev->name = "AUO-Pixcir touchscreen"; 610 573 input_dev->phys = ts->phys; 611 574 input_dev->id.bustype = BUS_I2C; 612 - input_dev->dev.parent = &client->dev; 613 575 614 576 input_dev->open = auo_pixcir_input_open; 615 577 input_dev->close = auo_pixcir_input_close; ··· 604 626 AUO_PIXCIR_MAX_AREA, 0, 0); 605 627 input_set_abs_params(input_dev, ABS_MT_ORIENTATION, 0, 1, 0, 0); 606 628 607 - ret = i2c_smbus_read_byte_data(client, AUO_PIXCIR_REG_VERSION); 608 - if (ret < 0) 609 - goto err_fw_vers; 610 - dev_info(&client->dev, "firmware version 0x%X\n", ret); 611 - 612 - ret = auo_pixcir_int_config(ts, pdata->int_setting); 613 - if (ret) 614 - goto err_fw_vers; 615 - 616 629 input_set_drvdata(ts->input, ts); 617 - ts->stopped = true; 618 630 619 - ret = request_threaded_irq(client->irq, NULL, auo_pixcir_interrupt, 620 - IRQF_TRIGGER_RISING | IRQF_ONESHOT, 621 - input_dev->name, ts); 622 - if (ret) { 623 - dev_err(&client->dev, "irq %d requested failed\n", client->irq); 624 - goto err_fw_vers; 631 + error = devm_gpio_request_one(&client->dev, pdata->gpio_int, 632 + GPIOF_DIR_IN, "auo_pixcir_ts_int"); 633 + if (error) { 634 + dev_err(&client->dev, "request of gpio %d failed, %d\n", 635 + pdata->gpio_int, error); 636 + return error; 637 + } 638 + 639 + error = devm_gpio_request_one(&client->dev, pdata->gpio_rst, 640 + GPIOF_DIR_OUT | GPIOF_INIT_HIGH, 641 + "auo_pixcir_ts_rst"); 642 + if (error) { 643 + dev_err(&client->dev, "request of gpio %d failed, %d\n", 644 + pdata->gpio_rst, error); 645 + return error; 646 + } 647 + 648 + error = devm_add_action(&client->dev, auo_pixcir_reset, ts); 649 + if (error) { 650 + auo_pixcir_reset(ts); 651 + dev_err(&client->dev, "failed to register reset action, %d\n", 652 + error); 653 + return error; 654 + } 655 + 656 + msleep(200); 657 + 658 + version = i2c_smbus_read_byte_data(client, AUO_PIXCIR_REG_VERSION); 659 + if (version < 0) { 660 + error = version; 661 + return error; 662 + } 663 + 664 + dev_info(&client->dev, "firmware version 0x%X\n", version); 665 + 666 + error = auo_pixcir_int_config(ts, pdata->int_setting); 667 + if (error) 668 + return error; 669 + 670 + error = devm_request_threaded_irq(&client->dev, client->irq, 671 + NULL, auo_pixcir_interrupt, 672 + IRQF_TRIGGER_RISING | IRQF_ONESHOT, 673 + input_dev->name, ts); 674 + if (error) { 675 + dev_err(&client->dev, "irq %d requested failed, %d\n", 676 + client->irq, error); 677 + return error; 625 678 } 626 679 627 680 /* stop device and put it into deep sleep until it is opened */ 628 - ret = auo_pixcir_stop(ts); 629 - if (ret < 0) 630 - goto err_input_register; 681 + error = auo_pixcir_stop(ts); 682 + if (error) 683 + return error; 631 684 632 - ret = input_register_device(input_dev); 633 - if (ret) { 634 - dev_err(&client->dev, "could not register input device\n"); 635 - goto err_input_register; 685 + error = input_register_device(input_dev); 686 + if (error) { 687 + dev_err(&client->dev, "could not register input device, %d\n", 688 + error); 689 + return error; 636 690 } 637 691 638 692 i2c_set_clientdata(client, ts); 639 - 640 - return 0; 641 - 642 - err_input_register: 643 - free_irq(client->irq, ts); 644 - err_fw_vers: 645 - input_free_device(input_dev); 646 - err_input_alloc: 647 - gpio_set_value(pdata->gpio_rst, 0); 648 - err_gpio_rst: 649 - gpio_free(pdata->gpio_rst); 650 - err_gpio_dir: 651 - gpio_free(pdata->gpio_int); 652 - err_gpio_int: 653 - kfree(ts); 654 - 655 - return ret; 656 - } 657 - 658 - static int auo_pixcir_remove(struct i2c_client *client) 659 - { 660 - struct auo_pixcir_ts *ts = i2c_get_clientdata(client); 661 - const struct auo_pixcir_ts_platdata *pdata = ts->pdata; 662 - 663 - free_irq(client->irq, ts); 664 - 665 - input_unregister_device(ts->input); 666 - 667 - gpio_set_value(pdata->gpio_rst, 0); 668 - gpio_free(pdata->gpio_rst); 669 - 670 - gpio_free(pdata->gpio_int); 671 - 672 - kfree(ts); 673 693 674 694 return 0; 675 695 } ··· 694 718 .of_match_table = of_match_ptr(auo_pixcir_ts_dt_idtable), 695 719 }, 696 720 .probe = auo_pixcir_probe, 697 - .remove = auo_pixcir_remove, 698 721 .id_table = auo_pixcir_idtable, 699 722 }; 700 723