Commit 34f719b0 authored by Brian Swetland's avatar Brian Swetland Committed by Daniel Walker

msm/qsd: smd: avoid race condition in smd channel allocation

Don't mark a channel as allocated if we failed to allocate it
(perhaps the modem updated one table but not the other, etc)
Signed-off-by: default avatarBrian Swetland <swetland@google.com>
Signed-off-by: default avatarDaniel Walker <dwalker@codeaurora.org>
parent 7632fba0
...@@ -153,7 +153,7 @@ LIST_HEAD(smd_ch_list_dsp); ...@@ -153,7 +153,7 @@ LIST_HEAD(smd_ch_list_dsp);
static unsigned char smd_ch_allocated[64]; static unsigned char smd_ch_allocated[64];
static struct work_struct probe_work; static struct work_struct probe_work;
static void smd_alloc_channel(const char *name, uint32_t cid, uint32_t type); static int smd_alloc_channel(const char *name, uint32_t cid, uint32_t type);
static void smd_channel_probe_worker(struct work_struct *work) static void smd_channel_probe_worker(struct work_struct *work)
{ {
...@@ -186,7 +186,7 @@ static void smd_channel_probe_worker(struct work_struct *work) ...@@ -186,7 +186,7 @@ static void smd_channel_probe_worker(struct work_struct *work)
type = shared[n].ctype & SMD_TYPE_MASK; type = shared[n].ctype & SMD_TYPE_MASK;
if ((type == SMD_TYPE_APPS_MODEM) || if ((type == SMD_TYPE_APPS_MODEM) ||
(type == SMD_TYPE_APPS_DSP)) (type == SMD_TYPE_APPS_DSP))
smd_alloc_channel(shared[n].name, shared[n].cid, ctype); if (!smd_alloc_channel(shared[n].name, shared[n].cid, ctype))
smd_ch_allocated[n] = 1; smd_ch_allocated[n] = 1;
} }
} }
...@@ -641,20 +641,20 @@ static int smd_alloc_v1(struct smd_channel *ch) ...@@ -641,20 +641,20 @@ static int smd_alloc_v1(struct smd_channel *ch)
} }
static void smd_alloc_channel(const char *name, uint32_t cid, uint32_t type) static int smd_alloc_channel(const char *name, uint32_t cid, uint32_t type)
{ {
struct smd_channel *ch; struct smd_channel *ch;
ch = kzalloc(sizeof(struct smd_channel), GFP_KERNEL); ch = kzalloc(sizeof(struct smd_channel), GFP_KERNEL);
if (ch == 0) { if (ch == 0) {
pr_err("smd_alloc_channel() out of memory\n"); pr_err("smd_alloc_channel() out of memory\n");
return; return -1;
} }
ch->n = cid; ch->n = cid;
if (smd_alloc_v2(ch) && smd_alloc_v1(ch)) { if (smd_alloc_v2(ch) && smd_alloc_v1(ch)) {
kfree(ch); kfree(ch);
return; return -1;
} }
ch->fifo_mask = ch->fifo_size - 1; ch->fifo_mask = ch->fifo_size - 1;
...@@ -696,6 +696,7 @@ static void smd_alloc_channel(const char *name, uint32_t cid, uint32_t type) ...@@ -696,6 +696,7 @@ static void smd_alloc_channel(const char *name, uint32_t cid, uint32_t type)
mutex_unlock(&smd_creation_mutex); mutex_unlock(&smd_creation_mutex);
platform_device_register(&ch->pdev); platform_device_register(&ch->pdev);
return 0;
} }
static void do_nothing_notify(void *priv, unsigned flags) static void do_nothing_notify(void *priv, unsigned flags)
......
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