Commit aaf40322 authored by Christian Gromm's avatar Christian Gromm Committed by Greg Kroah-Hartman

staging: most: allocate only all requested memory

This prohibits the allocation of the memory for the MBOs if only the
part of the MBOs, requested by the application, may be allocated.  The
function arm_mbo_chain, if cannot allocate all requested MBO, frees all
prior allocated memory and returns 0.
Signed-off-by: default avatarAndrey Shvetsov <andrey.shvetsov@k2l.de>
Signed-off-by: default avatarChristian Gromm <christian.gromm@microchip.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 8a95c132
...@@ -952,18 +952,17 @@ static int arm_mbo_chain(struct most_channel *c, int dir, ...@@ -952,18 +952,17 @@ static int arm_mbo_chain(struct most_channel *c, int dir,
void (*compl)(struct mbo *)) void (*compl)(struct mbo *))
{ {
unsigned int i; unsigned int i;
int retval;
struct mbo *mbo; struct mbo *mbo;
unsigned long flags;
u32 coherent_buf_size = c->cfg.buffer_size + c->cfg.extra_len; u32 coherent_buf_size = c->cfg.buffer_size + c->cfg.extra_len;
atomic_set(&c->mbo_nq_level, 0); atomic_set(&c->mbo_nq_level, 0);
for (i = 0; i < c->cfg.num_buffers; i++) { for (i = 0; i < c->cfg.num_buffers; i++) {
mbo = kzalloc(sizeof(*mbo), GFP_KERNEL); mbo = kzalloc(sizeof(*mbo), GFP_KERNEL);
if (!mbo) { if (!mbo)
retval = i; goto flush_fifos;
goto _exit;
}
mbo->context = c; mbo->context = c;
mbo->ifp = c->iface; mbo->ifp = c->iface;
mbo->hdm_channel_id = c->channel_id; mbo->hdm_channel_id = c->channel_id;
...@@ -971,26 +970,28 @@ static int arm_mbo_chain(struct most_channel *c, int dir, ...@@ -971,26 +970,28 @@ static int arm_mbo_chain(struct most_channel *c, int dir,
coherent_buf_size, coherent_buf_size,
&mbo->bus_address, &mbo->bus_address,
GFP_KERNEL); GFP_KERNEL);
if (!mbo->virt_address) { if (!mbo->virt_address)
pr_info("WARN: No DMA coherent buffer.\n"); goto release_mbo;
retval = i;
goto _error1;
}
mbo->complete = compl; mbo->complete = compl;
mbo->num_buffers_ptr = &dummy_num_buffers; mbo->num_buffers_ptr = &dummy_num_buffers;
if (dir == MOST_CH_RX) { if (dir == MOST_CH_RX) {
nq_hdm_mbo(mbo); nq_hdm_mbo(mbo);
atomic_inc(&c->mbo_nq_level); atomic_inc(&c->mbo_nq_level);
} else { } else {
arm_mbo(mbo); spin_lock_irqsave(&c->fifo_lock, flags);
list_add_tail(&mbo->list, &c->fifo);
spin_unlock_irqrestore(&c->fifo_lock, flags);
} }
} }
return i; return c->cfg.num_buffers;
_error1: release_mbo:
kfree(mbo); kfree(mbo);
_exit:
return retval; flush_fifos:
flush_channel_fifos(c);
return 0;
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment