diff options
author | Himangi Saraogi <himangi774@gmail.com> | 2014-05-29 03:23:39 -0400 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2014-05-29 03:26:36 -0400 |
commit | 7b961d5b12dc5cfbe564dab3e4841c2ad1ce3228 (patch) | |
tree | fc4b0883e37b417c34314e84f06735d90ef8ef37 | |
parent | 04115e410c85b841f0f97785fe2a58d231e44890 (diff) |
Input: ab8500-ponkey - 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>
-rw-r--r-- | drivers/input/misc/ab8500-ponkey.c | 54 |
1 files changed, 18 insertions, 36 deletions
diff --git a/drivers/input/misc/ab8500-ponkey.c b/drivers/input/misc/ab8500-ponkey.c index f2fbdd88ed20..95ef7dd6442d 100644 --- a/drivers/input/misc/ab8500-ponkey.c +++ b/drivers/input/misc/ab8500-ponkey.c | |||
@@ -7,6 +7,7 @@ | |||
7 | * AB8500 Power-On Key handler | 7 | * AB8500 Power-On Key handler |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <linux/device.h> | ||
10 | #include <linux/kernel.h> | 11 | #include <linux/kernel.h> |
11 | #include <linux/module.h> | 12 | #include <linux/module.h> |
12 | #include <linux/platform_device.h> | 13 | #include <linux/platform_device.h> |
@@ -65,12 +66,14 @@ static int ab8500_ponkey_probe(struct platform_device *pdev) | |||
65 | return irq_dbr; | 66 | return irq_dbr; |
66 | } | 67 | } |
67 | 68 | ||
68 | ponkey = kzalloc(sizeof(struct ab8500_ponkey), GFP_KERNEL); | 69 | ponkey = devm_kzalloc(&pdev->dev, sizeof(struct ab8500_ponkey), |
69 | input = input_allocate_device(); | 70 | GFP_KERNEL); |
70 | if (!ponkey || !input) { | 71 | if (!ponkey) |
71 | error = -ENOMEM; | 72 | return -ENOMEM; |
72 | goto err_free_mem; | 73 | |
73 | } | 74 | input = devm_input_allocate_device(&pdev->dev); |
75 | if (!input) | ||
76 | return -ENOMEM; | ||
74 | 77 | ||
75 | ponkey->idev = input; | 78 | ponkey->idev = input; |
76 | ponkey->ab8500 = ab8500; | 79 | ponkey->ab8500 = ab8500; |
@@ -82,52 +85,32 @@ static int ab8500_ponkey_probe(struct platform_device *pdev) | |||
82 | 85 | ||
83 | input_set_capability(input, EV_KEY, KEY_POWER); | 86 | input_set_capability(input, EV_KEY, KEY_POWER); |
84 | 87 | ||
85 | error = request_any_context_irq(ponkey->irq_dbf, ab8500_ponkey_handler, | 88 | error = devm_request_any_context_irq(&pdev->dev, ponkey->irq_dbf, |
86 | 0, "ab8500-ponkey-dbf", ponkey); | 89 | ab8500_ponkey_handler, 0, |
90 | "ab8500-ponkey-dbf", ponkey); | ||
87 | if (error < 0) { | 91 | if (error < 0) { |
88 | dev_err(ab8500->dev, "Failed to request dbf IRQ#%d: %d\n", | 92 | dev_err(ab8500->dev, "Failed to request dbf IRQ#%d: %d\n", |
89 | ponkey->irq_dbf, error); | 93 | ponkey->irq_dbf, error); |
90 | goto err_free_mem; | 94 | return error; |
91 | } | 95 | } |
92 | 96 | ||
93 | error = request_any_context_irq(ponkey->irq_dbr, ab8500_ponkey_handler, | 97 | error = devm_request_any_context_irq(&pdev->dev, ponkey->irq_dbr, |
94 | 0, "ab8500-ponkey-dbr", ponkey); | 98 | ab8500_ponkey_handler, 0, |
99 | "ab8500-ponkey-dbr", ponkey); | ||
95 | if (error < 0) { | 100 | if (error < 0) { |
96 | dev_err(ab8500->dev, "Failed to request dbr IRQ#%d: %d\n", | 101 | dev_err(ab8500->dev, "Failed to request dbr IRQ#%d: %d\n", |
97 | ponkey->irq_dbr, error); | 102 | ponkey->irq_dbr, error); |
98 | goto err_free_dbf_irq; | 103 | return error; |
99 | } | 104 | } |
100 | 105 | ||
101 | error = input_register_device(ponkey->idev); | 106 | error = input_register_device(ponkey->idev); |
102 | if (error) { | 107 | if (error) { |
103 | dev_err(ab8500->dev, "Can't register input device: %d\n", error); | 108 | dev_err(ab8500->dev, "Can't register input device: %d\n", error); |
104 | goto err_free_dbr_irq; | 109 | return error; |
105 | } | 110 | } |
106 | 111 | ||
107 | platform_set_drvdata(pdev, ponkey); | 112 | platform_set_drvdata(pdev, ponkey); |
108 | return 0; | 113 | return 0; |
109 | |||
110 | err_free_dbr_irq: | ||
111 | free_irq(ponkey->irq_dbr, ponkey); | ||
112 | err_free_dbf_irq: | ||
113 | free_irq(ponkey->irq_dbf, ponkey); | ||
114 | err_free_mem: | ||
115 | input_free_device(input); | ||
116 | kfree(ponkey); | ||
117 | |||
118 | return error; | ||
119 | } | ||
120 | |||
121 | static int ab8500_ponkey_remove(struct platform_device *pdev) | ||
122 | { | ||
123 | struct ab8500_ponkey *ponkey = platform_get_drvdata(pdev); | ||
124 | |||
125 | free_irq(ponkey->irq_dbf, ponkey); | ||
126 | free_irq(ponkey->irq_dbr, ponkey); | ||
127 | input_unregister_device(ponkey->idev); | ||
128 | kfree(ponkey); | ||
129 | |||
130 | return 0; | ||
131 | } | 114 | } |
132 | 115 | ||
133 | #ifdef CONFIG_OF | 116 | #ifdef CONFIG_OF |
@@ -144,7 +127,6 @@ static struct platform_driver ab8500_ponkey_driver = { | |||
144 | .of_match_table = of_match_ptr(ab8500_ponkey_match), | 127 | .of_match_table = of_match_ptr(ab8500_ponkey_match), |
145 | }, | 128 | }, |
146 | .probe = ab8500_ponkey_probe, | 129 | .probe = ab8500_ponkey_probe, |
147 | .remove = ab8500_ponkey_remove, | ||
148 | }; | 130 | }; |
149 | module_platform_driver(ab8500_ponkey_driver); | 131 | module_platform_driver(ab8500_ponkey_driver); |
150 | 132 | ||