ALSA: pcm: Fix refcount_inc() on zero usage
authorTakashi Iwai <tiwai@suse.de>
Fri, 19 Jul 2019 08:55:05 +0000 (10:55 +0200)
committerTakashi Iwai <tiwai@suse.de>
Fri, 19 Jul 2019 13:47:00 +0000 (15:47 +0200)
commit0e279dcea0ec897af1c979ebee4ec92b461793f5
tree404599ef22d243be51004f7252fc6188aa22f70c
parent70256b42caaf3e13c2932c2be7903a73fbe8bb8b
ALSA: pcm: Fix refcount_inc() on zero usage

The recent rewrite of PCM link lock management introduced the refcount
in snd_pcm_group object, managed by the kernel refcount_t API.  This
caused unexpected kernel warnings when the kernel is built with
CONFIG_REFCOUNT_FULL=y.  As the warning line indicates, the problem is
obviously that we start with refcount=0 and do refcount_inc() for
adding each PCM link, while refcount_t API doesn't like refcount_inc()
performed on zero.

For adapting the proper refcount_t usage, this patch changes the logic
slightly:
- The initial refcount is 1, assuming the single list entry
- The refcount is incremented / decremented at each PCM link addition
  and deletion
- ... which allows us concentrating only on the refcount as a release
  condition

Fixes: f57f3df03a8e ("ALSA: pcm: More fine-grained PCM link locking")
BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=204221
Reported-and-tested-by: Duncan Overbruck <kernel@duncano.de>
Cc: <stable@vger.kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/core/pcm_native.c