Skip to content

Commit 2893f6b

Browse files
Linus Walleijvinodkoul
authored andcommitted
dmaengine: ste_dma40: Return error codes properly
This makes the probe() and its subfunction d40_hw_detect_init() return proper error codes. One effect of this is that deferred probe, e.g from the clock, will start to work, would it happen. Also it is better design. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Link: https://lore.kernel.org/r/20230417-ux500-dma40-cleanup-v3-7-60bfa6785968@linaro.org Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent 339f504 commit 2893f6b

1 file changed

Lines changed: 24 additions & 22 deletions

File tree

drivers/dma/ste_dma40.c

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3132,7 +3132,8 @@ static void d40_drop_kmem_cache_action(void *d)
31323132
kmem_cache_destroy(desc_slab);
31333133
}
31343134

3135-
static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev)
3135+
static int __init d40_hw_detect_init(struct platform_device *pdev,
3136+
struct d40_base **retbase)
31363137
{
31373138
struct stedma40_platform_data *plat_data = dev_get_platdata(&pdev->dev);
31383139
struct device *dev = &pdev->dev;
@@ -3150,14 +3151,12 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev)
31503151

31513152
clk = devm_clk_get_enabled(dev, NULL);
31523153
if (IS_ERR(clk))
3153-
return NULL;
3154+
return PTR_ERR(clk);
31543155

31553156
/* Get IO for DMAC base address */
31563157
virtbase = devm_platform_ioremap_resource_byname(pdev, "base");
3157-
if (IS_ERR(virtbase)) {
3158-
dev_err(dev, "No IO base defined\n");
3159-
return NULL;
3160-
}
3158+
if (IS_ERR(virtbase))
3159+
return PTR_ERR(virtbase);
31613160

31623161
/* This is just a regular AMBA PrimeCell ID actually */
31633162
for (pid = 0, i = 0; i < 4; i++)
@@ -3169,13 +3168,13 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev)
31693168

31703169
if (cid != AMBA_CID) {
31713170
d40_err(dev, "Unknown hardware! No PrimeCell ID\n");
3172-
return NULL;
3171+
return -EINVAL;
31733172
}
31743173
if (AMBA_MANF_BITS(pid) != AMBA_VENDOR_ST) {
31753174
d40_err(dev, "Unknown designer! Got %x wanted %x\n",
31763175
AMBA_MANF_BITS(pid),
31773176
AMBA_VENDOR_ST);
3178-
return NULL;
3177+
return -EINVAL;
31793178
}
31803179
/*
31813180
* HW revision:
@@ -3189,7 +3188,7 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev)
31893188
rev = AMBA_REV_BITS(pid);
31903189
if (rev < 2) {
31913190
d40_err(dev, "hardware revision: %d is not supported", rev);
3192-
return NULL;
3191+
return -EINVAL;
31933192
}
31943193

31953194
/* The number of physical channels on this HW */
@@ -3216,7 +3215,7 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev)
32163215
sizeof(struct d40_chan), GFP_KERNEL);
32173216

32183217
if (!base)
3219-
return NULL;
3218+
return -ENOMEM;
32203219

32213220
base->rev = rev;
32223221
base->clk = clk;
@@ -3263,51 +3262,53 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev)
32633262
sizeof(*base->phy_res),
32643263
GFP_KERNEL);
32653264
if (!base->phy_res)
3266-
return NULL;
3265+
return -ENOMEM;
32673266

32683267
base->lookup_phy_chans = devm_kcalloc(dev, num_phy_chans,
32693268
sizeof(*base->lookup_phy_chans),
32703269
GFP_KERNEL);
32713270
if (!base->lookup_phy_chans)
3272-
return NULL;
3271+
return -ENOMEM;
32733272

32743273
base->lookup_log_chans = devm_kcalloc(dev, num_log_chans,
32753274
sizeof(*base->lookup_log_chans),
32763275
GFP_KERNEL);
32773276
if (!base->lookup_log_chans)
3278-
return NULL;
3277+
return -ENOMEM;
32793278

32803279
base->reg_val_backup_chan = devm_kmalloc_array(dev, base->num_phy_chans,
32813280
sizeof(d40_backup_regs_chan),
32823281
GFP_KERNEL);
32833282
if (!base->reg_val_backup_chan)
3284-
return NULL;
3283+
return -ENOMEM;
32853284

32863285
base->lcla_pool.alloc_map = devm_kcalloc(dev, num_phy_chans
32873286
* D40_LCLA_LINK_PER_EVENT_GRP,
32883287
sizeof(*base->lcla_pool.alloc_map),
32893288
GFP_KERNEL);
32903289
if (!base->lcla_pool.alloc_map)
3291-
return NULL;
3290+
return -ENOMEM;
32923291

32933292
base->regs_interrupt = devm_kmalloc_array(dev, base->gen_dmac.il_size,
32943293
sizeof(*base->regs_interrupt),
32953294
GFP_KERNEL);
32963295
if (!base->regs_interrupt)
3297-
return NULL;
3296+
return -ENOMEM;
32983297

32993298
base->desc_slab = kmem_cache_create(D40_NAME, sizeof(struct d40_desc),
33003299
0, SLAB_HWCACHE_ALIGN,
33013300
NULL);
33023301
if (!base->desc_slab)
3303-
return NULL;
3302+
return -ENOMEM;
33043303

33053304
ret = devm_add_action_or_reset(dev, d40_drop_kmem_cache_action,
33063305
base->desc_slab);
33073306
if (ret)
3308-
return NULL;
3307+
return ret;
3308+
3309+
*retbase = base;
33093310

3310-
return base;
3311+
return 0;
33113312
}
33123313

33133314
static void __init d40_hw_init(struct d40_base *base)
@@ -3503,20 +3504,20 @@ static int __init d40_probe(struct platform_device *pdev)
35033504
struct device *dev = &pdev->dev;
35043505
struct device_node *np = pdev->dev.of_node;
35053506
struct device_node *np_lcpa;
3506-
int ret = -ENOENT;
35073507
struct d40_base *base;
35083508
struct resource *res;
35093509
struct resource res_lcpa;
35103510
int num_reserved_chans;
35113511
u32 val;
3512+
int ret;
35123513

35133514
if (d40_of_probe(dev, np)) {
35143515
ret = -ENOMEM;
35153516
goto report_failure;
35163517
}
35173518

3518-
base = d40_hw_detect_init(pdev);
3519-
if (!base)
3519+
ret = d40_hw_detect_init(pdev, &base);
3520+
if (ret)
35203521
goto report_failure;
35213522

35223523
num_reserved_chans = d40_phy_res_init(base);
@@ -3530,6 +3531,7 @@ static int __init d40_probe(struct platform_device *pdev)
35303531
np_lcpa = of_parse_phandle(np, "sram", 0);
35313532
if (!np_lcpa) {
35323533
dev_err(dev, "no LCPA SRAM node\n");
3534+
ret = -EINVAL;
35333535
goto report_failure;
35343536
}
35353537
/* This is no device so read the address directly from the node */

0 commit comments

Comments
 (0)