aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Boyd <sboyd@codeaurora.org>2013-12-15 06:43:06 -0500
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2013-12-15 06:58:31 -0500
commit12a5a8fdfbab14427df0eb6e6c05559444ee2c73 (patch)
tree421b3a82a1c8b75043ec4ac1f8638738eb4841c3
parent9222d8069d3812400b346ebd5fea47b8b88c7cbf (diff)
Input: pm8xxx-vibrator - switch to using managed resources
Simplify the error paths and reduce the lines of code in this driver by using the devm_* APIs. Signed-off-by: Stephen Boyd <sboyd@codeaurora.org> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
-rw-r--r--drivers/input/misc/pm8xxx-vibrator.c43
1 files changed, 12 insertions, 31 deletions
diff --git a/drivers/input/misc/pm8xxx-vibrator.c b/drivers/input/misc/pm8xxx-vibrator.c
index ec086f6f3cc3..50be8abb7d0c 100644
--- a/drivers/input/misc/pm8xxx-vibrator.c
+++ b/drivers/input/misc/pm8xxx-vibrator.c
@@ -186,13 +186,13 @@ static int pm8xxx_vib_probe(struct platform_device *pdev)
186 int error; 186 int error;
187 u8 val; 187 u8 val;
188 188
189 vib = kzalloc(sizeof(*vib), GFP_KERNEL); 189 vib = devm_kzalloc(&pdev->dev, sizeof(*vib), GFP_KERNEL);
190 input_dev = input_allocate_device(); 190 if (!vib)
191 if (!vib || !input_dev) { 191 return -ENOMEM;
192 dev_err(&pdev->dev, "couldn't allocate memory\n"); 192
193 error = -ENOMEM; 193 input_dev = devm_input_allocate_device(&pdev->dev);
194 goto err_free_mem; 194 if (!input_dev)
195 } 195 return -ENOMEM;
196 196
197 INIT_WORK(&vib->work, pm8xxx_work_handler); 197 INIT_WORK(&vib->work, pm8xxx_work_handler);
198 vib->dev = &pdev->dev; 198 vib->dev = &pdev->dev;
@@ -201,17 +201,17 @@ static int pm8xxx_vib_probe(struct platform_device *pdev)
201 /* operate in manual mode */ 201 /* operate in manual mode */
202 error = pm8xxx_vib_read_u8(vib, &val, VIB_DRV); 202 error = pm8xxx_vib_read_u8(vib, &val, VIB_DRV);
203 if (error < 0) 203 if (error < 0)
204 goto err_free_mem; 204 return error;
205
205 val &= ~VIB_DRV_EN_MANUAL_MASK; 206 val &= ~VIB_DRV_EN_MANUAL_MASK;
206 error = pm8xxx_vib_write_u8(vib, val, VIB_DRV); 207 error = pm8xxx_vib_write_u8(vib, val, VIB_DRV);
207 if (error < 0) 208 if (error < 0)
208 goto err_free_mem; 209 return error;
209 210
210 vib->reg_vib_drv = val; 211 vib->reg_vib_drv = val;
211 212
212 input_dev->name = "pm8xxx_vib_ffmemless"; 213 input_dev->name = "pm8xxx_vib_ffmemless";
213 input_dev->id.version = 1; 214 input_dev->id.version = 1;
214 input_dev->dev.parent = &pdev->dev;
215 input_dev->close = pm8xxx_vib_close; 215 input_dev->close = pm8xxx_vib_close;
216 input_set_drvdata(input_dev, vib); 216 input_set_drvdata(input_dev, vib);
217 input_set_capability(vib->vib_input_dev, EV_FF, FF_RUMBLE); 217 input_set_capability(vib->vib_input_dev, EV_FF, FF_RUMBLE);
@@ -221,35 +221,17 @@ static int pm8xxx_vib_probe(struct platform_device *pdev)
221 if (error) { 221 if (error) {
222 dev_err(&pdev->dev, 222 dev_err(&pdev->dev,
223 "couldn't register vibrator as FF device\n"); 223 "couldn't register vibrator as FF device\n");
224 goto err_free_mem; 224 return error;
225 } 225 }
226 226
227 error = input_register_device(input_dev); 227 error = input_register_device(input_dev);
228 if (error) { 228 if (error) {
229 dev_err(&pdev->dev, "couldn't register input device\n"); 229 dev_err(&pdev->dev, "couldn't register input device\n");
230 goto err_destroy_memless; 230 return error;
231 } 231 }
232 232
233 platform_set_drvdata(pdev, vib); 233 platform_set_drvdata(pdev, vib);
234 return 0; 234 return 0;
235
236err_destroy_memless:
237 input_ff_destroy(input_dev);
238err_free_mem:
239 input_free_device(input_dev);
240 kfree(vib);
241
242 return error;
243}
244
245static int pm8xxx_vib_remove(struct platform_device *pdev)
246{
247 struct pm8xxx_vib *vib = platform_get_drvdata(pdev);
248
249 input_unregister_device(vib->vib_input_dev);
250 kfree(vib);
251
252 return 0;
253} 235}
254 236
255#ifdef CONFIG_PM_SLEEP 237#ifdef CONFIG_PM_SLEEP
@@ -268,7 +250,6 @@ static SIMPLE_DEV_PM_OPS(pm8xxx_vib_pm_ops, pm8xxx_vib_suspend, NULL);
268 250
269static struct platform_driver pm8xxx_vib_driver = { 251static struct platform_driver pm8xxx_vib_driver = {
270 .probe = pm8xxx_vib_probe, 252 .probe = pm8xxx_vib_probe,
271 .remove = pm8xxx_vib_remove,
272 .driver = { 253 .driver = {
273 .name = "pm8xxx-vib", 254 .name = "pm8xxx-vib",
274 .owner = THIS_MODULE, 255 .owner = THIS_MODULE,