diff options
author | Linus Walleij <linus.walleij@linaro.org> | 2012-07-30 17:41:32 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-07-30 20:25:17 -0400 |
commit | 36ac1d24f1488c32b85a1718a4edfda615b2ef77 (patch) | |
tree | b66db67306aaa9d8e154e7d2c04f03712a880251 /drivers/rtc | |
parent | 8384dfeb759acac48ea24b81f134cac3cbb3e6fc (diff) |
drivers/rtc/rtc-coh901331.c: use devm allocation
Allocate memory, region, remap and irq for device state using devm_*
helpers to simplify memory accounting.
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/rtc')
-rw-r--r-- | drivers/rtc/rtc-coh901331.c | 50 |
1 files changed, 15 insertions, 35 deletions
diff --git a/drivers/rtc/rtc-coh901331.c b/drivers/rtc/rtc-coh901331.c index 58665029d6f3..76b2156d3c62 100644 --- a/drivers/rtc/rtc-coh901331.c +++ b/drivers/rtc/rtc-coh901331.c | |||
@@ -155,14 +155,10 @@ static int __exit coh901331_remove(struct platform_device *pdev) | |||
155 | struct coh901331_port *rtap = dev_get_drvdata(&pdev->dev); | 155 | struct coh901331_port *rtap = dev_get_drvdata(&pdev->dev); |
156 | 156 | ||
157 | if (rtap) { | 157 | if (rtap) { |
158 | free_irq(rtap->irq, rtap); | ||
159 | rtc_device_unregister(rtap->rtc); | 158 | rtc_device_unregister(rtap->rtc); |
160 | clk_unprepare(rtap->clk); | 159 | clk_unprepare(rtap->clk); |
161 | clk_put(rtap->clk); | 160 | clk_put(rtap->clk); |
162 | iounmap(rtap->virtbase); | ||
163 | release_mem_region(rtap->phybase, rtap->physize); | ||
164 | platform_set_drvdata(pdev, NULL); | 161 | platform_set_drvdata(pdev, NULL); |
165 | kfree(rtap); | ||
166 | } | 162 | } |
167 | 163 | ||
168 | return 0; | 164 | return 0; |
@@ -175,42 +171,36 @@ static int __init coh901331_probe(struct platform_device *pdev) | |||
175 | struct coh901331_port *rtap; | 171 | struct coh901331_port *rtap; |
176 | struct resource *res; | 172 | struct resource *res; |
177 | 173 | ||
178 | rtap = kzalloc(sizeof(struct coh901331_port), GFP_KERNEL); | 174 | rtap = devm_kzalloc(&pdev->dev, |
175 | sizeof(struct coh901331_port), GFP_KERNEL); | ||
179 | if (!rtap) | 176 | if (!rtap) |
180 | return -ENOMEM; | 177 | return -ENOMEM; |
181 | 178 | ||
182 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 179 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
183 | if (!res) { | 180 | if (!res) |
184 | ret = -ENOENT; | 181 | return -ENOENT; |
185 | goto out_no_resource; | 182 | |
186 | } | ||
187 | rtap->phybase = res->start; | 183 | rtap->phybase = res->start; |
188 | rtap->physize = resource_size(res); | 184 | rtap->physize = resource_size(res); |
189 | 185 | ||
190 | if (request_mem_region(rtap->phybase, rtap->physize, | 186 | if (devm_request_mem_region(&pdev->dev, rtap->phybase, rtap->physize, |
191 | "rtc-coh901331") == NULL) { | 187 | "rtc-coh901331") == NULL) |
192 | ret = -EBUSY; | 188 | return -EBUSY; |
193 | goto out_no_memregion; | ||
194 | } | ||
195 | 189 | ||
196 | rtap->virtbase = ioremap(rtap->phybase, rtap->physize); | 190 | rtap->virtbase = devm_ioremap(&pdev->dev, rtap->phybase, rtap->physize); |
197 | if (!rtap->virtbase) { | 191 | if (!rtap->virtbase) |
198 | ret = -ENOMEM; | 192 | return -ENOMEM; |
199 | goto out_no_remap; | ||
200 | } | ||
201 | 193 | ||
202 | rtap->irq = platform_get_irq(pdev, 0); | 194 | rtap->irq = platform_get_irq(pdev, 0); |
203 | if (request_irq(rtap->irq, coh901331_interrupt, 0, | 195 | if (devm_request_irq(&pdev->dev, rtap->irq, coh901331_interrupt, 0, |
204 | "RTC COH 901 331 Alarm", rtap)) { | 196 | "RTC COH 901 331 Alarm", rtap)) |
205 | ret = -EIO; | 197 | return -EIO; |
206 | goto out_no_irq; | ||
207 | } | ||
208 | 198 | ||
209 | rtap->clk = clk_get(&pdev->dev, NULL); | 199 | rtap->clk = clk_get(&pdev->dev, NULL); |
210 | if (IS_ERR(rtap->clk)) { | 200 | if (IS_ERR(rtap->clk)) { |
211 | ret = PTR_ERR(rtap->clk); | 201 | ret = PTR_ERR(rtap->clk); |
212 | dev_err(&pdev->dev, "could not get clock\n"); | 202 | dev_err(&pdev->dev, "could not get clock\n"); |
213 | goto out_no_clk; | 203 | return ret; |
214 | } | 204 | } |
215 | 205 | ||
216 | /* We enable/disable the clock only to assure it works */ | 206 | /* We enable/disable the clock only to assure it works */ |
@@ -236,16 +226,6 @@ static int __init coh901331_probe(struct platform_device *pdev) | |||
236 | clk_unprepare(rtap->clk); | 226 | clk_unprepare(rtap->clk); |
237 | out_no_clk_prepenable: | 227 | out_no_clk_prepenable: |
238 | clk_put(rtap->clk); | 228 | clk_put(rtap->clk); |
239 | out_no_clk: | ||
240 | free_irq(rtap->irq, rtap); | ||
241 | out_no_irq: | ||
242 | iounmap(rtap->virtbase); | ||
243 | out_no_remap: | ||
244 | platform_set_drvdata(pdev, NULL); | ||
245 | out_no_memregion: | ||
246 | release_mem_region(rtap->phybase, SZ_4K); | ||
247 | out_no_resource: | ||
248 | kfree(rtap); | ||
249 | return ret; | 229 | return ret; |
250 | } | 230 | } |
251 | 231 | ||