Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3803468ybi; Mon, 29 Jul 2019 12:57:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqxMImirK11tsGJE0lq2LIUfkMH6PvEF2rxh2W9Ytq72QA7uaEfarjKPgoi4QCFJErkOk9bw X-Received: by 2002:a17:902:361:: with SMTP id 88mr113287735pld.123.1564430254676; Mon, 29 Jul 2019 12:57:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564430254; cv=none; d=google.com; s=arc-20160816; b=j48caJXO1evbpd+Eb4hrvarRCv1vuK0LfyCzOYoIhVQpC5bcr4t8b3lJsAGKEJ642i gLdxBC0Pwf04bgLxwBDpomTRnar3JNnew0s9PRMKRrsh7671kGZgda31QXoM2qnbrRz+ wemnn0M8CznMQ+Xp+ngoT9I1LbvJbRrPUNQdh2lauvImR3vAbwU/9S2WPLjXKaoUkeVt wJyFozD/egJoPJLmkfE9uypghsIivT/vZkWB2sORJr0IOVuK8ibVktLoOuhuNsvsIy3Z TxMWJljVNUn5AJyi7OXDNrZEZKcm2/D3vc+1DMZ/AgzNyc3cfDvWbRI26kaLK8D9+jWX Onpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+OCqPrYin4MiCHlCGLHemH31lr6hwAdWUOSK4HuoJ0Q=; b=Fq1cz12sTKkYu6OemH9mL9juZ0eH/3DB1pYsZhqRV5TacpQB2O0pdKhzjjJZfRly+H k1CL0h2RMKThzNIYOBE216ia2E+FyZ/KsCtQMqi6jEUPaOpPgfFKSec0jeNYbAuGVSJQ lfUvUgmQn5gSj8GBh09HjoxZIUWDmB9Anp0yxCBbd73OqxEiJeHgr84HfBrK37gWuwKx Un3cevgHbdBKQtyzcCTG7UOgB9o8LFq6fM8JtD0gUm87aTUJKcnm4q+YHzrzbTLHHFoI TknepkCxfQPTgG52URNhxRiFL6nRfvb6Frb6Lh8wASQcWuhJGrIwsUBCfuMPZz+GnWoi 0Xmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UlahhL24; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t185si18065368pgb.329.2019.07.29.12.57.19; Mon, 29 Jul 2019 12:57:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UlahhL24; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403944AbfG2Ty4 (ORCPT + 99 others); Mon, 29 Jul 2019 15:54:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:47576 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404132AbfG2Tyx (ORCPT ); Mon, 29 Jul 2019 15:54:53 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2B1CF204EC; Mon, 29 Jul 2019 19:54:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564430092; bh=JSym5BCHXIZhjJG90piwBXOB0c8hcCgBoTk+AG7pemM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UlahhL24bwsv1b6MT7Jg7JnTt3PvVvLBKOyHPuKt4u2a4LNK8ARRRzLCihYsEwBVy MD4n4hstBX0ZM8XY0PLQ9xAqAaO3Xfv52842IvwM5qgt51I3Xh/j+VTJ8mU10zkiLB /yVS29dAzWLNxRuZ2nJip7V9JbV0toUaqshdwoh0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Takashi Iwai , Duncan Overbruck Subject: [PATCH 5.2 193/215] ALSA: pcm: Fix refcount_inc() on zero usage Date: Mon, 29 Jul 2019 21:23:09 +0200 Message-Id: <20190729190813.335586133@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190739.971253303@linuxfoundation.org> References: <20190729190739.971253303@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Takashi Iwai commit 0e279dcea0ec897af1c979ebee4ec92b461793f5 upstream. 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 Cc: Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/core/pcm_native.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -77,7 +77,7 @@ void snd_pcm_group_init(struct snd_pcm_g spin_lock_init(&group->lock); mutex_init(&group->mutex); INIT_LIST_HEAD(&group->substreams); - refcount_set(&group->refs, 0); + refcount_set(&group->refs, 1); } /* define group lock helpers */ @@ -1096,8 +1096,7 @@ static void snd_pcm_group_unref(struct s if (!group) return; - do_free = refcount_dec_and_test(&group->refs) && - list_empty(&group->substreams); + do_free = refcount_dec_and_test(&group->refs); snd_pcm_group_unlock(group, substream->pcm->nonatomic); if (do_free) kfree(group); @@ -2020,6 +2019,7 @@ static int snd_pcm_link(struct snd_pcm_s snd_pcm_group_lock_irq(target_group, nonatomic); snd_pcm_stream_lock(substream1); snd_pcm_group_assign(substream1, target_group); + refcount_inc(&target_group->refs); snd_pcm_stream_unlock(substream1); snd_pcm_group_unlock_irq(target_group, nonatomic); _end: @@ -2056,13 +2056,14 @@ static int snd_pcm_unlink(struct snd_pcm snd_pcm_group_lock_irq(group, nonatomic); relink_to_local(substream); + refcount_dec(&group->refs); /* detach the last stream, too */ if (list_is_singular(&group->substreams)) { relink_to_local(list_first_entry(&group->substreams, struct snd_pcm_substream, link_list)); - do_free = !refcount_read(&group->refs); + do_free = refcount_dec_and_test(&group->refs); } snd_pcm_group_unlock_irq(group, nonatomic);