Commit 7c1d69ee11b8986c40a53d8e2238204fc86f5b33

Authored by Julia Lawall
Committed by Linus Torvalds
1 parent 1735be4b82

rtc: simplify devm_request_mem_region/devm_ioremap

Convert the composition of devm_request_mem_region and devm_ioremap to a
single call to devm_ioremap_resource.  The associated call to
platform_get_resource is also simplified and moved next to the new call
to devm_ioremap_resource.

This was done using a combination of the semantic patches
devm_ioremap_resource.cocci and devm_request_and_ioremap.cocci, found in
the scripts/coccinelle/api directory.

In rtc-lpc32xx.c and rtc-mv.c, the local variable size is no longer needed.

In rtc-ds1511.c the size field of the local structure is not useful any
more, and is deleted.

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 9 changed files with 37 additions and 107 deletions Side-by-side Diff

drivers/rtc/rtc-ds1511.c
... ... @@ -89,7 +89,6 @@
89 89 struct rtc_plat_data {
90 90 struct rtc_device *rtc;
91 91 void __iomem *ioaddr; /* virtual base address */
92   - int size; /* amount of memory mapped */
93 92 int irq;
94 93 unsigned int irqen;
95 94 int alrm_sec;
96 95  
... ... @@ -479,20 +478,14 @@
479 478 struct rtc_plat_data *pdata;
480 479 int ret = 0;
481 480  
482   - res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
483   - if (!res)
484   - return -ENODEV;
485   -
486 481 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
487 482 if (!pdata)
488 483 return -ENOMEM;
489   - pdata->size = resource_size(res);
490   - if (!devm_request_mem_region(&pdev->dev, res->start, pdata->size,
491   - pdev->name))
492   - return -EBUSY;
493   - ds1511_base = devm_ioremap(&pdev->dev, res->start, pdata->size);
494   - if (!ds1511_base)
495   - return -ENOMEM;
  484 +
  485 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  486 + ds1511_base = devm_ioremap_resource(&pdev->dev, res);
  487 + if (IS_ERR(ds1511_base))
  488 + return PTR_ERR(ds1511_base);
496 489 pdata->ioaddr = ds1511_base;
497 490 pdata->irq = platform_get_irq(pdev, 0);
498 491  
drivers/rtc/rtc-ds1553.c
... ... @@ -285,19 +285,14 @@
285 285 void __iomem *ioaddr;
286 286 int ret = 0;
287 287  
288   - res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
289   - if (!res)
290   - return -ENODEV;
291 288 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
292 289 if (!pdata)
293 290 return -ENOMEM;
294   - if (!devm_request_mem_region(&pdev->dev, res->start, RTC_REG_SIZE,
295   - pdev->name))
296   - return -EBUSY;
297 291  
298   - ioaddr = devm_ioremap(&pdev->dev, res->start, RTC_REG_SIZE);
299   - if (!ioaddr)
300   - return -ENOMEM;
  292 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  293 + ioaddr = devm_ioremap_resource(&pdev->dev, res);
  294 + if (IS_ERR(ioaddr))
  295 + return PTR_ERR(ioaddr);
301 296 pdata->ioaddr = ioaddr;
302 297 pdata->irq = platform_get_irq(pdev, 0);
303 298  
drivers/rtc/rtc-ep93xx.c
... ... @@ -138,17 +138,9 @@
138 138 return -ENOMEM;
139 139  
140 140 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
141   - if (!res)
142   - return -ENXIO;
143   -
144   - if (!devm_request_mem_region(&pdev->dev, res->start,
145   - resource_size(res), pdev->name))
146   - return -EBUSY;
147   -
148   - ep93xx_rtc->mmio_base = devm_ioremap(&pdev->dev, res->start,
149   - resource_size(res));
150   - if (!ep93xx_rtc->mmio_base)
151   - return -ENXIO;
  141 + ep93xx_rtc->mmio_base = devm_ioremap_resource(&pdev->dev, res);
  142 + if (IS_ERR(ep93xx_rtc->mmio_base))
  143 + return PTR_ERR(ep93xx_rtc->mmio_base);
152 144  
153 145 pdev->dev.platform_data = ep93xx_rtc;
154 146 platform_set_drvdata(pdev, ep93xx_rtc);
drivers/rtc/rtc-imxdi.c
... ... @@ -375,24 +375,16 @@
375 375 struct imxdi_dev *imxdi;
376 376 int rc;
377 377  
378   - res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
379   - if (!res)
380   - return -ENODEV;
381   -
382 378 imxdi = devm_kzalloc(&pdev->dev, sizeof(*imxdi), GFP_KERNEL);
383 379 if (!imxdi)
384 380 return -ENOMEM;
385 381  
386 382 imxdi->pdev = pdev;
387 383  
388   - if (!devm_request_mem_region(&pdev->dev, res->start, resource_size(res),
389   - pdev->name))
390   - return -EBUSY;
391   -
392   - imxdi->ioaddr = devm_ioremap(&pdev->dev, res->start,
393   - resource_size(res));
394   - if (imxdi->ioaddr == NULL)
395   - return -ENOMEM;
  384 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  385 + imxdi->ioaddr = devm_ioremap_resource(&pdev->dev, res);
  386 + if (IS_ERR(imxdi->ioaddr))
  387 + return PTR_ERR(imxdi->ioaddr);
396 388  
397 389 spin_lock_init(&imxdi->irq_lock);
398 390  
drivers/rtc/rtc-lpc32xx.c
... ... @@ -201,16 +201,9 @@
201 201 {
202 202 struct resource *res;
203 203 struct lpc32xx_rtc *rtc;
204   - resource_size_t size;
205 204 int rtcirq;
206 205 u32 tmp;
207 206  
208   - res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
209   - if (!res) {
210   - dev_err(&pdev->dev, "Can't get memory resource\n");
211   - return -ENOENT;
212   - }
213   -
214 207 rtcirq = platform_get_irq(pdev, 0);
215 208 if (rtcirq < 0 || rtcirq >= NR_IRQS) {
216 209 dev_warn(&pdev->dev, "Can't get interrupt resource\n");
... ... @@ -224,19 +217,10 @@
224 217 }
225 218 rtc->irq = rtcirq;
226 219  
227   - size = resource_size(res);
228   -
229   - if (!devm_request_mem_region(&pdev->dev, res->start, size,
230   - pdev->name)) {
231   - dev_err(&pdev->dev, "RTC registers are not free\n");
232   - return -EBUSY;
233   - }
234   -
235   - rtc->rtc_base = devm_ioremap(&pdev->dev, res->start, size);
236   - if (!rtc->rtc_base) {
237   - dev_err(&pdev->dev, "Can't map memory\n");
238   - return -ENOMEM;
239   - }
  220 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  221 + rtc->rtc_base = devm_ioremap_resource(&pdev->dev, res);
  222 + if (IS_ERR(rtc->rtc_base))
  223 + return PTR_ERR(rtc->rtc_base);
240 224  
241 225 spin_lock_init(&rtc->lock);
242 226  
drivers/rtc/rtc-mv.c
... ... @@ -221,26 +221,17 @@
221 221 {
222 222 struct resource *res;
223 223 struct rtc_plat_data *pdata;
224   - resource_size_t size;
225 224 u32 rtc_time;
226 225 int ret = 0;
227 226  
228   - res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
229   - if (!res)
230   - return -ENODEV;
231   -
232 227 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
233 228 if (!pdata)
234 229 return -ENOMEM;
235 230  
236   - size = resource_size(res);
237   - if (!devm_request_mem_region(&pdev->dev, res->start, size,
238   - pdev->name))
239   - return -EBUSY;
240   -
241   - pdata->ioaddr = devm_ioremap(&pdev->dev, res->start, size);
242   - if (!pdata->ioaddr)
243   - return -ENOMEM;
  231 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  232 + pdata->ioaddr = devm_ioremap_resource(&pdev->dev, res);
  233 + if (IS_ERR(pdata->ioaddr))
  234 + return PTR_ERR(pdata->ioaddr);
244 235  
245 236 pdata->clk = devm_clk_get(&pdev->dev, NULL);
246 237 /* Not all SoCs require a clock.*/
drivers/rtc/rtc-mxc.c
... ... @@ -377,22 +377,16 @@
377 377 unsigned long rate;
378 378 int ret;
379 379  
380   - res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
381   - if (!res)
382   - return -ENODEV;
383   -
384 380 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
385 381 if (!pdata)
386 382 return -ENOMEM;
387 383  
388 384 pdata->devtype = pdev->id_entry->driver_data;
389 385  
390   - if (!devm_request_mem_region(&pdev->dev, res->start,
391   - resource_size(res), pdev->name))
392   - return -EBUSY;
393   -
394   - pdata->ioaddr = devm_ioremap(&pdev->dev, res->start,
395   - resource_size(res));
  386 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  387 + pdata->ioaddr = devm_ioremap_resource(&pdev->dev, res);
  388 + if (IS_ERR(pdata->ioaddr))
  389 + return PTR_ERR(pdata->ioaddr);
396 390  
397 391 pdata->clk = devm_clk_get(&pdev->dev, NULL);
398 392 if (IS_ERR(pdata->clk)) {
drivers/rtc/rtc-stk17ta8.c
... ... @@ -294,19 +294,14 @@
294 294 void __iomem *ioaddr;
295 295 int ret = 0;
296 296  
297   - res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
298   - if (!res)
299   - return -ENODEV;
300   -
301 297 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
302 298 if (!pdata)
303 299 return -ENOMEM;
304   - if (!devm_request_mem_region(&pdev->dev, res->start, RTC_REG_SIZE,
305   - pdev->name))
306   - return -EBUSY;
307   - ioaddr = devm_ioremap(&pdev->dev, res->start, RTC_REG_SIZE);
308   - if (!ioaddr)
309   - return -ENOMEM;
  300 +
  301 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  302 + ioaddr = devm_ioremap_resource(&pdev->dev, res);
  303 + if (IS_ERR(ioaddr))
  304 + return PTR_ERR(ioaddr);
310 305 pdata->ioaddr = ioaddr;
311 306 pdata->irq = platform_get_irq(pdev, 0);
312 307  
drivers/rtc/rtc-tx4939.c
... ... @@ -244,9 +244,6 @@
244 244 struct resource *res;
245 245 int irq, ret;
246 246  
247   - res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
248   - if (!res)
249   - return -ENODEV;
250 247 irq = platform_get_irq(pdev, 0);
251 248 if (irq < 0)
252 249 return -ENODEV;
... ... @@ -255,13 +252,10 @@
255 252 return -ENOMEM;
256 253 platform_set_drvdata(pdev, pdata);
257 254  
258   - if (!devm_request_mem_region(&pdev->dev, res->start,
259   - resource_size(res), pdev->name))
260   - return -EBUSY;
261   - pdata->rtcreg = devm_ioremap(&pdev->dev, res->start,
262   - resource_size(res));
263   - if (!pdata->rtcreg)
264   - return -EBUSY;
  255 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  256 + pdata->rtcreg = devm_ioremap_resource(&pdev->dev, res);
  257 + if (IS_ERR(pdata->rtcreg))
  258 + return PTR_ERR(pdata->rtcreg);
265 259  
266 260 spin_lock_init(&pdata->lock);
267 261 tx4939_rtc_cmd(pdata->rtcreg, TX4939_RTCCTL_COMMAND_NOP);