diff options
author | Pramod Gurav <pramod.gurav@smartplayin.com> | 2014-10-07 12:06:31 -0400 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2014-10-07 12:55:01 -0400 |
commit | 848d479361793edb79aa68140cb64d4ec9032d88 (patch) | |
tree | 34fb59f5e0aa844c9b394bc6be1047d77f69e2a8 /drivers/input | |
parent | 7c4f56070fde2367766fa1fb04852599b5e1ad35 (diff) |
Input: opencores-kbd - switch to using managed resources
This change switch to managed resources to simplifies error handling
and module unloading and does away with platform_driver remove function.
Signed-off-by: Pramod Gurav <pramod.gurav@smartplayin.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input')
-rw-r--r-- | drivers/input/keyboard/opencores-kbd.c | 72 |
1 files changed, 17 insertions, 55 deletions
diff --git a/drivers/input/keyboard/opencores-kbd.c b/drivers/input/keyboard/opencores-kbd.c index 7b9b44158ad1..62abe2c16670 100644 --- a/drivers/input/keyboard/opencores-kbd.c +++ b/drivers/input/keyboard/opencores-kbd.c | |||
@@ -18,7 +18,6 @@ | |||
18 | 18 | ||
19 | struct opencores_kbd { | 19 | struct opencores_kbd { |
20 | struct input_dev *input; | 20 | struct input_dev *input; |
21 | struct resource *addr_res; | ||
22 | void __iomem *addr; | 21 | void __iomem *addr; |
23 | int irq; | 22 | int irq; |
24 | unsigned short keycodes[128]; | 23 | unsigned short keycodes[128]; |
@@ -56,35 +55,25 @@ static int opencores_kbd_probe(struct platform_device *pdev) | |||
56 | return -EINVAL; | 55 | return -EINVAL; |
57 | } | 56 | } |
58 | 57 | ||
59 | opencores_kbd = kzalloc(sizeof(*opencores_kbd), GFP_KERNEL); | 58 | opencores_kbd = devm_kzalloc(&pdev->dev, sizeof(*opencores_kbd), |
60 | input = input_allocate_device(); | 59 | GFP_KERNEL); |
61 | if (!opencores_kbd || !input) { | 60 | if (!opencores_kbd) |
62 | dev_err(&pdev->dev, "failed to allocate device structures\n"); | 61 | return -ENOMEM; |
63 | error = -ENOMEM; | ||
64 | goto err_free_mem; | ||
65 | } | ||
66 | |||
67 | opencores_kbd->addr_res = res; | ||
68 | res = request_mem_region(res->start, resource_size(res), pdev->name); | ||
69 | if (!res) { | ||
70 | dev_err(&pdev->dev, "failed to request I/O memory\n"); | ||
71 | error = -EBUSY; | ||
72 | goto err_free_mem; | ||
73 | } | ||
74 | 62 | ||
75 | opencores_kbd->addr = ioremap(res->start, resource_size(res)); | 63 | input = devm_input_allocate_device(&pdev->dev); |
76 | if (!opencores_kbd->addr) { | 64 | if (!input) { |
77 | dev_err(&pdev->dev, "failed to remap I/O memory\n"); | 65 | dev_err(&pdev->dev, "failed to allocate input device\n"); |
78 | error = -ENXIO; | 66 | return -ENOMEM; |
79 | goto err_rel_mem; | ||
80 | } | 67 | } |
81 | 68 | ||
82 | opencores_kbd->input = input; | 69 | opencores_kbd->input = input; |
83 | opencores_kbd->irq = irq; | 70 | |
71 | opencores_kbd->addr = devm_ioremap_resource(&pdev->dev, res); | ||
72 | if (IS_ERR(opencores_kbd->addr)) | ||
73 | error = PTR_ERR(opencores_kbd->addr); | ||
84 | 74 | ||
85 | input->name = pdev->name; | 75 | input->name = pdev->name; |
86 | input->phys = "opencores-kbd/input0"; | 76 | input->phys = "opencores-kbd/input0"; |
87 | input->dev.parent = &pdev->dev; | ||
88 | 77 | ||
89 | input_set_drvdata(input, opencores_kbd); | 78 | input_set_drvdata(input, opencores_kbd); |
90 | 79 | ||
@@ -109,54 +98,27 @@ static int opencores_kbd_probe(struct platform_device *pdev) | |||
109 | } | 98 | } |
110 | __clear_bit(KEY_RESERVED, input->keybit); | 99 | __clear_bit(KEY_RESERVED, input->keybit); |
111 | 100 | ||
112 | error = request_irq(irq, &opencores_kbd_isr, | 101 | error = devm_request_irq(&pdev->dev, irq, &opencores_kbd_isr, |
113 | IRQF_TRIGGER_RISING, pdev->name, opencores_kbd); | 102 | IRQF_TRIGGER_RISING, |
103 | pdev->name, opencores_kbd); | ||
114 | if (error) { | 104 | if (error) { |
115 | dev_err(&pdev->dev, "unable to claim irq %d\n", irq); | 105 | dev_err(&pdev->dev, "unable to claim irq %d\n", irq); |
116 | goto err_unmap_mem; | 106 | return error; |
117 | } | 107 | } |
118 | 108 | ||
119 | error = input_register_device(input); | 109 | error = input_register_device(input); |
120 | if (error) { | 110 | if (error) { |
121 | dev_err(&pdev->dev, "unable to register input device\n"); | 111 | dev_err(&pdev->dev, "unable to register input device\n"); |
122 | goto err_free_irq; | 112 | return error; |
123 | } | 113 | } |
124 | 114 | ||
125 | platform_set_drvdata(pdev, opencores_kbd); | 115 | platform_set_drvdata(pdev, opencores_kbd); |
126 | 116 | ||
127 | return 0; | 117 | return 0; |
128 | |||
129 | err_free_irq: | ||
130 | free_irq(irq, opencores_kbd); | ||
131 | err_unmap_mem: | ||
132 | iounmap(opencores_kbd->addr); | ||
133 | err_rel_mem: | ||
134 | release_mem_region(res->start, resource_size(res)); | ||
135 | err_free_mem: | ||
136 | input_free_device(input); | ||
137 | kfree(opencores_kbd); | ||
138 | |||
139 | return error; | ||
140 | } | ||
141 | |||
142 | static int opencores_kbd_remove(struct platform_device *pdev) | ||
143 | { | ||
144 | struct opencores_kbd *opencores_kbd = platform_get_drvdata(pdev); | ||
145 | |||
146 | free_irq(opencores_kbd->irq, opencores_kbd); | ||
147 | |||
148 | iounmap(opencores_kbd->addr); | ||
149 | release_mem_region(opencores_kbd->addr_res->start, | ||
150 | resource_size(opencores_kbd->addr_res)); | ||
151 | input_unregister_device(opencores_kbd->input); | ||
152 | kfree(opencores_kbd); | ||
153 | |||
154 | return 0; | ||
155 | } | 118 | } |
156 | 119 | ||
157 | static struct platform_driver opencores_kbd_device_driver = { | 120 | static struct platform_driver opencores_kbd_device_driver = { |
158 | .probe = opencores_kbd_probe, | 121 | .probe = opencores_kbd_probe, |
159 | .remove = opencores_kbd_remove, | ||
160 | .driver = { | 122 | .driver = { |
161 | .name = "opencores-kbd", | 123 | .name = "opencores-kbd", |
162 | }, | 124 | }, |