diff options
author | Ralf Baechle <ralf@linux-mips.org> | 2007-03-15 13:13:47 -0400 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2007-03-16 21:03:28 -0400 |
commit | bc4809e939b91c9642f1ddaea732e2d432ee6af6 (patch) | |
tree | 0536fee2c956f0caa2379041a46bdc8db66a6d74 /arch/mips/kernel/rtlx.c | |
parent | 61dcc6f4d9ed5db71f4f0be9026bdd09f1a7dc06 (diff) |
[MIPS] RTLX: Protect rtlx_{read,write} with mutex.
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'arch/mips/kernel/rtlx.c')
-rw-r--r-- | arch/mips/kernel/rtlx.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/arch/mips/kernel/rtlx.c b/arch/mips/kernel/rtlx.c index 0441c7c1e44c..745649e15adc 100644 --- a/arch/mips/kernel/rtlx.c +++ b/arch/mips/kernel/rtlx.c | |||
@@ -54,6 +54,7 @@ static struct chan_waitqueues { | |||
54 | wait_queue_head_t rt_queue; | 54 | wait_queue_head_t rt_queue; |
55 | wait_queue_head_t lx_queue; | 55 | wait_queue_head_t lx_queue; |
56 | atomic_t in_open; | 56 | atomic_t in_open; |
57 | struct mutex mutex; | ||
57 | } channel_wqs[RTLX_CHANNELS]; | 58 | } channel_wqs[RTLX_CHANNELS]; |
58 | 59 | ||
59 | static struct irqaction irq; | 60 | static struct irqaction irq; |
@@ -314,6 +315,7 @@ ssize_t rtlx_read(int index, void *buff, size_t count, int user) | |||
314 | 315 | ||
315 | lx = &rtlx->channel[index]; | 316 | lx = &rtlx->channel[index]; |
316 | 317 | ||
318 | mutex_lock(&channel_wqs[index].mutex); | ||
317 | smp_rmb(); | 319 | smp_rmb(); |
318 | lx_write = lx->lx_write; | 320 | lx_write = lx->lx_write; |
319 | 321 | ||
@@ -334,6 +336,7 @@ ssize_t rtlx_read(int index, void *buff, size_t count, int user) | |||
334 | smp_wmb(); | 336 | smp_wmb(); |
335 | lx->lx_read = (lx->lx_read + count) % lx->buffer_size; | 337 | lx->lx_read = (lx->lx_read + count) % lx->buffer_size; |
336 | smp_wmb(); | 338 | smp_wmb(); |
339 | mutex_unlock(&channel_wqs[index].mutex); | ||
337 | 340 | ||
338 | return count; | 341 | return count; |
339 | } | 342 | } |
@@ -349,6 +352,7 @@ ssize_t rtlx_write(int index, void *buffer, size_t count, int user) | |||
349 | 352 | ||
350 | rt = &rtlx->channel[index]; | 353 | rt = &rtlx->channel[index]; |
351 | 354 | ||
355 | mutex_lock(&channel_wqs[index].mutex); | ||
352 | smp_rmb(); | 356 | smp_rmb(); |
353 | rt_read = rt->rt_read; | 357 | rt_read = rt->rt_read; |
354 | 358 | ||
@@ -368,6 +372,7 @@ ssize_t rtlx_write(int index, void *buffer, size_t count, int user) | |||
368 | smp_wmb(); | 372 | smp_wmb(); |
369 | rt->rt_write = (rt->rt_write + count) % rt->buffer_size; | 373 | rt->rt_write = (rt->rt_write + count) % rt->buffer_size; |
370 | smp_wmb(); | 374 | smp_wmb(); |
375 | mutex_unlock(&channel_wqs[index].mutex); | ||
371 | 376 | ||
372 | return count; | 377 | return count; |
373 | } | 378 | } |
@@ -486,6 +491,7 @@ static int rtlx_module_init(void) | |||
486 | init_waitqueue_head(&channel_wqs[i].rt_queue); | 491 | init_waitqueue_head(&channel_wqs[i].rt_queue); |
487 | init_waitqueue_head(&channel_wqs[i].lx_queue); | 492 | init_waitqueue_head(&channel_wqs[i].lx_queue); |
488 | atomic_set(&channel_wqs[i].in_open, 0); | 493 | atomic_set(&channel_wqs[i].in_open, 0); |
494 | mutex_init(&channel_wqs[i].mutex); | ||
489 | 495 | ||
490 | dev = device_create(mt_class, NULL, MKDEV(major, i), | 496 | dev = device_create(mt_class, NULL, MKDEV(major, i), |
491 | "%s%d", module_name, i); | 497 | "%s%d", module_name, i); |