Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 81599
b: refs/heads/master
c: 17596a8
h: refs/heads/master
i:
  81597: 59c44ca
  81595: d1eb344
  81591: e3af66e
  81583: ca70db1
  81567: 36213c1
  81535: 8cbf7ee
v: v3
  • Loading branch information
Marcin Ślusarz authored and Jaroslav Kysela committed Jan 31, 2008
1 parent 7d3b3b7 commit ac1f82a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: a780c0aeb39e9251c1b48166380f4455871bc067
refs/heads/master: 17596a80d3b57763f6d111fa95416559bad9c8dc
40 changes: 21 additions & 19 deletions trunk/sound/core/rawmidi.c
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,8 @@ int snd_rawmidi_receive(struct snd_rawmidi_substream *substream,
}

static long snd_rawmidi_kernel_read1(struct snd_rawmidi_substream *substream,
unsigned char *buf, long count, int kernel)
unsigned char __user *userbuf,
unsigned char *kernelbuf, long count)
{
unsigned long flags;
long result = 0, count1;
Expand All @@ -924,11 +925,11 @@ static long snd_rawmidi_kernel_read1(struct snd_rawmidi_substream *substream,
spin_lock_irqsave(&runtime->lock, flags);
if (count1 > (int)runtime->avail)
count1 = runtime->avail;
if (kernel) {
memcpy(buf + result, runtime->buffer + runtime->appl_ptr, count1);
} else {
if (kernelbuf)
memcpy(kernelbuf + result, runtime->buffer + runtime->appl_ptr, count1);
if (userbuf) {
spin_unlock_irqrestore(&runtime->lock, flags);
if (copy_to_user((char __user *)buf + result,
if (copy_to_user(userbuf + result,
runtime->buffer + runtime->appl_ptr, count1)) {
return result > 0 ? result : -EFAULT;
}
Expand All @@ -948,7 +949,7 @@ long snd_rawmidi_kernel_read(struct snd_rawmidi_substream *substream,
unsigned char *buf, long count)
{
snd_rawmidi_input_trigger(substream, 1);
return snd_rawmidi_kernel_read1(substream, buf, count, 1);
return snd_rawmidi_kernel_read1(substream, NULL/*userbuf*/, buf, count);
}

static ssize_t snd_rawmidi_read(struct file *file, char __user *buf, size_t count,
Expand Down Expand Up @@ -989,8 +990,9 @@ static ssize_t snd_rawmidi_read(struct file *file, char __user *buf, size_t coun
}
spin_unlock_irq(&runtime->lock);
count1 = snd_rawmidi_kernel_read1(substream,
(unsigned char __force *)buf,
count, 0);
(unsigned char __user *)buf,
NULL/*kernelbuf*/,
count);
if (count1 < 0)
return result > 0 ? result : count1;
result += count1;
Expand Down Expand Up @@ -1131,13 +1133,15 @@ int snd_rawmidi_transmit(struct snd_rawmidi_substream *substream,
}

static long snd_rawmidi_kernel_write1(struct snd_rawmidi_substream *substream,
const unsigned char *buf, long count, int kernel)
const unsigned char __user *userbuf,
const unsigned char *kernelbuf,
long count)
{
unsigned long flags;
long count1, result;
struct snd_rawmidi_runtime *runtime = substream->runtime;

snd_assert(buf != NULL, return -EINVAL);
snd_assert(kernelbuf != NULL || userbuf != NULL, return -EINVAL);
snd_assert(runtime->buffer != NULL, return -EINVAL);

result = 0;
Expand All @@ -1154,12 +1158,13 @@ static long snd_rawmidi_kernel_write1(struct snd_rawmidi_substream *substream,
count1 = count;
if (count1 > (long)runtime->avail)
count1 = runtime->avail;
if (kernel) {
memcpy(runtime->buffer + runtime->appl_ptr, buf, count1);
} else {
if (kernelbuf)
memcpy(runtime->buffer + runtime->appl_ptr,
kernelbuf + result, count1);
else if (userbuf) {
spin_unlock_irqrestore(&runtime->lock, flags);
if (copy_from_user(runtime->buffer + runtime->appl_ptr,
(char __user *)buf, count1)) {
userbuf + result, count1)) {
spin_lock_irqsave(&runtime->lock, flags);
result = result > 0 ? result : -EFAULT;
goto __end;
Expand All @@ -1170,7 +1175,6 @@ static long snd_rawmidi_kernel_write1(struct snd_rawmidi_substream *substream,
runtime->appl_ptr %= runtime->buffer_size;
runtime->avail -= count1;
result += count1;
buf += count1;
count -= count1;
}
__end:
Expand All @@ -1184,7 +1188,7 @@ static long snd_rawmidi_kernel_write1(struct snd_rawmidi_substream *substream,
long snd_rawmidi_kernel_write(struct snd_rawmidi_substream *substream,
const unsigned char *buf, long count)
{
return snd_rawmidi_kernel_write1(substream, buf, count, 1);
return snd_rawmidi_kernel_write1(substream, NULL, buf, count);
}

static ssize_t snd_rawmidi_write(struct file *file, const char __user *buf,
Expand Down Expand Up @@ -1224,9 +1228,7 @@ static ssize_t snd_rawmidi_write(struct file *file, const char __user *buf,
spin_lock_irq(&runtime->lock);
}
spin_unlock_irq(&runtime->lock);
count1 = snd_rawmidi_kernel_write1(substream,
(unsigned char __force *)buf,
count, 0);
count1 = snd_rawmidi_kernel_write1(substream, buf, NULL, count);
if (count1 < 0)
return result > 0 ? result : count1;
result += count1;
Expand Down

0 comments on commit ac1f82a

Please sign in to comment.