ste_dma40: Rename jump labels in d40_dmaengine_init()
[cascardo/linux.git] / drivers / dma / ste_dma40.c
index 8b18e44..4b89a35 100644 (file)
@@ -2891,7 +2891,7 @@ static int __init d40_dmaengine_init(struct d40_base *base,
 
        if (err) {
                d40_err(base->dev, "Failed to register slave channels\n");
-               goto failure1;
+               goto exit;
        }
 
        d40_chan_init(base, &base->dma_memcpy, base->log_chans,
@@ -2908,7 +2908,7 @@ static int __init d40_dmaengine_init(struct d40_base *base,
        if (err) {
                d40_err(base->dev,
                        "Failed to register memcpy only channels\n");
-               goto failure2;
+               goto unregister_slave;
        }
 
        d40_chan_init(base, &base->dma_both, base->phy_chans,
@@ -2926,14 +2926,14 @@ static int __init d40_dmaengine_init(struct d40_base *base,
        if (err) {
                d40_err(base->dev,
                        "Failed to register logical and physical capable channels\n");
-               goto failure3;
+               goto unregister_memcpy;
        }
        return 0;
-failure3:
+ unregister_memcpy:
        dma_async_device_unregister(&base->dma_memcpy);
-failure2:
+ unregister_slave:
        dma_async_device_unregister(&base->dma_slave);
-failure1:
+ exit:
        return err;
 }
 
@@ -3144,11 +3144,11 @@ static int __init d40_phy_res_init(struct d40_base *base)
 static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev)
 {
        struct stedma40_platform_data *plat_data = dev_get_platdata(&pdev->dev);
-       struct clk *clk = NULL;
-       void __iomem *virtbase = NULL;
-       struct resource *res = NULL;
-       struct d40_base *base = NULL;
-       int num_log_chans = 0;
+       struct clk *clk;
+       void __iomem *virtbase;
+       struct resource *res;
+       struct d40_base *base;
+       int num_log_chans;
        int num_phy_chans;
        int num_memcpy_chans;
        int clk_ret = -EINVAL;
@@ -3160,27 +3160,27 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev)
        clk = clk_get(&pdev->dev, NULL);
        if (IS_ERR(clk)) {
                d40_err(&pdev->dev, "No matching clock found\n");
-               goto failure;
+               goto check_prepare_enabled;
        }
 
        clk_ret = clk_prepare_enable(clk);
        if (clk_ret) {
                d40_err(&pdev->dev, "Failed to prepare/enable clock\n");
-               goto failure;
+               goto disable_unprepare;
        }
 
        /* Get IO for DMAC base address */
        res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "base");
        if (!res)
-               goto failure;
+               goto disable_unprepare;
 
        if (request_mem_region(res->start, resource_size(res),
                               D40_NAME " I/O base") == NULL)
-               goto failure;
+               goto release_region;
 
        virtbase = ioremap(res->start, resource_size(res));
        if (!virtbase)
-               goto failure;
+               goto release_region;
 
        /* This is just a regular AMBA PrimeCell ID actually */
        for (pid = 0, i = 0; i < 4; i++)
@@ -3192,13 +3192,13 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev)
 
        if (cid != AMBA_CID) {
                d40_err(&pdev->dev, "Unknown hardware! No PrimeCell ID\n");
-               goto failure;
+               goto unmap_io;
        }
        if (AMBA_MANF_BITS(pid) != AMBA_VENDOR_ST) {
                d40_err(&pdev->dev, "Unknown designer! Got %x wanted %x\n",
                        AMBA_MANF_BITS(pid),
                        AMBA_VENDOR_ST);
-               goto failure;
+               goto unmap_io;
        }
        /*
         * HW revision:
@@ -3212,7 +3212,7 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev)
        rev = AMBA_REV_BITS(pid);
        if (rev < 2) {
                d40_err(&pdev->dev, "hardware revision: %d is not supported", rev);
-               goto failure;
+               goto unmap_io;
        }
 
        /* The number of physical channels on this HW */
@@ -3238,7 +3238,7 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev)
                       sizeof(struct d40_chan), GFP_KERNEL);
 
        if (base == NULL)
-               goto failure;
+               goto unmap_io;
 
        base->rev = rev;
        base->clk = clk;
@@ -3283,65 +3283,66 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev)
                base->gen_dmac.init_reg_size = ARRAY_SIZE(dma_init_reg_v4a);
        }
 
-       base->phy_res = kzalloc(num_phy_chans * sizeof(struct d40_phy_res),
+       base->phy_res = kcalloc(num_phy_chans,
+                               sizeof(*base->phy_res),
                                GFP_KERNEL);
        if (!base->phy_res)
-               goto failure;
+               goto free_base;
 
-       base->lookup_phy_chans = kzalloc(num_phy_chans *
-                                        sizeof(struct d40_chan *),
+       base->lookup_phy_chans = kcalloc(num_phy_chans,
+                                        sizeof(*base->lookup_phy_chans),
                                         GFP_KERNEL);
        if (!base->lookup_phy_chans)
-               goto failure;
+               goto free_phy_res;
 
-       base->lookup_log_chans = kzalloc(num_log_chans *
-                                        sizeof(struct d40_chan *),
+       base->lookup_log_chans = kcalloc(num_log_chans,
+                                        sizeof(*base->lookup_log_chans),
                                         GFP_KERNEL);
        if (!base->lookup_log_chans)
-               goto failure;
+               goto free_phy_chans;
 
-       base->reg_val_backup_chan = kmalloc(base->num_phy_chans *
-                                           sizeof(d40_backup_regs_chan),
-                                           GFP_KERNEL);
+       base->reg_val_backup_chan = kmalloc_array(base->num_phy_chans,
+                                                 sizeof(d40_backup_regs_chan),
+                                                 GFP_KERNEL);
        if (!base->reg_val_backup_chan)
-               goto failure;
+               goto free_log_chans;
 
-       base->lcla_pool.alloc_map =
-               kzalloc(num_phy_chans * sizeof(struct d40_desc *)
-                       * D40_LCLA_LINK_PER_EVENT_GRP, GFP_KERNEL);
+       base->lcla_pool.alloc_map = kcalloc(num_phy_chans
+                                           * D40_LCLA_LINK_PER_EVENT_GRP,
+                                           sizeof(*base->lcla_pool.alloc_map),
+                                           GFP_KERNEL);
        if (!base->lcla_pool.alloc_map)
-               goto failure;
+               goto free_backup_chan;
 
        base->desc_slab = kmem_cache_create(D40_NAME, sizeof(struct d40_desc),
                                            0, SLAB_HWCACHE_ALIGN,
                                            NULL);
        if (base->desc_slab == NULL)
-               goto failure;
+               goto free_map;
 
        return base;
-
-failure:
+ free_map:
+       kfree(base->lcla_pool.alloc_map);
+ free_backup_chan:
+       kfree(base->reg_val_backup_chan);
+ free_log_chans:
+       kfree(base->lookup_log_chans);
+ free_phy_chans:
+       kfree(base->lookup_phy_chans);
+ free_phy_res:
+       kfree(base->phy_res);
+ free_base:
+       kfree(base);
+ unmap_io:
+       iounmap(virtbase);
+ release_region:
+       release_mem_region(res->start, resource_size(res));
+ check_prepare_enabled:
        if (!clk_ret)
+ disable_unprepare:
                clk_disable_unprepare(clk);
        if (!IS_ERR(clk))
                clk_put(clk);
-       if (virtbase)
-               iounmap(virtbase);
-       if (res)
-               release_mem_region(res->start,
-                                  resource_size(res));
-       if (virtbase)
-               iounmap(virtbase);
-
-       if (base) {
-               kfree(base->lcla_pool.alloc_map);
-               kfree(base->reg_val_backup_chan);
-               kfree(base->lookup_log_chans);
-               kfree(base->lookup_phy_chans);
-               kfree(base->phy_res);
-               kfree(base);
-       }
-
        return NULL;
 }
 
@@ -3404,20 +3405,18 @@ static int __init d40_lcla_allocate(struct d40_base *base)
        struct d40_lcla_pool *pool = &base->lcla_pool;
        unsigned long *page_list;
        int i, j;
-       int ret = 0;
+       int ret;
 
        /*
         * This is somewhat ugly. We need 8192 bytes that are 18 bit aligned,
         * To full fill this hardware requirement without wasting 256 kb
         * we allocate pages until we get an aligned one.
         */
-       page_list = kmalloc(sizeof(unsigned long) * MAX_LCLA_ALLOC_ATTEMPTS,
-                           GFP_KERNEL);
-
-       if (!page_list) {
-               ret = -ENOMEM;
-               goto failure;
-       }
+       page_list = kmalloc_array(MAX_LCLA_ALLOC_ATTEMPTS,
+                                 sizeof(*page_list),
+                                 GFP_KERNEL);
+       if (!page_list)
+               return -ENOMEM;
 
        /* Calculating how many pages that are required */
        base->lcla_pool.pages = SZ_1K * base->num_phy_chans / PAGE_SIZE;
@@ -3433,7 +3432,7 @@ static int __init d40_lcla_allocate(struct d40_base *base)
 
                        for (j = 0; j < i; j++)
                                free_pages(page_list[j], base->lcla_pool.pages);
-                       goto failure;
+                       goto free_page_list;
                }
 
                if ((virt_to_phys((void *)page_list[i]) &
@@ -3460,7 +3459,7 @@ static int __init d40_lcla_allocate(struct d40_base *base)
                                                         GFP_KERNEL);
                if (!base->lcla_pool.base_unaligned) {
                        ret = -ENOMEM;
-                       goto failure;
+                       goto free_page_list;
                }
 
                base->lcla_pool.base = PTR_ALIGN(base->lcla_pool.base_unaligned,
@@ -3473,12 +3472,13 @@ static int __init d40_lcla_allocate(struct d40_base *base)
        if (dma_mapping_error(base->dev, pool->dma_addr)) {
                pool->dma_addr = 0;
                ret = -ENOMEM;
-               goto failure;
+               goto free_page_list;
        }
 
        writel(virt_to_phys(base->lcla_pool.base),
               base->virtbase + D40_DREG_LCLA);
-failure:
+       ret = 0;
+ free_page_list:
        kfree(page_list);
        return ret;
 }
@@ -3490,9 +3490,7 @@ static int __init d40_of_probe(struct platform_device *pdev,
        int num_phy = 0, num_memcpy = 0, num_disabled = 0;
        const __be32 *list;
 
-       pdata = devm_kzalloc(&pdev->dev,
-                            sizeof(struct stedma40_platform_data),
-                            GFP_KERNEL);
+       pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
        if (!pdata)
                return -ENOMEM;
 
@@ -3574,7 +3572,7 @@ static int __init d40_probe(struct platform_device *pdev)
        if (!res) {
                ret = -ENOENT;
                d40_err(&pdev->dev, "No \"lcpa\" memory resource\n");
-               goto failure;
+               goto destroy_cache;
        }
        base->lcpa_size = resource_size(res);
        base->phy_lcpa = res->start;
@@ -3583,7 +3581,7 @@ static int __init d40_probe(struct platform_device *pdev)
                               D40_NAME " I/O lcpa") == NULL) {
                ret = -EBUSY;
                d40_err(&pdev->dev, "Failed to request LCPA region %pR\n", res);
-               goto failure;
+               goto destroy_cache;
        }
 
        /* We make use of ESRAM memory for this. */
@@ -3599,7 +3597,7 @@ static int __init d40_probe(struct platform_device *pdev)
        if (!base->lcpa_base) {
                ret = -ENOMEM;
                d40_err(&pdev->dev, "Failed to ioremap LCPA region\n");
-               goto failure;
+               goto destroy_cache;
        }
        /* If lcla has to be located in ESRAM we don't need to allocate */
        if (base->plat_data->use_esram_lcla) {
@@ -3609,14 +3607,14 @@ static int __init d40_probe(struct platform_device *pdev)
                        ret = -ENOENT;
                        d40_err(&pdev->dev,
                                "No \"lcla_esram\" memory resource\n");
-                       goto failure;
+                       goto destroy_cache;
                }
                base->lcla_pool.base = ioremap(res->start,
                                                resource_size(res));
                if (!base->lcla_pool.base) {
                        ret = -ENOMEM;
                        d40_err(&pdev->dev, "Failed to ioremap LCLA region\n");
-                       goto failure;
+                       goto destroy_cache;
                }
                writel(res->start, base->virtbase + D40_DREG_LCLA);
 
@@ -3624,7 +3622,7 @@ static int __init d40_probe(struct platform_device *pdev)
                ret = d40_lcla_allocate(base);
                if (ret) {
                        d40_err(&pdev->dev, "Failed to allocate LCLA area\n");
-                       goto failure;
+                       goto destroy_cache;
                }
        }
 
@@ -3635,7 +3633,7 @@ static int __init d40_probe(struct platform_device *pdev)
        ret = request_irq(base->irq, d40_handle_interrupt, 0, D40_NAME, base);
        if (ret) {
                d40_err(&pdev->dev, "No IRQ defined\n");
-               goto failure;
+               goto destroy_cache;
        }
 
        if (base->plat_data->use_esram_lcla) {
@@ -3645,7 +3643,7 @@ static int __init d40_probe(struct platform_device *pdev)
                        d40_err(&pdev->dev, "Failed to get lcpa_regulator\n");
                        ret = PTR_ERR(base->lcpa_regulator);
                        base->lcpa_regulator = NULL;
-                       goto failure;
+                       goto destroy_cache;
                }
 
                ret = regulator_enable(base->lcpa_regulator);
@@ -3654,7 +3652,7 @@ static int __init d40_probe(struct platform_device *pdev)
                                "Failed to enable lcpa_regulator\n");
                        regulator_put(base->lcpa_regulator);
                        base->lcpa_regulator = NULL;
-                       goto failure;
+                       goto destroy_cache;
                }
        }
 
@@ -3669,13 +3667,13 @@ static int __init d40_probe(struct platform_device *pdev)
 
        ret = d40_dmaengine_init(base, num_reserved_chans);
        if (ret)
-               goto failure;
+               goto destroy_cache;
 
        base->dev->dma_parms = &base->dma_parms;
        ret = dma_set_max_seg_size(base->dev, STEDMA40_MAX_SEG_SIZE);
        if (ret) {
                d40_err(&pdev->dev, "Failed to set dma max seg size\n");
-               goto failure;
+               goto destroy_cache;
        }
 
        d40_hw_init(base);
@@ -3689,8 +3687,7 @@ static int __init d40_probe(struct platform_device *pdev)
 
        dev_info(base->dev, "initialized\n");
        return 0;
-
-failure:
+ destroy_cache:
        kmem_cache_destroy(base->desc_slab);
        if (base->virtbase)
                iounmap(base->virtbase);
@@ -3732,7 +3729,7 @@ failure:
        kfree(base->lookup_phy_chans);
        kfree(base->phy_res);
        kfree(base);
-report_failure:
+ report_failure:
        d40_err(&pdev->dev, "probe failed\n");
        return ret;
 }