@@ -635,7 +635,7 @@ static int snd_rawmidi_info_select_user(struct snd_card *card,
635
635
int snd_rawmidi_output_params (struct snd_rawmidi_substream * substream ,
636
636
struct snd_rawmidi_params * params )
637
637
{
638
- char * newbuf ;
638
+ char * newbuf , * oldbuf ;
639
639
struct snd_rawmidi_runtime * runtime = substream -> runtime ;
640
640
641
641
if (substream -> append && substream -> use_count > 1 )
@@ -648,13 +648,17 @@ int snd_rawmidi_output_params(struct snd_rawmidi_substream *substream,
648
648
return - EINVAL ;
649
649
}
650
650
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 );
653
652
if (!newbuf )
654
653
return - ENOMEM ;
654
+ spin_lock_irq (& runtime -> lock );
655
+ oldbuf = runtime -> buffer ;
655
656
runtime -> buffer = newbuf ;
656
657
runtime -> buffer_size = params -> buffer_size ;
657
658
runtime -> avail = runtime -> buffer_size ;
659
+ runtime -> appl_ptr = runtime -> hw_ptr = 0 ;
660
+ spin_unlock_irq (& runtime -> lock );
661
+ kfree (oldbuf );
658
662
}
659
663
runtime -> avail_min = params -> avail_min ;
660
664
substream -> active_sensing = !params -> no_active_sensing ;
@@ -665,7 +669,7 @@ EXPORT_SYMBOL(snd_rawmidi_output_params);
665
669
int snd_rawmidi_input_params (struct snd_rawmidi_substream * substream ,
666
670
struct snd_rawmidi_params * params )
667
671
{
668
- char * newbuf ;
672
+ char * newbuf , * oldbuf ;
669
673
struct snd_rawmidi_runtime * runtime = substream -> runtime ;
670
674
671
675
snd_rawmidi_drain_input (substream );
@@ -676,12 +680,16 @@ int snd_rawmidi_input_params(struct snd_rawmidi_substream *substream,
676
680
return - EINVAL ;
677
681
}
678
682
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 );
681
684
if (!newbuf )
682
685
return - ENOMEM ;
686
+ spin_lock_irq (& runtime -> lock );
687
+ oldbuf = runtime -> buffer ;
683
688
runtime -> buffer = newbuf ;
684
689
runtime -> buffer_size = params -> buffer_size ;
690
+ runtime -> appl_ptr = runtime -> hw_ptr = 0 ;
691
+ spin_unlock_irq (& runtime -> lock );
692
+ kfree (oldbuf );
685
693
}
686
694
runtime -> avail_min = params -> avail_min ;
687
695
return 0 ;
0 commit comments