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>
This commit is contained in:
Andy Shevchenko 2014-03-05 15:48:12 +02:00 committed by Vinod Koul
parent 2acec15034
commit 000871ce03
2 changed files with 12 additions and 9 deletions

View File

@ -1479,7 +1479,6 @@ static void dw_dma_off(struct dw_dma *dw)
int dw_dma_probe(struct dw_dma_chip *chip, struct dw_dma_platform_data *pdata) int dw_dma_probe(struct dw_dma_chip *chip, struct dw_dma_platform_data *pdata)
{ {
struct dw_dma *dw; struct dw_dma *dw;
size_t size;
bool autocfg; bool autocfg;
unsigned int dw_params; unsigned int dw_params;
unsigned int nr_channels; unsigned int nr_channels;
@ -1487,6 +1486,13 @@ int dw_dma_probe(struct dw_dma_chip *chip, struct dw_dma_platform_data *pdata)
int err; int err;
int i; int i;
dw = devm_kzalloc(chip->dev, sizeof(*dw), GFP_KERNEL);
if (!dw)
return -ENOMEM;
dw->regs = chip->regs;
chip->dw = dw;
dw_params = dma_read_byaddr(chip->regs, DW_PARAMS); dw_params = dma_read_byaddr(chip->regs, DW_PARAMS);
autocfg = dw_params >> DW_PARAMS_EN & 0x1; autocfg = dw_params >> DW_PARAMS_EN & 0x1;
@ -1509,9 +1515,9 @@ int dw_dma_probe(struct dw_dma_chip *chip, struct dw_dma_platform_data *pdata)
else else
nr_channels = pdata->nr_channels; nr_channels = pdata->nr_channels;
size = sizeof(struct dw_dma) + nr_channels * sizeof(struct dw_dma_chan); dw->chan = devm_kcalloc(chip->dev, nr_channels, sizeof(*dw->chan),
dw = devm_kzalloc(chip->dev, size, GFP_KERNEL); GFP_KERNEL);
if (!dw) if (!dw->chan)
return -ENOMEM; return -ENOMEM;
dw->clk = devm_clk_get(chip->dev, "hclk"); dw->clk = devm_clk_get(chip->dev, "hclk");
@ -1519,9 +1525,6 @@ int dw_dma_probe(struct dw_dma_chip *chip, struct dw_dma_platform_data *pdata)
return PTR_ERR(dw->clk); return PTR_ERR(dw->clk);
clk_prepare_enable(dw->clk); clk_prepare_enable(dw->clk);
dw->regs = chip->regs;
chip->dw = dw;
/* Get hardware configuration parameters */ /* Get hardware configuration parameters */
if (autocfg) { if (autocfg) {
max_blk_size = dma_readl(dw, MAX_BLK_SIZE); max_blk_size = dma_readl(dw, MAX_BLK_SIZE);

View File

@ -252,13 +252,13 @@ struct dw_dma {
struct tasklet_struct tasklet; struct tasklet_struct tasklet;
struct clk *clk; struct clk *clk;
/* channels */
struct dw_dma_chan *chan;
u8 all_chan_mask; u8 all_chan_mask;
/* hardware configuration */ /* hardware configuration */
unsigned char nr_masters; unsigned char nr_masters;
unsigned char data_width[4]; unsigned char data_width[4];
struct dw_dma_chan chan[0];
}; };
static inline struct dw_dma_regs __iomem *__dw_regs(struct dw_dma *dw) static inline struct dw_dma_regs __iomem *__dw_regs(struct dw_dma *dw)