aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/misc/bfin_rotary.c
diff options
context:
space:
mode:
authorSonic Zhang <sonic.zhang@analog.com>2015-02-06 00:42:42 -0500
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2015-02-15 19:06:28 -0500
commitf14d4df93a6bb5712a92666901198403900790a0 (patch)
treed7247e8558e15dc77833f5fdaa8e4472ec250232 /drivers/input/misc/bfin_rotary.c
parent71adf22f476aae18bfe1fb7605d41f9cf95d0e5f (diff)
Input: bfin_rotary - convert to use managed resources
Use of managed resources simplifies error handling. Signed-off-by: Sonic Zhang <sonic.zhang@analog.com> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input/misc/bfin_rotary.c')
-rw-r--r--drivers/input/misc/bfin_rotary.c83
1 files changed, 38 insertions, 45 deletions
diff --git a/drivers/input/misc/bfin_rotary.c b/drivers/input/misc/bfin_rotary.c
index 791ea6a48984..ea8ed9c8dcbe 100644
--- a/drivers/input/misc/bfin_rotary.c
+++ b/drivers/input/misc/bfin_rotary.c
@@ -92,11 +92,15 @@ static irqreturn_t bfin_rotary_isr(int irq, void *dev_id)
92 return IRQ_HANDLED; 92 return IRQ_HANDLED;
93} 93}
94 94
95static void bfin_rotary_free_action(void *data)
96{
97 peripheral_free_list(data);
98}
99
95static int bfin_rotary_probe(struct platform_device *pdev) 100static int bfin_rotary_probe(struct platform_device *pdev)
96{ 101{
97 const struct bfin_rotary_platform_data *pdata =
98 dev_get_platdata(&pdev->dev);
99 struct device *dev = &pdev->dev; 102 struct device *dev = &pdev->dev;
103 const struct bfin_rotary_platform_data *pdata = dev_get_platdata(dev);
100 struct bfin_rot *rotary; 104 struct bfin_rot *rotary;
101 struct resource *res; 105 struct resource *res;
102 struct input_dev *input; 106 struct input_dev *input;
@@ -112,24 +116,33 @@ static int bfin_rotary_probe(struct platform_device *pdev)
112 error = peripheral_request_list(pdata->pin_list, 116 error = peripheral_request_list(pdata->pin_list,
113 dev_name(&pdev->dev)); 117 dev_name(&pdev->dev));
114 if (error) { 118 if (error) {
115 dev_err(&pdev->dev, "requesting peripherals failed\n"); 119 dev_err(dev, "requesting peripherals failed: %d\n",
120 error);
116 return error; 121 return error;
117 } 122 }
118 }
119 123
120 rotary = kzalloc(sizeof(struct bfin_rot), GFP_KERNEL); 124 error = devm_add_action(dev, bfin_rotary_free_action,
121 input = input_allocate_device(); 125 pdata->pin_list);
122 if (!rotary || !input) { 126 if (error) {
123 error = -ENOMEM; 127 dev_err(dev, "setting cleanup action failed: %d\n",
124 goto out1; 128 error);
129 peripheral_free_list(pdata->pin_list);
130 return error;
131 }
125 } 132 }
126 133
134 rotary = devm_kzalloc(dev, sizeof(struct bfin_rot), GFP_KERNEL);
135 if (!rotary)
136 return -ENOMEM;
137
127 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 138 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
128 rotary->base = devm_ioremap_resource(dev, res); 139 rotary->base = devm_ioremap_resource(dev, res);
129 if (IS_ERR(rotary->base)) { 140 if (IS_ERR(rotary->base))
130 error = PTR_ERR(rotary->base); 141 return PTR_ERR(rotary->base);
131 goto out1; 142
132 } 143 input = devm_input_allocate_device(dev);
144 if (!input)
145 return -ENOMEM;
133 146
134 rotary->input = input; 147 rotary->input = input;
135 148
@@ -138,10 +151,6 @@ static int bfin_rotary_probe(struct platform_device *pdev)
138 rotary->button_key = pdata->rotary_button_key; 151 rotary->button_key = pdata->rotary_button_key;
139 rotary->rel_code = pdata->rotary_rel_code; 152 rotary->rel_code = pdata->rotary_rel_code;
140 153
141 error = rotary->irq = platform_get_irq(pdev, 0);
142 if (error < 0)
143 goto out1;
144
145 input->name = pdev->name; 154 input->name = pdev->name;
146 input->phys = "bfin-rotary/input0"; 155 input->phys = "bfin-rotary/input0";
147 input->dev.parent = &pdev->dev; 156 input->dev.parent = &pdev->dev;
@@ -167,20 +176,24 @@ static int bfin_rotary_probe(struct platform_device *pdev)
167 __set_bit(rotary->button_key, input->keybit); 176 __set_bit(rotary->button_key, input->keybit);
168 } 177 }
169 178
170 error = request_irq(rotary->irq, bfin_rotary_isr, 179 rotary->irq = platform_get_irq(pdev, 0);
171 0, dev_name(&pdev->dev), rotary); 180 if (rotary->irq < 0) {
181 dev_err(dev, "No rotary IRQ specified\n");
182 return -ENOENT;
183 }
184
185 error = devm_request_irq(dev, rotary->irq, bfin_rotary_isr,
186 0, dev_name(dev), rotary);
172 if (error) { 187 if (error) {
173 dev_err(&pdev->dev, 188 dev_err(dev, "unable to claim irq %d; error %d\n",
174 "unable to claim irq %d; error %d\n",
175 rotary->irq, error); 189 rotary->irq, error);
176 goto out1; 190 return error;
177 } 191 }
178 192
179 error = input_register_device(input); 193 error = input_register_device(input);
180 if (error) { 194 if (error) {
181 dev_err(&pdev->dev, 195 dev_err(dev, "unable to register input device (%d)\n", error);
182 "unable to register input device (%d)\n", error); 196 return error;
183 goto out2;
184 } 197 }
185 198
186 if (pdata->rotary_button_key) 199 if (pdata->rotary_button_key)
@@ -204,35 +217,15 @@ static int bfin_rotary_probe(struct platform_device *pdev)
204 device_init_wakeup(&pdev->dev, 1); 217 device_init_wakeup(&pdev->dev, 1);
205 218
206 return 0; 219 return 0;
207
208out2:
209 free_irq(rotary->irq, rotary);
210out1:
211 input_free_device(input);
212 kfree(rotary);
213 if (pdata->pin_list)
214 peripheral_free_list(pdata->pin_list);
215
216 return error;
217} 220}
218 221
219static int bfin_rotary_remove(struct platform_device *pdev) 222static int bfin_rotary_remove(struct platform_device *pdev)
220{ 223{
221 const struct bfin_rotary_platform_data *pdata =
222 dev_get_platdata(&pdev->dev);
223 struct bfin_rot *rotary = platform_get_drvdata(pdev); 224 struct bfin_rot *rotary = platform_get_drvdata(pdev);
224 225
225 writew(0, rotary->base + CNT_CONFIG_OFF); 226 writew(0, rotary->base + CNT_CONFIG_OFF);
226 writew(0, rotary->base + CNT_IMASK_OFF); 227 writew(0, rotary->base + CNT_IMASK_OFF);
227 228
228 free_irq(rotary->irq, rotary);
229 input_unregister_device(rotary->input);
230
231 if (pdata->pin_list)
232 peripheral_free_list(pdata->pin_list);
233
234 kfree(rotary);
235
236 return 0; 229 return 0;
237} 230}
238 231