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

Input: max8925_onkey - switch to using managed resources

Let's switch the driver to use managed resources, this will simplify
error handling and driver unbinding logic.

Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Himangi Saraogi and committed by
Dmitry Torokhov
04115e41 5ac66de5

+18 -37
+18 -37
drivers/input/misc/max8925_onkey.c
··· 26 26 #include <linux/interrupt.h> 27 27 #include <linux/mfd/max8925.h> 28 28 #include <linux/slab.h> 29 + #include <linux/device.h> 29 30 30 31 #define SW_INPUT (1 << 7) /* 0/1 -- up/down */ 31 32 #define HARDRESET_EN (1 << 7) ··· 82 81 return -EINVAL; 83 82 } 84 83 85 - info = kzalloc(sizeof(struct max8925_onkey_info), GFP_KERNEL); 86 - input = input_allocate_device(); 87 - if (!info || !input) { 88 - error = -ENOMEM; 89 - goto err_free_mem; 90 - } 84 + info = devm_kzalloc(&pdev->dev, sizeof(struct max8925_onkey_info), 85 + GFP_KERNEL); 86 + if (!info) 87 + return -ENOMEM; 88 + 89 + input = devm_input_allocate_device(&pdev->dev); 90 + if (!input) 91 + return -ENOMEM; 91 92 92 93 info->idev = input; 93 94 info->i2c = chip->i2c; ··· 103 100 input->dev.parent = &pdev->dev; 104 101 input_set_capability(input, EV_KEY, KEY_POWER); 105 102 106 - error = request_threaded_irq(irq[0], NULL, max8925_onkey_handler, 107 - IRQF_ONESHOT, "onkey-down", info); 103 + error = devm_request_threaded_irq(&pdev->dev, irq[0], NULL, 104 + max8925_onkey_handler, IRQF_ONESHOT, 105 + "onkey-down", info); 108 106 if (error < 0) { 109 107 dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n", 110 108 irq[0], error); 111 - goto err_free_mem; 109 + return error; 112 110 } 113 111 114 - error = request_threaded_irq(irq[1], NULL, max8925_onkey_handler, 115 - IRQF_ONESHOT, "onkey-up", info); 112 + error = devm_request_threaded_irq(&pdev->dev, irq[1], NULL, 113 + max8925_onkey_handler, IRQF_ONESHOT, 114 + "onkey-up", info); 116 115 if (error < 0) { 117 116 dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n", 118 117 irq[1], error); 119 - goto err_free_irq0; 118 + return error; 120 119 } 121 120 122 121 error = input_register_device(info->idev); 123 122 if (error) { 124 123 dev_err(chip->dev, "Can't register input device: %d\n", error); 125 - goto err_free_irq1; 124 + return error; 126 125 } 127 126 128 127 platform_set_drvdata(pdev, info); 129 128 device_init_wakeup(&pdev->dev, 1); 130 - 131 - return 0; 132 - 133 - err_free_irq1: 134 - free_irq(irq[1], info); 135 - err_free_irq0: 136 - free_irq(irq[0], info); 137 - err_free_mem: 138 - input_free_device(input); 139 - kfree(info); 140 - 141 - return error; 142 - } 143 - 144 - static int max8925_onkey_remove(struct platform_device *pdev) 145 - { 146 - struct max8925_onkey_info *info = platform_get_drvdata(pdev); 147 - struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent); 148 - 149 - free_irq(info->irq[0] + chip->irq_base, info); 150 - free_irq(info->irq[1] + chip->irq_base, info); 151 - input_unregister_device(info->idev); 152 - kfree(info); 153 129 154 130 return 0; 155 131 } ··· 172 190 .pm = &max8925_onkey_pm_ops, 173 191 }, 174 192 .probe = max8925_onkey_probe, 175 - .remove = max8925_onkey_remove, 176 193 }; 177 194 module_platform_driver(max8925_onkey_driver); 178 195