OSDN Git Service

ALSA: timer: Improve user queue reallocation
authorTakashi Iwai <tiwai@suse.de>
Fri, 2 Jun 2017 15:16:59 +0000 (17:16 +0200)
committerTakashi Iwai <tiwai@suse.de>
Wed, 7 Jun 2017 08:25:51 +0000 (10:25 +0200)
commit890e2cb5d184629702a2c1a1e9631f9f64523c65
treeeb3192675a5da8226d56dc6f832a3482741b56af
parent4c7aba46c9e82aa236502760a677e666589afead
ALSA: timer: Improve user queue reallocation

ALSA timer may reallocate the user queue upon request, and it happens
at three places for now: at opening, at SNDRV_TIMER_IOCTL_PARAMS, and
at SNDRV_TIMER_IOCTL_SELECT.  However, the last one,
snd_timer_user_tselect(), doesn't need to reallocate the buffer since
it doesn't change the queue size.  It does just because tu->tread
might have been changed before starting the timer.

Instead of *_SELECT ioctl, we should reallocate the queue at
SNDRV_TIMER_IOCTL_TREAD; then the timer is guaranteed to be stopped,
thus we can reassign the buffer more safely.

This patch implements that with a slight code refactoring.
Essentially, the patch achieves:
- Introduce realloc_user_queue() for (re-)allocating the ring buffer,
  and call it from all places.  Also, realloc_user_queue() uses
  kcalloc() for avoiding possible leaks.
- Add the buffer reallocation at SNDRV_TIMER_IOCTL_TREAD.  When it
  fails, tu->tread is restored to the old value, too.
- Drop the buffer reallocation at snd_timer_user_tselect().

Tested-by: Alexander Potapenko <glider@google.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/core/timer.c