Skip to content

Commit 7397c28

Browse files
committed
Merge branch 'for-linus'
2 parents 782a684 + 39675f7 commit 7397c28

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

sound/core/rawmidi.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ static int snd_rawmidi_info_select_user(struct snd_card *card,
635635
int snd_rawmidi_output_params(struct snd_rawmidi_substream *substream,
636636
struct snd_rawmidi_params * params)
637637
{
638-
char *newbuf;
638+
char *newbuf, *oldbuf;
639639
struct snd_rawmidi_runtime *runtime = substream->runtime;
640640

641641
if (substream->append && substream->use_count > 1)
@@ -648,13 +648,17 @@ int snd_rawmidi_output_params(struct snd_rawmidi_substream *substream,
648648
return -EINVAL;
649649
}
650650
if (params->buffer_size != runtime->buffer_size) {
651-
newbuf = krealloc(runtime->buffer, params->buffer_size,
652-
GFP_KERNEL);
651+
newbuf = kmalloc(params->buffer_size, GFP_KERNEL);
653652
if (!newbuf)
654653
return -ENOMEM;
654+
spin_lock_irq(&runtime->lock);
655+
oldbuf = runtime->buffer;
655656
runtime->buffer = newbuf;
656657
runtime->buffer_size = params->buffer_size;
657658
runtime->avail = runtime->buffer_size;
659+
runtime->appl_ptr = runtime->hw_ptr = 0;
660+
spin_unlock_irq(&runtime->lock);
661+
kfree(oldbuf);
658662
}
659663
runtime->avail_min = params->avail_min;
660664
substream->active_sensing = !params->no_active_sensing;
@@ -665,7 +669,7 @@ EXPORT_SYMBOL(snd_rawmidi_output_params);
665669
int snd_rawmidi_input_params(struct snd_rawmidi_substream *substream,
666670
struct snd_rawmidi_params * params)
667671
{
668-
char *newbuf;
672+
char *newbuf, *oldbuf;
669673
struct snd_rawmidi_runtime *runtime = substream->runtime;
670674

671675
snd_rawmidi_drain_input(substream);
@@ -676,12 +680,16 @@ int snd_rawmidi_input_params(struct snd_rawmidi_substream *substream,
676680
return -EINVAL;
677681
}
678682
if (params->buffer_size != runtime->buffer_size) {
679-
newbuf = krealloc(runtime->buffer, params->buffer_size,
680-
GFP_KERNEL);
683+
newbuf = kmalloc(params->buffer_size, GFP_KERNEL);
681684
if (!newbuf)
682685
return -ENOMEM;
686+
spin_lock_irq(&runtime->lock);
687+
oldbuf = runtime->buffer;
683688
runtime->buffer = newbuf;
684689
runtime->buffer_size = params->buffer_size;
690+
runtime->appl_ptr = runtime->hw_ptr = 0;
691+
spin_unlock_irq(&runtime->lock);
692+
kfree(oldbuf);
685693
}
686694
runtime->avail_min = params->avail_min;
687695
return 0;

0 commit comments

Comments
 (0)