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

Input: cy8ctmg110_ts - switch to using managed resources

This simplifies error handling paths and allows to get rid of
cy8ctmg110_remove() method.

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/20210603043726.3793876-6-dmitry.torokhov@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+28 -46
+28 -46
drivers/input/touchscreen/cy8ctmg110_ts.c
··· 161 161 return IRQ_HANDLED; 162 162 } 163 163 164 + static void cy8ctmg110_shut_off(void *_ts) 165 + { 166 + struct cy8ctmg110 *ts = _ts; 167 + 168 + cy8ctmg110_set_sleepmode(ts, true); 169 + cy8ctmg110_power(ts, false); 170 + } 171 + 164 172 static int cy8ctmg110_probe(struct i2c_client *client, 165 173 const struct i2c_device_id *id) 166 174 { ··· 187 179 I2C_FUNC_SMBUS_READ_WORD_DATA)) 188 180 return -EIO; 189 181 190 - ts = kzalloc(sizeof(struct cy8ctmg110), GFP_KERNEL); 191 - input_dev = input_allocate_device(); 192 - if (!ts || !input_dev) { 193 - err = -ENOMEM; 194 - goto err_free_mem; 195 - } 182 + ts = devm_kzalloc(&client->dev, sizeof(*ts), GFP_KERNEL); 183 + if (!ts) 184 + return -ENOMEM; 185 + 186 + input_dev = devm_input_allocate_device(&client->dev); 187 + if (!input_dev) 188 + return -ENOMEM; 196 189 197 190 ts->client = client; 198 191 ts->input = input_dev; ··· 205 196 input_dev->name = CY8CTMG110_DRIVER_NAME " Touchscreen"; 206 197 input_dev->phys = ts->phys; 207 198 input_dev->id.bustype = BUS_I2C; 208 - input_dev->dev.parent = &client->dev; 209 199 210 - input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); 211 - input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); 212 - 200 + input_set_capability(input_dev, EV_KEY, BTN_TOUCH); 213 201 input_set_abs_params(input_dev, ABS_X, 214 202 CY8CTMG110_X_MIN, CY8CTMG110_X_MAX, 4, 0); 215 203 input_set_abs_params(input_dev, ABS_Y, 216 204 CY8CTMG110_Y_MIN, CY8CTMG110_Y_MAX, 4, 0); 217 205 218 206 if (ts->reset_pin) { 219 - err = gpio_request(ts->reset_pin, NULL); 207 + err = devm_gpio_request(&client->dev, ts->reset_pin, NULL); 220 208 if (err) { 221 209 dev_err(&client->dev, 222 210 "Unable to request GPIO pin %d.\n", 223 211 ts->reset_pin); 224 - goto err_free_mem; 212 + return err; 225 213 } 226 214 } 227 215 228 216 cy8ctmg110_power(ts, true); 229 217 cy8ctmg110_set_sleepmode(ts, false); 230 218 231 - err = request_threaded_irq(client->irq, NULL, cy8ctmg110_irq_thread, 232 - IRQF_ONESHOT, "touch_reset_key", ts); 233 - if (err < 0) { 219 + err = devm_add_action_or_reset(&client->dev, cy8ctmg110_shut_off, ts); 220 + if (err) 221 + return err; 222 + 223 + err = devm_request_threaded_irq(&client->dev, client->irq, 224 + NULL, cy8ctmg110_irq_thread, 225 + IRQF_ONESHOT, "touch_reset_key", ts); 226 + if (err) { 234 227 dev_err(&client->dev, 235 228 "irq %d busy? error %d\n", client->irq, err); 236 - goto err_shutoff_device; 229 + return err; 237 230 } 238 231 239 232 err = input_register_device(input_dev); 240 233 if (err) 241 - goto err_free_irq; 234 + return err; 242 235 243 236 i2c_set_clientdata(client, ts); 244 237 245 238 return 0; 246 - 247 - err_free_irq: 248 - free_irq(client->irq, ts); 249 - err_shutoff_device: 250 - cy8ctmg110_set_sleepmode(ts, true); 251 - cy8ctmg110_power(ts, false); 252 - if (ts->reset_pin) 253 - gpio_free(ts->reset_pin); 254 - err_free_mem: 255 - input_free_device(input_dev); 256 - kfree(ts); 257 - return err; 258 239 } 259 240 260 241 static int __maybe_unused cy8ctmg110_suspend(struct device *dev) ··· 275 276 276 277 static SIMPLE_DEV_PM_OPS(cy8ctmg110_pm, cy8ctmg110_suspend, cy8ctmg110_resume); 277 278 278 - static int cy8ctmg110_remove(struct i2c_client *client) 279 - { 280 - struct cy8ctmg110 *ts = i2c_get_clientdata(client); 281 - 282 - cy8ctmg110_set_sleepmode(ts, true); 283 - cy8ctmg110_power(ts, false); 284 - 285 - free_irq(client->irq, ts); 286 - input_unregister_device(ts->input); 287 - if (ts->reset_pin) 288 - gpio_free(ts->reset_pin); 289 - kfree(ts); 290 - 291 - return 0; 292 - } 293 - 294 279 static const struct i2c_device_id cy8ctmg110_idtable[] = { 295 280 { CY8CTMG110_DRIVER_NAME, 1 }, 296 281 { } ··· 289 306 }, 290 307 .id_table = cy8ctmg110_idtable, 291 308 .probe = cy8ctmg110_probe, 292 - .remove = cy8ctmg110_remove, 293 309 }; 294 310 295 311 module_i2c_driver(cy8ctmg110_driver);