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

Input: cyttsp - use devres managed resource allocations

Use devm_() functions for allocating memory, input device and IRQ.

Signed-off-by: Oreste Salerno <oreste.salerno@tomtom.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Oreste Salerno and committed by
Dmitry Torokhov
e4cf92ba 809d9516

+30 -59
+30 -38
drivers/input/touchscreen/cyttsp_core.c
··· 528 528 cyttsp_disable(ts); 529 529 } 530 530 531 + static void cyttsp_platform_exit(void *data) 532 + { 533 + struct cyttsp *ts = data; 534 + 535 + if (ts->pdata->exit) 536 + ts->pdata->exit(); 537 + } 538 + 531 539 struct cyttsp *cyttsp_probe(const struct cyttsp_bus_ops *bus_ops, 532 540 struct device *dev, int irq, size_t xfer_buf_size) 533 541 { ··· 544 536 struct input_dev *input_dev; 545 537 int error; 546 538 547 - if (!pdata || !pdata->name || irq <= 0) { 548 - error = -EINVAL; 549 - goto err_out; 550 - } 539 + if (!pdata || !pdata->name || irq <= 0) 540 + return ERR_PTR(-EINVAL); 551 541 552 - ts = kzalloc(sizeof(*ts) + xfer_buf_size, GFP_KERNEL); 553 - input_dev = input_allocate_device(); 554 - if (!ts || !input_dev) { 555 - error = -ENOMEM; 556 - goto err_free_mem; 557 - } 542 + ts = devm_kzalloc(dev, sizeof(*ts) + xfer_buf_size, GFP_KERNEL); 543 + if (!ts) 544 + return ERR_PTR(-ENOMEM); 545 + 546 + input_dev = devm_input_allocate_device(dev); 547 + if (!input_dev) 548 + return ERR_PTR(-ENOMEM); 558 549 559 550 ts->dev = dev; 560 551 ts->input = input_dev; ··· 564 557 init_completion(&ts->bl_ready); 565 558 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(dev)); 566 559 560 + error = devm_add_action(dev, cyttsp_platform_exit, ts); 561 + if (error) { 562 + dev_err(dev, "failed to install exit action: %d\n", error); 563 + return ERR_PTR(error); 564 + } 565 + 567 566 if (pdata->init) { 568 567 error = pdata->init(); 569 568 if (error) { 570 569 dev_err(ts->dev, "platform init failed, err: %d\n", 571 570 error); 572 - goto err_free_mem; 571 + return ERR_PTR(error); 573 572 } 574 573 } 575 574 ··· 599 586 600 587 input_mt_init_slots(input_dev, CY_MAX_ID, 0); 601 588 602 - error = request_threaded_irq(ts->irq, NULL, cyttsp_irq, 603 - IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 604 - pdata->name, ts); 589 + error = devm_request_threaded_irq(dev, ts->irq, NULL, cyttsp_irq, 590 + IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 591 + pdata->name, ts); 605 592 if (error) { 606 593 dev_err(ts->dev, "failed to request IRQ %d, err: %d\n", 607 594 ts->irq, error); 608 - goto err_platform_exit; 595 + return ERR_PTR(error); 609 596 } 610 597 611 598 disable_irq(ts->irq); 612 599 613 600 error = cyttsp_power_on(ts); 614 601 if (error) 615 - goto err_free_irq; 602 + return ERR_PTR(error); 616 603 617 604 error = input_register_device(input_dev); 618 605 if (error) { 619 606 dev_err(ts->dev, "failed to register input device: %d\n", 620 607 error); 621 - goto err_free_irq; 608 + return ERR_PTR(error); 622 609 } 623 610 624 611 return ts; 625 - 626 - err_free_irq: 627 - free_irq(ts->irq, ts); 628 - err_platform_exit: 629 - if (pdata->exit) 630 - pdata->exit(); 631 - err_free_mem: 632 - input_free_device(input_dev); 633 - kfree(ts); 634 - err_out: 635 - return ERR_PTR(error); 636 612 } 637 613 EXPORT_SYMBOL_GPL(cyttsp_probe); 638 - 639 - void cyttsp_remove(struct cyttsp *ts) 640 - { 641 - free_irq(ts->irq, ts); 642 - input_unregister_device(ts->input); 643 - if (ts->pdata->exit) 644 - ts->pdata->exit(); 645 - kfree(ts); 646 - } 647 - EXPORT_SYMBOL_GPL(cyttsp_remove); 648 614 649 615 MODULE_LICENSE("GPL"); 650 616 MODULE_DESCRIPTION("Cypress TrueTouch(R) Standard touchscreen driver core");
-1
drivers/input/touchscreen/cyttsp_core.h
··· 143 143 144 144 struct cyttsp *cyttsp_probe(const struct cyttsp_bus_ops *bus_ops, 145 145 struct device *dev, int irq, size_t xfer_buf_size); 146 - void cyttsp_remove(struct cyttsp *ts); 147 146 148 147 int cyttsp_i2c_write_block_data(struct device *dev, u8 *xfer_buf, u16 addr, 149 148 u8 length, const void *values);
-10
drivers/input/touchscreen/cyttsp_i2c.c
··· 56 56 return 0; 57 57 } 58 58 59 - static int cyttsp_i2c_remove(struct i2c_client *client) 60 - { 61 - struct cyttsp *ts = i2c_get_clientdata(client); 62 - 63 - cyttsp_remove(ts); 64 - 65 - return 0; 66 - } 67 - 68 59 static const struct i2c_device_id cyttsp_i2c_id[] = { 69 60 { CY_I2C_NAME, 0 }, 70 61 { } ··· 68 77 .pm = &cyttsp_pm_ops, 69 78 }, 70 79 .probe = cyttsp_i2c_probe, 71 - .remove = cyttsp_i2c_remove, 72 80 .id_table = cyttsp_i2c_id, 73 81 }; 74 82
-10
drivers/input/touchscreen/cyttsp_spi.c
··· 170 170 return 0; 171 171 } 172 172 173 - static int cyttsp_spi_remove(struct spi_device *spi) 174 - { 175 - struct cyttsp *ts = spi_get_drvdata(spi); 176 - 177 - cyttsp_remove(ts); 178 - 179 - return 0; 180 - } 181 - 182 173 static struct spi_driver cyttsp_spi_driver = { 183 174 .driver = { 184 175 .name = CY_SPI_NAME, 185 176 .pm = &cyttsp_pm_ops, 186 177 }, 187 178 .probe = cyttsp_spi_probe, 188 - .remove = cyttsp_spi_remove, 189 179 }; 190 180 191 181 module_spi_driver(cyttsp_spi_driver);