Skip to content

Commit

Permalink
[MIPS] RTLX: Protect rtlx_{read,write} with mutex.
Browse files Browse the repository at this point in the history
Signed-off-by: Ralf Baechle <[email protected]>
  • Loading branch information
ralfbaechle committed Mar 17, 2007
1 parent 61dcc6f commit bc4809e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions arch/mips/kernel/rtlx.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ static struct chan_waitqueues {
wait_queue_head_t rt_queue;
wait_queue_head_t lx_queue;
atomic_t in_open;
struct mutex mutex;
} channel_wqs[RTLX_CHANNELS];

static struct irqaction irq;
Expand Down Expand Up @@ -314,6 +315,7 @@ ssize_t rtlx_read(int index, void *buff, size_t count, int user)

lx = &rtlx->channel[index];

mutex_lock(&channel_wqs[index].mutex);
smp_rmb();
lx_write = lx->lx_write;

Expand All @@ -334,6 +336,7 @@ ssize_t rtlx_read(int index, void *buff, size_t count, int user)
smp_wmb();
lx->lx_read = (lx->lx_read + count) % lx->buffer_size;
smp_wmb();
mutex_unlock(&channel_wqs[index].mutex);

return count;
}
Expand All @@ -349,6 +352,7 @@ ssize_t rtlx_write(int index, void *buffer, size_t count, int user)

rt = &rtlx->channel[index];

mutex_lock(&channel_wqs[index].mutex);
smp_rmb();
rt_read = rt->rt_read;

Expand All @@ -368,6 +372,7 @@ ssize_t rtlx_write(int index, void *buffer, size_t count, int user)
smp_wmb();
rt->rt_write = (rt->rt_write + count) % rt->buffer_size;
smp_wmb();
mutex_unlock(&channel_wqs[index].mutex);

return count;
}
Expand Down Expand Up @@ -486,6 +491,7 @@ static int rtlx_module_init(void)
init_waitqueue_head(&channel_wqs[i].rt_queue);
init_waitqueue_head(&channel_wqs[i].lx_queue);
atomic_set(&channel_wqs[i].in_open, 0);
mutex_init(&channel_wqs[i].mutex);

dev = device_create(mt_class, NULL, MKDEV(major, i),
"%s%d", module_name, i);
Expand Down

0 comments on commit bc4809e

Please sign in to comment.