aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input
diff options
context:
space:
mode:
authorAlexander Shiyan <shc_work@mail.ru>2014-04-28 13:48:49 -0400
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2014-05-14 19:40:04 -0400
commit68252638c8d03a39e5055f823f842c6886d3f83b (patch)
treed07a424707d9adcb82151c163ec3549b9451dcb4 /drivers/input
parentbf1de9761c21f56d5b0c6a0acd3b792d801c61e6 (diff)
Input: gpio_keys_polled - convert to devm-* API
Replace existing resource handling in the driver with managed device resources, this ensures more consistent error values and simplifies error handling paths: kzalloc -> devm_kzalloc gpio_request_one -> devm_gpio_request_one input_allocate_polled_device -> devm_input_allocate_polled_device Signed-off-by: Alexander Shiyan <shc_work@mail.ru> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/keyboard/gpio_keys_polled.c98
1 files changed, 21 insertions, 77 deletions
diff --git a/drivers/input/keyboard/gpio_keys_polled.c b/drivers/input/keyboard/gpio_keys_polled.c
index bea53a633c52..432d36395f35 100644
--- a/drivers/input/keyboard/gpio_keys_polled.c
+++ b/drivers/input/keyboard/gpio_keys_polled.c
@@ -120,12 +120,10 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct
120 if (nbuttons == 0) 120 if (nbuttons == 0)
121 return NULL; 121 return NULL;
122 122
123 pdata = kzalloc(sizeof(*pdata) + nbuttons * (sizeof *button), 123 pdata = devm_kzalloc(dev, sizeof(*pdata) + nbuttons * sizeof(*button),
124 GFP_KERNEL); 124 GFP_KERNEL);
125 if (!pdata) { 125 if (!pdata)
126 error = -ENOMEM; 126 return ERR_PTR(-ENOMEM);
127 goto err_out;
128 }
129 127
130 pdata->buttons = (struct gpio_keys_button *)(pdata + 1); 128 pdata->buttons = (struct gpio_keys_button *)(pdata + 1);
131 pdata->nbuttons = nbuttons; 129 pdata->nbuttons = nbuttons;
@@ -151,7 +149,7 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct
151 dev_err(dev, 149 dev_err(dev,
152 "Failed to get gpio flags, error: %d\n", 150 "Failed to get gpio flags, error: %d\n",
153 error); 151 error);
154 goto err_free_pdata; 152 return ERR_PTR(error);
155 } 153 }
156 154
157 button = &pdata->buttons[i++]; 155 button = &pdata->buttons[i++];
@@ -162,8 +160,7 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct
162 if (of_property_read_u32(pp, "linux,code", &button->code)) { 160 if (of_property_read_u32(pp, "linux,code", &button->code)) {
163 dev_err(dev, "Button without keycode: 0x%x\n", 161 dev_err(dev, "Button without keycode: 0x%x\n",
164 button->gpio); 162 button->gpio);
165 error = -EINVAL; 163 return ERR_PTR(-EINVAL);
166 goto err_free_pdata;
167 } 164 }
168 165
169 button->desc = of_get_property(pp, "label", NULL); 166 button->desc = of_get_property(pp, "label", NULL);
@@ -178,17 +175,10 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct
178 button->debounce_interval = 5; 175 button->debounce_interval = 5;
179 } 176 }
180 177
181 if (pdata->nbuttons == 0) { 178 if (pdata->nbuttons == 0)
182 error = -EINVAL; 179 return ERR_PTR(-EINVAL);
183 goto err_free_pdata;
184 }
185 180
186 return pdata; 181 return pdata;
187
188err_free_pdata:
189 kfree(pdata);
190err_out:
191 return ERR_PTR(error);
192} 182}
193 183
194static const struct of_device_id gpio_keys_polled_of_match[] = { 184static const struct of_device_id gpio_keys_polled_of_match[] = {
@@ -213,6 +203,7 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)
213 struct gpio_keys_polled_dev *bdev; 203 struct gpio_keys_polled_dev *bdev;
214 struct input_polled_dev *poll_dev; 204 struct input_polled_dev *poll_dev;
215 struct input_dev *input; 205 struct input_dev *input;
206 size_t size;
216 int error; 207 int error;
217 int i; 208 int i;
218 209
@@ -228,24 +219,21 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)
228 219
229 if (!pdata->poll_interval) { 220 if (!pdata->poll_interval) {
230 dev_err(dev, "missing poll_interval value\n"); 221 dev_err(dev, "missing poll_interval value\n");
231 error = -EINVAL; 222 return -EINVAL;
232 goto err_free_pdata;
233 } 223 }
234 224
235 bdev = kzalloc(sizeof(struct gpio_keys_polled_dev) + 225 size = sizeof(struct gpio_keys_polled_dev) +
236 pdata->nbuttons * sizeof(struct gpio_keys_button_data), 226 pdata->nbuttons * sizeof(struct gpio_keys_button_data);
237 GFP_KERNEL); 227 bdev = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
238 if (!bdev) { 228 if (!bdev) {
239 dev_err(dev, "no memory for private data\n"); 229 dev_err(dev, "no memory for private data\n");
240 error = -ENOMEM; 230 return -ENOMEM;
241 goto err_free_pdata;
242 } 231 }
243 232
244 poll_dev = input_allocate_polled_device(); 233 poll_dev = devm_input_allocate_polled_device(&pdev->dev);
245 if (!poll_dev) { 234 if (!poll_dev) {
246 dev_err(dev, "no memory for polled device\n"); 235 dev_err(dev, "no memory for polled device\n");
247 error = -ENOMEM; 236 return -ENOMEM;
248 goto err_free_bdev;
249 } 237 }
250 238
251 poll_dev->private = bdev; 239 poll_dev->private = bdev;
@@ -258,7 +246,6 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)
258 246
259 input->name = pdev->name; 247 input->name = pdev->name;
260 input->phys = DRV_NAME"/input0"; 248 input->phys = DRV_NAME"/input0";
261 input->dev.parent = &pdev->dev;
262 249
263 input->id.bustype = BUS_HOST; 250 input->id.bustype = BUS_HOST;
264 input->id.vendor = 0x0001; 251 input->id.vendor = 0x0001;
@@ -277,16 +264,15 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)
277 264
278 if (button->wakeup) { 265 if (button->wakeup) {
279 dev_err(dev, DRV_NAME " does not support wakeup\n"); 266 dev_err(dev, DRV_NAME " does not support wakeup\n");
280 error = -EINVAL; 267 return -EINVAL;
281 goto err_free_gpio;
282 } 268 }
283 269
284 error = gpio_request_one(gpio, GPIOF_IN, 270 error = devm_gpio_request_one(&pdev->dev, gpio, GPIOF_IN,
285 button->desc ?: DRV_NAME); 271 button->desc ? : DRV_NAME);
286 if (error) { 272 if (error) {
287 dev_err(dev, "unable to claim gpio %u, err=%d\n", 273 dev_err(dev, "unable to claim gpio %u, err=%d\n",
288 gpio, error); 274 gpio, error);
289 goto err_free_gpio; 275 return error;
290 } 276 }
291 277
292 bdata->can_sleep = gpio_cansleep(gpio); 278 bdata->can_sleep = gpio_cansleep(gpio);
@@ -306,7 +292,7 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)
306 if (error) { 292 if (error) {
307 dev_err(dev, "unable to register polled device, err=%d\n", 293 dev_err(dev, "unable to register polled device, err=%d\n",
308 error); 294 error);
309 goto err_free_gpio; 295 return error;
310 } 296 }
311 297
312 /* report initial state of the buttons */ 298 /* report initial state of the buttons */
@@ -315,52 +301,10 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)
315 &bdev->data[i]); 301 &bdev->data[i]);
316 302
317 return 0; 303 return 0;
318
319err_free_gpio:
320 while (--i >= 0)
321 gpio_free(pdata->buttons[i].gpio);
322
323 input_free_polled_device(poll_dev);
324
325err_free_bdev:
326 kfree(bdev);
327
328err_free_pdata:
329 /* If we have no platform_data, we allocated pdata dynamically. */
330 if (!dev_get_platdata(&pdev->dev))
331 kfree(pdata);
332
333 return error;
334}
335
336static int gpio_keys_polled_remove(struct platform_device *pdev)
337{
338 struct gpio_keys_polled_dev *bdev = platform_get_drvdata(pdev);
339 const struct gpio_keys_platform_data *pdata = bdev->pdata;
340 int i;
341
342 input_unregister_polled_device(bdev->poll_dev);
343
344 for (i = 0; i < pdata->nbuttons; i++)
345 gpio_free(pdata->buttons[i].gpio);
346
347 input_free_polled_device(bdev->poll_dev);
348
349 /*
350 * If we had no platform_data, we allocated pdata dynamically and
351 * must free it here.
352 */
353 if (!dev_get_platdata(&pdev->dev))
354 kfree(pdata);
355
356 kfree(bdev);
357
358 return 0;
359} 304}
360 305
361static struct platform_driver gpio_keys_polled_driver = { 306static struct platform_driver gpio_keys_polled_driver = {
362 .probe = gpio_keys_polled_probe, 307 .probe = gpio_keys_polled_probe,
363 .remove = gpio_keys_polled_remove,
364 .driver = { 308 .driver = {
365 .name = DRV_NAME, 309 .name = DRV_NAME,
366 .owner = THIS_MODULE, 310 .owner = THIS_MODULE,