Commit f6d1f14c authored by Jaroslav Kysela's avatar Jaroslav Kysela

[ALSA] fix buffer wrap in snd_rawmidi_transmit_peek

RawMidi Midlevel
Fix the behaviour and return value of snd_rawmidi_transmit_peek
when the buffer wraps around.
Signed-off-by: default avatarClemens Ladisch <clemens@ladisch.de>
parent 8c8a652c
......@@ -1047,8 +1047,12 @@ int snd_rawmidi_transmit_peek(snd_rawmidi_substream_t * substream, unsigned char
memcpy(buffer, runtime->buffer + runtime->hw_ptr, count1);
count -= count1;
result += count1;
if (count > 0)
if (count > 0) {
if (count > (int)(runtime->buffer_size - runtime->avail - count1))
count = runtime->buffer_size - runtime->avail - count1;
memcpy(buffer + count1, runtime->buffer, count);
result += count;
}
}
__skip:
spin_unlock_irqrestore(&runtime->lock, 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