summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2016-01-16 20:22:07 -0800
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2016-01-18 09:17:27 -0800
commitd9202af2ffa083f096684fd5f4b530aebbc07439 (patch)
tree0360cee99a7fbc9a3a83cf3f35abfeeb823df8d4 /drivers
parentafd2ff9b7e1b367172f18ba7f693dfb62bdcb2dc (diff)
downloadblackbird-op-linux-d9202af2ffa083f096684fd5f4b530aebbc07439.tar.gz
blackbird-op-linux-d9202af2ffa083f096684fd5f4b530aebbc07439.zip
Input: rotary_encoder - convert to devm-* api
Use managed resource API for simplifying error paths. Signed-off-by: Timo Teräs <timo.teras@iki.fi> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/input/misc/rotary_encoder.c86
1 files changed, 25 insertions, 61 deletions
diff --git a/drivers/input/misc/rotary_encoder.c b/drivers/input/misc/rotary_encoder.c
index 8aee71986430..ebbadf3f0579 100644
--- a/drivers/input/misc/rotary_encoder.c
+++ b/drivers/input/misc/rotary_encoder.c
@@ -211,8 +211,8 @@ static struct rotary_encoder_platform_data *rotary_encoder_parse_dt(struct devic
if (!of_id || !np)
return NULL;
- pdata = kzalloc(sizeof(struct rotary_encoder_platform_data),
- GFP_KERNEL);
+ pdata = devm_kzalloc(dev, sizeof(struct rotary_encoder_platform_data),
+ GFP_KERNEL);
if (!pdata)
return ERR_PTR(-ENOMEM);
@@ -277,12 +277,13 @@ static int rotary_encoder_probe(struct platform_device *pdev)
}
}
- encoder = kzalloc(sizeof(struct rotary_encoder), GFP_KERNEL);
- input = input_allocate_device();
- if (!encoder || !input) {
- err = -ENOMEM;
- goto exit_free_mem;
- }
+ encoder = devm_kzalloc(dev, sizeof(struct rotary_encoder), GFP_KERNEL);
+ if (!encoder)
+ return -ENOMEM;
+
+ input = devm_input_allocate_device(dev);
+ if (!input)
+ return -ENOMEM;
encoder->input = input;
encoder->pdata = pdata;
@@ -301,16 +302,18 @@ static int rotary_encoder_probe(struct platform_device *pdev)
}
/* request the GPIOs */
- err = gpio_request_one(pdata->gpio_a, GPIOF_IN, dev_name(dev));
+ err = devm_gpio_request_one(dev, pdata->gpio_a, GPIOF_IN,
+ dev_name(dev));
if (err) {
dev_err(dev, "unable to request GPIO %d\n", pdata->gpio_a);
- goto exit_free_mem;
+ return err;
}
- err = gpio_request_one(pdata->gpio_b, GPIOF_IN, dev_name(dev));
+ err = devm_gpio_request_one(dev, pdata->gpio_b, GPIOF_IN,
+ dev_name(dev));
if (err) {
dev_err(dev, "unable to request GPIO %d\n", pdata->gpio_b);
- goto exit_free_gpio_a;
+ return err;
}
encoder->irq_a = gpio_to_irq(pdata->gpio_a);
@@ -331,30 +334,29 @@ static int rotary_encoder_probe(struct platform_device *pdev)
default:
dev_err(dev, "'%d' is not a valid steps-per-period value\n",
pdata->steps_per_period);
- err = -EINVAL;
- goto exit_free_gpio_b;
+ return -EINVAL;
}
- err = request_irq(encoder->irq_a, handler,
- IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
- DRV_NAME, encoder);
+ err = devm_request_irq(dev, encoder->irq_a, handler,
+ IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
+ DRV_NAME, encoder);
if (err) {
dev_err(dev, "unable to request IRQ %d\n", encoder->irq_a);
- goto exit_free_gpio_b;
+ return err;
}
- err = request_irq(encoder->irq_b, handler,
- IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
- DRV_NAME, encoder);
+ err = devm_request_irq(dev, encoder->irq_b, handler,
+ IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
+ DRV_NAME, encoder);
if (err) {
dev_err(dev, "unable to request IRQ %d\n", encoder->irq_b);
- goto exit_free_irq_a;
+ return err;
}
err = input_register_device(input);
if (err) {
dev_err(dev, "failed to register input device\n");
- goto exit_free_irq_b;
+ return err;
}
device_init_wakeup(&pdev->dev, pdata->wakeup_source);
@@ -362,43 +364,6 @@ static int rotary_encoder_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, encoder);
return 0;
-
-exit_free_irq_b:
- free_irq(encoder->irq_b, encoder);
-exit_free_irq_a:
- free_irq(encoder->irq_a, encoder);
-exit_free_gpio_b:
- gpio_free(pdata->gpio_b);
-exit_free_gpio_a:
- gpio_free(pdata->gpio_a);
-exit_free_mem:
- input_free_device(input);
- kfree(encoder);
- if (!dev_get_platdata(&pdev->dev))
- kfree(pdata);
-
- return err;
-}
-
-static int rotary_encoder_remove(struct platform_device *pdev)
-{
- struct rotary_encoder *encoder = platform_get_drvdata(pdev);
- const struct rotary_encoder_platform_data *pdata = encoder->pdata;
-
- device_init_wakeup(&pdev->dev, false);
-
- free_irq(encoder->irq_a, encoder);
- free_irq(encoder->irq_b, encoder);
- gpio_free(pdata->gpio_a);
- gpio_free(pdata->gpio_b);
-
- input_unregister_device(encoder->input);
- kfree(encoder);
-
- if (!dev_get_platdata(&pdev->dev))
- kfree(pdata);
-
- return 0;
}
#ifdef CONFIG_PM_SLEEP
@@ -432,7 +397,6 @@ static SIMPLE_DEV_PM_OPS(rotary_encoder_pm_ops,
static struct platform_driver rotary_encoder_driver = {
.probe = rotary_encoder_probe,
- .remove = rotary_encoder_remove,
.driver = {
.name = DRV_NAME,
.pm = &rotary_encoder_pm_ops,
OpenPOWER on IntegriCloud