drivers: net: davinci_cpdma: Convert kzalloc() to devm_kzalloc().

Convert kzalloc() to devm_kzalloc().

Signed-off-by: George Cherian <george.cherian@ti.com>
Reviewed-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
George Cherian 2014-05-12 10:21:21 +05:30 committed by David S. Miller
parent a92f40a9a3
commit e194312854
1 changed files with 12 additions and 23 deletions

View File

@ -158,9 +158,9 @@ cpdma_desc_pool_create(struct device *dev, u32 phys, u32 hw_addr,
int bitmap_size; int bitmap_size;
struct cpdma_desc_pool *pool; struct cpdma_desc_pool *pool;
pool = kzalloc(sizeof(*pool), GFP_KERNEL); pool = devm_kzalloc(dev, sizeof(*pool), GFP_KERNEL);
if (!pool) if (!pool)
return NULL; goto fail;
spin_lock_init(&pool->lock); spin_lock_init(&pool->lock);
@ -170,7 +170,7 @@ cpdma_desc_pool_create(struct device *dev, u32 phys, u32 hw_addr,
pool->num_desc = size / pool->desc_size; pool->num_desc = size / pool->desc_size;
bitmap_size = (pool->num_desc / BITS_PER_LONG) * sizeof(long); bitmap_size = (pool->num_desc / BITS_PER_LONG) * sizeof(long);
pool->bitmap = kzalloc(bitmap_size, GFP_KERNEL); pool->bitmap = devm_kzalloc(dev, bitmap_size, GFP_KERNEL);
if (!pool->bitmap) if (!pool->bitmap)
goto fail; goto fail;
@ -187,10 +187,7 @@ cpdma_desc_pool_create(struct device *dev, u32 phys, u32 hw_addr,
if (pool->iomap) if (pool->iomap)
return pool; return pool;
fail: fail:
kfree(pool->bitmap);
kfree(pool);
return NULL; return NULL;
} }
@ -203,7 +200,6 @@ static void cpdma_desc_pool_destroy(struct cpdma_desc_pool *pool)
spin_lock_irqsave(&pool->lock, flags); spin_lock_irqsave(&pool->lock, flags);
WARN_ON(pool->used_desc); WARN_ON(pool->used_desc);
kfree(pool->bitmap);
if (pool->cpumap) { if (pool->cpumap) {
dma_free_coherent(pool->dev, pool->mem_size, pool->cpumap, dma_free_coherent(pool->dev, pool->mem_size, pool->cpumap,
pool->phys); pool->phys);
@ -211,7 +207,6 @@ static void cpdma_desc_pool_destroy(struct cpdma_desc_pool *pool)
iounmap(pool->iomap); iounmap(pool->iomap);
} }
spin_unlock_irqrestore(&pool->lock, flags); spin_unlock_irqrestore(&pool->lock, flags);
kfree(pool);
} }
static inline dma_addr_t desc_phys(struct cpdma_desc_pool *pool, static inline dma_addr_t desc_phys(struct cpdma_desc_pool *pool,
@ -276,7 +271,7 @@ struct cpdma_ctlr *cpdma_ctlr_create(struct cpdma_params *params)
{ {
struct cpdma_ctlr *ctlr; struct cpdma_ctlr *ctlr;
ctlr = kzalloc(sizeof(*ctlr), GFP_KERNEL); ctlr = devm_kzalloc(params->dev, sizeof(*ctlr), GFP_KERNEL);
if (!ctlr) if (!ctlr)
return NULL; return NULL;
@ -468,7 +463,6 @@ int cpdma_ctlr_destroy(struct cpdma_ctlr *ctlr)
cpdma_desc_pool_destroy(ctlr->pool); cpdma_desc_pool_destroy(ctlr->pool);
spin_unlock_irqrestore(&ctlr->lock, flags); spin_unlock_irqrestore(&ctlr->lock, flags);
kfree(ctlr);
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(cpdma_ctlr_destroy); EXPORT_SYMBOL_GPL(cpdma_ctlr_destroy);
@ -507,21 +501,22 @@ struct cpdma_chan *cpdma_chan_create(struct cpdma_ctlr *ctlr, int chan_num,
cpdma_handler_fn handler) cpdma_handler_fn handler)
{ {
struct cpdma_chan *chan; struct cpdma_chan *chan;
int ret, offset = (chan_num % CPDMA_MAX_CHANNELS) * 4; int offset = (chan_num % CPDMA_MAX_CHANNELS) * 4;
unsigned long flags; unsigned long flags;
if (__chan_linear(chan_num) >= ctlr->num_chan) if (__chan_linear(chan_num) >= ctlr->num_chan)
return NULL; return NULL;
ret = -ENOMEM; chan = devm_kzalloc(ctlr->dev, sizeof(*chan), GFP_KERNEL);
chan = kzalloc(sizeof(*chan), GFP_KERNEL);
if (!chan) if (!chan)
goto err_chan_alloc; return ERR_PTR(-ENOMEM);
spin_lock_irqsave(&ctlr->lock, flags); spin_lock_irqsave(&ctlr->lock, flags);
ret = -EBUSY; if (ctlr->channels[chan_num]) {
if (ctlr->channels[chan_num]) spin_unlock_irqrestore(&ctlr->lock, flags);
goto err_chan_busy; devm_kfree(ctlr->dev, chan);
return ERR_PTR(-EBUSY);
}
chan->ctlr = ctlr; chan->ctlr = ctlr;
chan->state = CPDMA_STATE_IDLE; chan->state = CPDMA_STATE_IDLE;
@ -551,12 +546,6 @@ struct cpdma_chan *cpdma_chan_create(struct cpdma_ctlr *ctlr, int chan_num,
ctlr->channels[chan_num] = chan; ctlr->channels[chan_num] = chan;
spin_unlock_irqrestore(&ctlr->lock, flags); spin_unlock_irqrestore(&ctlr->lock, flags);
return chan; return chan;
err_chan_busy:
spin_unlock_irqrestore(&ctlr->lock, flags);
kfree(chan);
err_chan_alloc:
return ERR_PTR(ret);
} }
EXPORT_SYMBOL_GPL(cpdma_chan_create); EXPORT_SYMBOL_GPL(cpdma_chan_create);