Commit 7c1d69ee authored by Julia Lawall's avatar Julia Lawall Committed by Linus Torvalds

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: default avatarJulia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 1735be4b
...@@ -89,7 +89,6 @@ enum ds1511reg { ...@@ -89,7 +89,6 @@ enum ds1511reg {
struct rtc_plat_data { struct rtc_plat_data {
struct rtc_device *rtc; struct rtc_device *rtc;
void __iomem *ioaddr; /* virtual base address */ void __iomem *ioaddr; /* virtual base address */
int size; /* amount of memory mapped */
int irq; int irq;
unsigned int irqen; unsigned int irqen;
int alrm_sec; int alrm_sec;
...@@ -479,20 +478,14 @@ static int ds1511_rtc_probe(struct platform_device *pdev) ...@@ -479,20 +478,14 @@ static int ds1511_rtc_probe(struct platform_device *pdev)
struct rtc_plat_data *pdata; struct rtc_plat_data *pdata;
int ret = 0; int ret = 0;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res)
return -ENODEV;
pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
if (!pdata) if (!pdata)
return -ENOMEM; return -ENOMEM;
pdata->size = resource_size(res);
if (!devm_request_mem_region(&pdev->dev, res->start, pdata->size, res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
pdev->name)) ds1511_base = devm_ioremap_resource(&pdev->dev, res);
return -EBUSY; if (IS_ERR(ds1511_base))
ds1511_base = devm_ioremap(&pdev->dev, res->start, pdata->size); return PTR_ERR(ds1511_base);
if (!ds1511_base)
return -ENOMEM;
pdata->ioaddr = ds1511_base; pdata->ioaddr = ds1511_base;
pdata->irq = platform_get_irq(pdev, 0); pdata->irq = platform_get_irq(pdev, 0);
......
...@@ -285,19 +285,14 @@ static int ds1553_rtc_probe(struct platform_device *pdev) ...@@ -285,19 +285,14 @@ static int ds1553_rtc_probe(struct platform_device *pdev)
void __iomem *ioaddr; void __iomem *ioaddr;
int ret = 0; int ret = 0;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res)
return -ENODEV;
pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
if (!pdata) if (!pdata)
return -ENOMEM; return -ENOMEM;
if (!devm_request_mem_region(&pdev->dev, res->start, RTC_REG_SIZE,
pdev->name))
return -EBUSY;
ioaddr = devm_ioremap(&pdev->dev, res->start, RTC_REG_SIZE); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!ioaddr) ioaddr = devm_ioremap_resource(&pdev->dev, res);
return -ENOMEM; if (IS_ERR(ioaddr))
return PTR_ERR(ioaddr);
pdata->ioaddr = ioaddr; pdata->ioaddr = ioaddr;
pdata->irq = platform_get_irq(pdev, 0); pdata->irq = platform_get_irq(pdev, 0);
......
...@@ -138,17 +138,9 @@ static int ep93xx_rtc_probe(struct platform_device *pdev) ...@@ -138,17 +138,9 @@ static int ep93xx_rtc_probe(struct platform_device *pdev)
return -ENOMEM; return -ENOMEM;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) ep93xx_rtc->mmio_base = devm_ioremap_resource(&pdev->dev, res);
return -ENXIO; if (IS_ERR(ep93xx_rtc->mmio_base))
return PTR_ERR(ep93xx_rtc->mmio_base);
if (!devm_request_mem_region(&pdev->dev, res->start,
resource_size(res), pdev->name))
return -EBUSY;
ep93xx_rtc->mmio_base = devm_ioremap(&pdev->dev, res->start,
resource_size(res));
if (!ep93xx_rtc->mmio_base)
return -ENXIO;
pdev->dev.platform_data = ep93xx_rtc; pdev->dev.platform_data = ep93xx_rtc;
platform_set_drvdata(pdev, ep93xx_rtc); platform_set_drvdata(pdev, ep93xx_rtc);
......
...@@ -375,24 +375,16 @@ static int __init dryice_rtc_probe(struct platform_device *pdev) ...@@ -375,24 +375,16 @@ static int __init dryice_rtc_probe(struct platform_device *pdev)
struct imxdi_dev *imxdi; struct imxdi_dev *imxdi;
int rc; int rc;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res)
return -ENODEV;
imxdi = devm_kzalloc(&pdev->dev, sizeof(*imxdi), GFP_KERNEL); imxdi = devm_kzalloc(&pdev->dev, sizeof(*imxdi), GFP_KERNEL);
if (!imxdi) if (!imxdi)
return -ENOMEM; return -ENOMEM;
imxdi->pdev = pdev; imxdi->pdev = pdev;
if (!devm_request_mem_region(&pdev->dev, res->start, resource_size(res), res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
pdev->name)) imxdi->ioaddr = devm_ioremap_resource(&pdev->dev, res);
return -EBUSY; if (IS_ERR(imxdi->ioaddr))
return PTR_ERR(imxdi->ioaddr);
imxdi->ioaddr = devm_ioremap(&pdev->dev, res->start,
resource_size(res));
if (imxdi->ioaddr == NULL)
return -ENOMEM;
spin_lock_init(&imxdi->irq_lock); spin_lock_init(&imxdi->irq_lock);
......
...@@ -201,16 +201,9 @@ static int lpc32xx_rtc_probe(struct platform_device *pdev) ...@@ -201,16 +201,9 @@ static int lpc32xx_rtc_probe(struct platform_device *pdev)
{ {
struct resource *res; struct resource *res;
struct lpc32xx_rtc *rtc; struct lpc32xx_rtc *rtc;
resource_size_t size;
int rtcirq; int rtcirq;
u32 tmp; u32 tmp;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) {
dev_err(&pdev->dev, "Can't get memory resource\n");
return -ENOENT;
}
rtcirq = platform_get_irq(pdev, 0); rtcirq = platform_get_irq(pdev, 0);
if (rtcirq < 0 || rtcirq >= NR_IRQS) { if (rtcirq < 0 || rtcirq >= NR_IRQS) {
dev_warn(&pdev->dev, "Can't get interrupt resource\n"); dev_warn(&pdev->dev, "Can't get interrupt resource\n");
...@@ -224,19 +217,10 @@ static int lpc32xx_rtc_probe(struct platform_device *pdev) ...@@ -224,19 +217,10 @@ static int lpc32xx_rtc_probe(struct platform_device *pdev)
} }
rtc->irq = rtcirq; rtc->irq = rtcirq;
size = resource_size(res); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
rtc->rtc_base = devm_ioremap_resource(&pdev->dev, res);
if (!devm_request_mem_region(&pdev->dev, res->start, size, if (IS_ERR(rtc->rtc_base))
pdev->name)) { return PTR_ERR(rtc->rtc_base);
dev_err(&pdev->dev, "RTC registers are not free\n");
return -EBUSY;
}
rtc->rtc_base = devm_ioremap(&pdev->dev, res->start, size);
if (!rtc->rtc_base) {
dev_err(&pdev->dev, "Can't map memory\n");
return -ENOMEM;
}
spin_lock_init(&rtc->lock); spin_lock_init(&rtc->lock);
......
...@@ -221,26 +221,17 @@ static int __init mv_rtc_probe(struct platform_device *pdev) ...@@ -221,26 +221,17 @@ static int __init mv_rtc_probe(struct platform_device *pdev)
{ {
struct resource *res; struct resource *res;
struct rtc_plat_data *pdata; struct rtc_plat_data *pdata;
resource_size_t size;
u32 rtc_time; u32 rtc_time;
int ret = 0; int ret = 0;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res)
return -ENODEV;
pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
if (!pdata) if (!pdata)
return -ENOMEM; return -ENOMEM;
size = resource_size(res); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!devm_request_mem_region(&pdev->dev, res->start, size, pdata->ioaddr = devm_ioremap_resource(&pdev->dev, res);
pdev->name)) if (IS_ERR(pdata->ioaddr))
return -EBUSY; return PTR_ERR(pdata->ioaddr);
pdata->ioaddr = devm_ioremap(&pdev->dev, res->start, size);
if (!pdata->ioaddr)
return -ENOMEM;
pdata->clk = devm_clk_get(&pdev->dev, NULL); pdata->clk = devm_clk_get(&pdev->dev, NULL);
/* Not all SoCs require a clock.*/ /* Not all SoCs require a clock.*/
......
...@@ -377,22 +377,16 @@ static int mxc_rtc_probe(struct platform_device *pdev) ...@@ -377,22 +377,16 @@ static int mxc_rtc_probe(struct platform_device *pdev)
unsigned long rate; unsigned long rate;
int ret; int ret;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res)
return -ENODEV;
pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
if (!pdata) if (!pdata)
return -ENOMEM; return -ENOMEM;
pdata->devtype = pdev->id_entry->driver_data; pdata->devtype = pdev->id_entry->driver_data;
if (!devm_request_mem_region(&pdev->dev, res->start, res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
resource_size(res), pdev->name)) pdata->ioaddr = devm_ioremap_resource(&pdev->dev, res);
return -EBUSY; if (IS_ERR(pdata->ioaddr))
return PTR_ERR(pdata->ioaddr);
pdata->ioaddr = devm_ioremap(&pdev->dev, res->start,
resource_size(res));
pdata->clk = devm_clk_get(&pdev->dev, NULL); pdata->clk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(pdata->clk)) { if (IS_ERR(pdata->clk)) {
......
...@@ -294,19 +294,14 @@ static int stk17ta8_rtc_probe(struct platform_device *pdev) ...@@ -294,19 +294,14 @@ static int stk17ta8_rtc_probe(struct platform_device *pdev)
void __iomem *ioaddr; void __iomem *ioaddr;
int ret = 0; int ret = 0;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res)
return -ENODEV;
pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
if (!pdata) if (!pdata)
return -ENOMEM; return -ENOMEM;
if (!devm_request_mem_region(&pdev->dev, res->start, RTC_REG_SIZE,
pdev->name)) res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
return -EBUSY; ioaddr = devm_ioremap_resource(&pdev->dev, res);
ioaddr = devm_ioremap(&pdev->dev, res->start, RTC_REG_SIZE); if (IS_ERR(ioaddr))
if (!ioaddr) return PTR_ERR(ioaddr);
return -ENOMEM;
pdata->ioaddr = ioaddr; pdata->ioaddr = ioaddr;
pdata->irq = platform_get_irq(pdev, 0); pdata->irq = platform_get_irq(pdev, 0);
......
...@@ -244,9 +244,6 @@ static int __init tx4939_rtc_probe(struct platform_device *pdev) ...@@ -244,9 +244,6 @@ static int __init tx4939_rtc_probe(struct platform_device *pdev)
struct resource *res; struct resource *res;
int irq, ret; int irq, ret;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res)
return -ENODEV;
irq = platform_get_irq(pdev, 0); irq = platform_get_irq(pdev, 0);
if (irq < 0) if (irq < 0)
return -ENODEV; return -ENODEV;
...@@ -255,13 +252,10 @@ static int __init tx4939_rtc_probe(struct platform_device *pdev) ...@@ -255,13 +252,10 @@ static int __init tx4939_rtc_probe(struct platform_device *pdev)
return -ENOMEM; return -ENOMEM;
platform_set_drvdata(pdev, pdata); platform_set_drvdata(pdev, pdata);
if (!devm_request_mem_region(&pdev->dev, res->start, res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
resource_size(res), pdev->name)) pdata->rtcreg = devm_ioremap_resource(&pdev->dev, res);
return -EBUSY; if (IS_ERR(pdata->rtcreg))
pdata->rtcreg = devm_ioremap(&pdev->dev, res->start, return PTR_ERR(pdata->rtcreg);
resource_size(res));
if (!pdata->rtcreg)
return -EBUSY;
spin_lock_init(&pdata->lock); spin_lock_init(&pdata->lock);
tx4939_rtc_cmd(pdata->rtcreg, TX4939_RTCCTL_COMMAND_NOP); tx4939_rtc_cmd(pdata->rtcreg, TX4939_RTCCTL_COMMAND_NOP);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment