Skip to content

Commit 000871c

Browse files
andy-shevVinod Koul
authored andcommitted
dma: dw: allocate memory in two stages in probe
This makes the probe() function a little bit clearer. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
1 parent 2acec15 commit 000871c

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

‎drivers/dma/dw/core.c‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,14 +1479,20 @@ static void dw_dma_off(struct dw_dma *dw)
14791479
int dw_dma_probe(struct dw_dma_chip *chip, struct dw_dma_platform_data *pdata)
14801480
{
14811481
struct dw_dma *dw;
1482-
size_t size;
14831482
bool autocfg;
14841483
unsigned int dw_params;
14851484
unsigned int nr_channels;
14861485
unsigned int max_blk_size = 0;
14871486
int err;
14881487
int i;
14891488

1489+
dw = devm_kzalloc(chip->dev, sizeof(*dw), GFP_KERNEL);
1490+
if (!dw)
1491+
return -ENOMEM;
1492+
1493+
dw->regs = chip->regs;
1494+
chip->dw = dw;
1495+
14901496
dw_params = dma_read_byaddr(chip->regs, DW_PARAMS);
14911497
autocfg = dw_params >> DW_PARAMS_EN & 0x1;
14921498

@@ -1509,19 +1515,16 @@ int dw_dma_probe(struct dw_dma_chip *chip, struct dw_dma_platform_data *pdata)
15091515
else
15101516
nr_channels = pdata->nr_channels;
15111517

1512-
size = sizeof(struct dw_dma) + nr_channels * sizeof(struct dw_dma_chan);
1513-
dw = devm_kzalloc(chip->dev, size, GFP_KERNEL);
1514-
if (!dw)
1518+
dw->chan = devm_kcalloc(chip->dev, nr_channels, sizeof(*dw->chan),
1519+
GFP_KERNEL);
1520+
if (!dw->chan)
15151521
return -ENOMEM;
15161522

15171523
dw->clk = devm_clk_get(chip->dev, "hclk");
15181524
if (IS_ERR(dw->clk))
15191525
return PTR_ERR(dw->clk);
15201526
clk_prepare_enable(dw->clk);
15211527

1522-
dw->regs = chip->regs;
1523-
chip->dw = dw;
1524-
15251528
/* Get hardware configuration parameters */
15261529
if (autocfg) {
15271530
max_blk_size = dma_readl(dw, MAX_BLK_SIZE);

‎drivers/dma/dw/regs.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,13 @@ struct dw_dma {
252252
struct tasklet_struct tasklet;
253253
struct clk *clk;
254254

255+
/* channels */
256+
struct dw_dma_chan *chan;
255257
u8 all_chan_mask;
256258

257259
/* hardware configuration */
258260
unsigned char nr_masters;
259261
unsigned char data_width[4];
260-
261-
struct dw_dma_chan chan[0];
262262
};
263263

264264
static inline struct dw_dma_regs __iomem *__dw_regs(struct dw_dma *dw)

0 commit comments

Comments
 (0)