diff options
author | Himangi Saraogi <himangi774@gmail.com> | 2014-05-29 03:21:56 -0400 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2014-05-29 03:26:35 -0400 |
commit | 04115e410c85b841f0f97785fe2a58d231e44890 (patch) | |
tree | 65bffaddf9999be501d6f0a23ed4b3520750c16d /drivers/input/misc | |
parent | 5ac66de5744b832530645ad82935d7357dba7afc (diff) |
Input: max8925_onkey - 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>
Diffstat (limited to 'drivers/input/misc')
-rw-r--r-- | drivers/input/misc/max8925_onkey.c | 55 |
1 files changed, 18 insertions, 37 deletions
diff --git a/drivers/input/misc/max8925_onkey.c b/drivers/input/misc/max8925_onkey.c index eef41cfc054d..3809618e6a5d 100644 --- a/drivers/input/misc/max8925_onkey.c +++ b/drivers/input/misc/max8925_onkey.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include <linux/interrupt.h> | 26 | #include <linux/interrupt.h> |
27 | #include <linux/mfd/max8925.h> | 27 | #include <linux/mfd/max8925.h> |
28 | #include <linux/slab.h> | 28 | #include <linux/slab.h> |
29 | #include <linux/device.h> | ||
29 | 30 | ||
30 | #define SW_INPUT (1 << 7) /* 0/1 -- up/down */ | 31 | #define SW_INPUT (1 << 7) /* 0/1 -- up/down */ |
31 | #define HARDRESET_EN (1 << 7) | 32 | #define HARDRESET_EN (1 << 7) |
@@ -81,12 +82,14 @@ static int max8925_onkey_probe(struct platform_device *pdev) | |||
81 | return -EINVAL; | 82 | return -EINVAL; |
82 | } | 83 | } |
83 | 84 | ||
84 | info = kzalloc(sizeof(struct max8925_onkey_info), GFP_KERNEL); | 85 | info = devm_kzalloc(&pdev->dev, sizeof(struct max8925_onkey_info), |
85 | input = input_allocate_device(); | 86 | GFP_KERNEL); |
86 | if (!info || !input) { | 87 | if (!info) |
87 | error = -ENOMEM; | 88 | return -ENOMEM; |
88 | goto err_free_mem; | 89 | |
89 | } | 90 | input = devm_input_allocate_device(&pdev->dev); |
91 | if (!input) | ||
92 | return -ENOMEM; | ||
90 | 93 | ||
91 | info->idev = input; | 94 | info->idev = input; |
92 | info->i2c = chip->i2c; | 95 | info->i2c = chip->i2c; |
@@ -100,55 +103,34 @@ static int max8925_onkey_probe(struct platform_device *pdev) | |||
100 | input->dev.parent = &pdev->dev; | 103 | input->dev.parent = &pdev->dev; |
101 | input_set_capability(input, EV_KEY, KEY_POWER); | 104 | input_set_capability(input, EV_KEY, KEY_POWER); |
102 | 105 | ||
103 | error = request_threaded_irq(irq[0], NULL, max8925_onkey_handler, | 106 | error = devm_request_threaded_irq(&pdev->dev, irq[0], NULL, |
104 | IRQF_ONESHOT, "onkey-down", info); | 107 | max8925_onkey_handler, IRQF_ONESHOT, |
108 | "onkey-down", info); | ||
105 | if (error < 0) { | 109 | if (error < 0) { |
106 | dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n", | 110 | dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n", |
107 | irq[0], error); | 111 | irq[0], error); |
108 | goto err_free_mem; | 112 | return error; |
109 | } | 113 | } |
110 | 114 | ||
111 | error = request_threaded_irq(irq[1], NULL, max8925_onkey_handler, | 115 | error = devm_request_threaded_irq(&pdev->dev, irq[1], NULL, |
112 | IRQF_ONESHOT, "onkey-up", info); | 116 | max8925_onkey_handler, IRQF_ONESHOT, |
117 | "onkey-up", info); | ||
113 | if (error < 0) { | 118 | if (error < 0) { |
114 | dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n", | 119 | dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n", |
115 | irq[1], error); | 120 | irq[1], error); |
116 | goto err_free_irq0; | 121 | return error; |
117 | } | 122 | } |
118 | 123 | ||
119 | error = input_register_device(info->idev); | 124 | error = input_register_device(info->idev); |
120 | if (error) { | 125 | if (error) { |
121 | dev_err(chip->dev, "Can't register input device: %d\n", error); | 126 | dev_err(chip->dev, "Can't register input device: %d\n", error); |
122 | goto err_free_irq1; | 127 | return error; |
123 | } | 128 | } |
124 | 129 | ||
125 | platform_set_drvdata(pdev, info); | 130 | platform_set_drvdata(pdev, info); |
126 | device_init_wakeup(&pdev->dev, 1); | 131 | device_init_wakeup(&pdev->dev, 1); |
127 | 132 | ||
128 | return 0; | 133 | return 0; |
129 | |||
130 | err_free_irq1: | ||
131 | free_irq(irq[1], info); | ||
132 | err_free_irq0: | ||
133 | free_irq(irq[0], info); | ||
134 | err_free_mem: | ||
135 | input_free_device(input); | ||
136 | kfree(info); | ||
137 | |||
138 | return error; | ||
139 | } | ||
140 | |||
141 | static int max8925_onkey_remove(struct platform_device *pdev) | ||
142 | { | ||
143 | struct max8925_onkey_info *info = platform_get_drvdata(pdev); | ||
144 | struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent); | ||
145 | |||
146 | free_irq(info->irq[0] + chip->irq_base, info); | ||
147 | free_irq(info->irq[1] + chip->irq_base, info); | ||
148 | input_unregister_device(info->idev); | ||
149 | kfree(info); | ||
150 | |||
151 | return 0; | ||
152 | } | 134 | } |
153 | 135 | ||
154 | #ifdef CONFIG_PM_SLEEP | 136 | #ifdef CONFIG_PM_SLEEP |
@@ -190,7 +172,6 @@ static struct platform_driver max8925_onkey_driver = { | |||
190 | .pm = &max8925_onkey_pm_ops, | 172 | .pm = &max8925_onkey_pm_ops, |
191 | }, | 173 | }, |
192 | .probe = max8925_onkey_probe, | 174 | .probe = max8925_onkey_probe, |
193 | .remove = max8925_onkey_remove, | ||
194 | }; | 175 | }; |
195 | module_platform_driver(max8925_onkey_driver); | 176 | module_platform_driver(max8925_onkey_driver); |
196 | 177 | ||