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

Configure Feed

Select the types of activity you want to include in your feed.

Input: adxl34x - switch to using managed resources

Switch the driver to use managed resources to simplify error handling.

Link: https://lore.kernel.org/r/20240610164301.1048482-3-dmitry.torokhov@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+17 -53
-8
drivers/input/misc/adxl34x-i2c.c
··· 98 98 return 0; 99 99 } 100 100 101 - static void adxl34x_i2c_remove(struct i2c_client *client) 102 - { 103 - struct adxl34x *ac = i2c_get_clientdata(client); 104 - 105 - adxl34x_remove(ac); 106 - } 107 - 108 101 static const struct i2c_device_id adxl34x_id[] = { 109 102 { "adxl34x" }, 110 103 { } ··· 130 137 .of_match_table = adxl34x_of_id, 131 138 }, 132 139 .probe = adxl34x_i2c_probe, 133 - .remove = adxl34x_i2c_remove, 134 140 .id_table = adxl34x_id, 135 141 }; 136 142
-8
drivers/input/misc/adxl34x-spi.c
··· 87 87 return 0; 88 88 } 89 89 90 - static void adxl34x_spi_remove(struct spi_device *spi) 91 - { 92 - struct adxl34x *ac = spi_get_drvdata(spi); 93 - 94 - adxl34x_remove(ac); 95 - } 96 - 97 90 static struct spi_driver adxl34x_driver = { 98 91 .driver = { 99 92 .name = "adxl34x", ··· 94 101 .pm = pm_sleep_ptr(&adxl34x_pm), 95 102 }, 96 103 .probe = adxl34x_spi_probe, 97 - .remove = adxl34x_spi_remove, 98 104 }; 99 105 100 106 module_spi_driver(adxl34x_driver);
+17 -36
drivers/input/misc/adxl34x.c
··· 707 707 struct adxl34x *ac; 708 708 struct input_dev *input_dev; 709 709 const struct adxl34x_platform_data *pdata; 710 - int err, range, i; 710 + int error, range, i; 711 711 int revid; 712 712 713 713 if (!irq) { 714 714 dev_err(dev, "no IRQ?\n"); 715 - err = -ENODEV; 716 - goto err_out; 715 + return ERR_PTR(-ENODEV); 717 716 } 718 717 719 - ac = kzalloc(sizeof(*ac), GFP_KERNEL); 720 - input_dev = input_allocate_device(); 721 - if (!ac || !input_dev) { 722 - err = -ENOMEM; 723 - goto err_free_mem; 724 - } 718 + ac = devm_kzalloc(dev, sizeof(*ac), GFP_KERNEL); 719 + if (!ac) 720 + return ERR_PTR(-ENOMEM); 721 + 722 + input_dev = devm_input_allocate_device(dev); 723 + if (!input_dev) 724 + return ERR_PTR(-ENOMEM); 725 725 726 726 ac->fifo_delay = fifo_delay_default; 727 727 ··· 754 754 break; 755 755 default: 756 756 dev_err(dev, "Failed to probe %s\n", input_dev->name); 757 - err = -ENODEV; 758 - goto err_free_mem; 757 + return ERR_PTR(-ENODEV); 759 758 } 760 759 761 760 snprintf(ac->phys, sizeof(ac->phys), "%s/input0", dev_name(dev)); 762 761 763 762 input_dev->phys = ac->phys; 764 - input_dev->dev.parent = dev; 765 763 input_dev->id.product = ac->model; 766 764 input_dev->id.bustype = bops->bustype; 767 765 input_dev->open = adxl34x_input_open; ··· 814 816 815 817 AC_WRITE(ac, POWER_CTL, 0); 816 818 817 - err = request_threaded_irq(ac->irq, NULL, adxl34x_irq, 818 - IRQF_ONESHOT, dev_name(dev), ac); 819 - if (err) { 819 + error = devm_request_threaded_irq(dev, ac->irq, NULL, adxl34x_irq, 820 + IRQF_ONESHOT, dev_name(dev), ac); 821 + if (error) { 820 822 dev_err(dev, "irq %d busy?\n", ac->irq); 821 - goto err_free_mem; 823 + return ERR_PTR(error); 822 824 } 823 825 824 - err = input_register_device(input_dev); 825 - if (err) 826 - goto err_free_irq; 826 + error = input_register_device(input_dev); 827 + if (error) 828 + return ERR_PTR(error); 827 829 828 830 AC_WRITE(ac, OFSX, pdata->x_axis_offset); 829 831 ac->hwcal.x = pdata->x_axis_offset; ··· 882 884 ac->pdata.power_mode &= (PCTL_AUTO_SLEEP | PCTL_LINK); 883 885 884 886 return ac; 885 - 886 - err_free_irq: 887 - free_irq(ac->irq, ac); 888 - err_free_mem: 889 - input_free_device(input_dev); 890 - kfree(ac); 891 - err_out: 892 - return ERR_PTR(err); 893 887 } 894 888 EXPORT_SYMBOL_GPL(adxl34x_probe); 895 - 896 - void adxl34x_remove(struct adxl34x *ac) 897 - { 898 - free_irq(ac->irq, ac); 899 - input_unregister_device(ac->input); 900 - dev_dbg(ac->dev, "unregistered accelerometer\n"); 901 - kfree(ac); 902 - } 903 - EXPORT_SYMBOL_GPL(adxl34x_remove); 904 889 905 890 EXPORT_GPL_SIMPLE_DEV_PM_OPS(adxl34x_pm, adxl34x_suspend, adxl34x_resume); 906 891
-1
drivers/input/misc/adxl34x.h
··· 23 23 struct adxl34x *adxl34x_probe(struct device *dev, int irq, 24 24 bool fifo_delay_default, 25 25 const struct adxl34x_bus_ops *bops); 26 - void adxl34x_remove(struct adxl34x *ac); 27 26 28 27 extern const struct dev_pm_ops adxl34x_pm; 29 28 extern const struct attribute_group *adxl34x_groups[];