diff options
author | Viresh Kumar <viresh.kumar@linaro.org> | 2012-11-10 03:11:10 -0500 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2012-11-10 03:30:33 -0500 |
commit | aaa4f2a7f6cce4485dc60063a56e210761f5a0c8 (patch) | |
tree | 1f84b9eda26990b93e4ec5cba60e0bf274824b46 /drivers/input | |
parent | 6102752eb354cca8fb751d8bace2c1ad4efffdde (diff) |
Input: stmpe-keyboard - switch to using managed resources
This patch frees stmpe-keyboard driver from burden of freeing resources :)
devm_* derivatives of multiple routines are used while allocating resources,
which would be freed automatically by kernel.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input')
-rw-r--r-- | drivers/input/keyboard/stmpe-keypad.c | 72 |
1 files changed, 28 insertions, 44 deletions
diff --git a/drivers/input/keyboard/stmpe-keypad.c b/drivers/input/keyboard/stmpe-keypad.c index 470a8778dec1..d3d2eaa5f841 100644 --- a/drivers/input/keyboard/stmpe-keypad.c +++ b/drivers/input/keyboard/stmpe-keypad.c | |||
@@ -260,10 +260,10 @@ static int __devinit stmpe_keypad_chip_init(struct stmpe_keypad *keypad) | |||
260 | static int __devinit stmpe_keypad_probe(struct platform_device *pdev) | 260 | static int __devinit stmpe_keypad_probe(struct platform_device *pdev) |
261 | { | 261 | { |
262 | struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent); | 262 | struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent); |
263 | struct stmpe_keypad_platform_data *plat; | 263 | const struct stmpe_keypad_platform_data *plat; |
264 | struct stmpe_keypad *keypad; | 264 | struct stmpe_keypad *keypad; |
265 | struct input_dev *input; | 265 | struct input_dev *input; |
266 | int ret; | 266 | int error; |
267 | int irq; | 267 | int irq; |
268 | int i; | 268 | int i; |
269 | 269 | ||
@@ -275,26 +275,25 @@ static int __devinit stmpe_keypad_probe(struct platform_device *pdev) | |||
275 | if (irq < 0) | 275 | if (irq < 0) |
276 | return irq; | 276 | return irq; |
277 | 277 | ||
278 | keypad = kzalloc(sizeof(struct stmpe_keypad), GFP_KERNEL); | 278 | keypad = devm_kzalloc(&pdev->dev, sizeof(struct stmpe_keypad), |
279 | GFP_KERNEL); | ||
279 | if (!keypad) | 280 | if (!keypad) |
280 | return -ENOMEM; | 281 | return -ENOMEM; |
281 | 282 | ||
282 | input = input_allocate_device(); | 283 | input = devm_input_allocate_device(&pdev->dev); |
283 | if (!input) { | 284 | if (!input) |
284 | ret = -ENOMEM; | 285 | return -ENOMEM; |
285 | goto out_freekeypad; | ||
286 | } | ||
287 | 286 | ||
288 | input->name = "STMPE keypad"; | 287 | input->name = "STMPE keypad"; |
289 | input->id.bustype = BUS_I2C; | 288 | input->id.bustype = BUS_I2C; |
290 | input->dev.parent = &pdev->dev; | 289 | input->dev.parent = &pdev->dev; |
291 | 290 | ||
292 | ret = matrix_keypad_build_keymap(plat->keymap_data, NULL, | 291 | error = matrix_keypad_build_keymap(plat->keymap_data, NULL, |
293 | STMPE_KEYPAD_MAX_ROWS, | 292 | STMPE_KEYPAD_MAX_ROWS, |
294 | STMPE_KEYPAD_MAX_COLS, | 293 | STMPE_KEYPAD_MAX_COLS, |
295 | keypad->keymap, input); | 294 | keypad->keymap, input); |
296 | if (ret) | 295 | if (error) |
297 | goto out_freeinput; | 296 | return error; |
298 | 297 | ||
299 | input_set_capability(input, EV_MSC, MSC_SCAN); | 298 | input_set_capability(input, EV_MSC, MSC_SCAN); |
300 | if (!plat->no_autorepeat) | 299 | if (!plat->no_autorepeat) |
@@ -312,50 +311,35 @@ static int __devinit stmpe_keypad_probe(struct platform_device *pdev) | |||
312 | keypad->input = input; | 311 | keypad->input = input; |
313 | keypad->variant = &stmpe_keypad_variants[stmpe->partnum]; | 312 | keypad->variant = &stmpe_keypad_variants[stmpe->partnum]; |
314 | 313 | ||
315 | ret = stmpe_keypad_chip_init(keypad); | 314 | error = stmpe_keypad_chip_init(keypad); |
316 | if (ret < 0) | 315 | if (error < 0) |
317 | goto out_freeinput; | 316 | return error; |
318 | 317 | ||
319 | ret = input_register_device(input); | 318 | error = devm_request_threaded_irq(&pdev->dev, irq, |
320 | if (ret) { | 319 | NULL, stmpe_keypad_irq, |
321 | dev_err(&pdev->dev, | 320 | IRQF_ONESHOT, "stmpe-keypad", keypad); |
322 | "unable to register input device: %d\n", ret); | 321 | if (error) { |
323 | goto out_freeinput; | 322 | dev_err(&pdev->dev, "unable to get irq: %d\n", error); |
323 | return error; | ||
324 | } | 324 | } |
325 | 325 | ||
326 | ret = request_threaded_irq(irq, NULL, stmpe_keypad_irq, IRQF_ONESHOT, | 326 | error = input_register_device(input); |
327 | "stmpe-keypad", keypad); | 327 | if (error) { |
328 | if (ret) { | 328 | dev_err(&pdev->dev, |
329 | dev_err(&pdev->dev, "unable to get irq: %d\n", ret); | 329 | "unable to register input device: %d\n", error); |
330 | goto out_unregisterinput; | 330 | return error; |
331 | } | 331 | } |
332 | 332 | ||
333 | platform_set_drvdata(pdev, keypad); | 333 | platform_set_drvdata(pdev, keypad); |
334 | 334 | ||
335 | return 0; | 335 | return 0; |
336 | |||
337 | out_unregisterinput: | ||
338 | input_unregister_device(input); | ||
339 | input = NULL; | ||
340 | out_freeinput: | ||
341 | input_free_device(input); | ||
342 | out_freekeypad: | ||
343 | kfree(keypad); | ||
344 | return ret; | ||
345 | } | 336 | } |
346 | 337 | ||
347 | static int __devexit stmpe_keypad_remove(struct platform_device *pdev) | 338 | static int __devexit stmpe_keypad_remove(struct platform_device *pdev) |
348 | { | 339 | { |
349 | struct stmpe_keypad *keypad = platform_get_drvdata(pdev); | 340 | struct stmpe_keypad *keypad = platform_get_drvdata(pdev); |
350 | struct stmpe *stmpe = keypad->stmpe; | ||
351 | int irq = platform_get_irq(pdev, 0); | ||
352 | |||
353 | stmpe_disable(stmpe, STMPE_BLOCK_KEYPAD); | ||
354 | 341 | ||
355 | free_irq(irq, keypad); | 342 | stmpe_disable(keypad->stmpe, STMPE_BLOCK_KEYPAD); |
356 | input_unregister_device(keypad->input); | ||
357 | platform_set_drvdata(pdev, NULL); | ||
358 | kfree(keypad); | ||
359 | 343 | ||
360 | return 0; | 344 | return 0; |
361 | } | 345 | } |