Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3317506imu; Sun, 11 Nov 2018 12:14:15 -0800 (PST) X-Google-Smtp-Source: AJdET5emBzm+zC7RTa0igCa5ck9nQwOZoFDGPZd9YLtnhKJDeH1Vu5SMj1GfR5LvBpYybhCc/GNT X-Received: by 2002:a17:902:5a4:: with SMTP id f33-v6mr16908268plf.324.1541967255737; Sun, 11 Nov 2018 12:14:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541967255; cv=none; d=google.com; s=arc-20160816; b=I4XszoCOTrPWhhsmNX3W7Qw2oWq9z1mXSoV340OwHfgO+xGIYTZvL1SPo/+T1poTOt a9PY4lXgl8juikngnUtGIU2bzbBuV/aC4x+Z3wIfFexNlgRliC5kcE2r6Totw/hbpaw2 u9KC3Xb1bNHsQXmZ5sP0fFrteoFeq3TFp3cW0UQmveHK8LnLc2pG4Gn5vPZk7Yc9hE/J 8FtxTLfpBTHIce/H+HU3OW2eTXqlonnuGGLiPK81X4EFznjIbF0mN0H0hVAnbRaJAOKg Nc1m/nT/nXRO8xQochrVikdpbbDReTf43JLTC974FGlCdUsPkKawvkoS1QfICXIGcVCj ullQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=QUENAxWh0u63KKnDn2PncHrA2pQzTmfdsB0fzwGPgqs=; b=1GnORaHYdDA3I8FGCPGqcgyCz1msXFaGzZxJLRqh1xSlrwFnEuZzWGs0bgU3YuQptT v96MjEMCFoDu35y8+SUpDhYvCElklexAZsBri4Ianew9WIuHkXtZEL+WD4Slw3k0s1Of 9WAv1dCrHsPk83RAyxJXPrVtKluTez+pbCDeRsbJicJZzUkg+Wx05ERkUQUvS6ln1b6F Groxdt5U8TwXYBMH3lNIf+nLhT4a7KhOnDr9qI8cRxIuf9iLYYItiht2h7pwenaGoYqj 7R2OLH+RyFqZ6DdwM8gFhfVe67v53lh35NccQWxSyOOj0G+dADtztk/WJrUpKsIVCPLk f3ag== ARC-Authentication-Results: i=1; mx.google.com; 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 r7-v6si14731390plo.100.2018.11.11.12.14.00; Sun, 11 Nov 2018 12:14:15 -0800 (PST) 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; 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 S1731040AbeKLGBd (ORCPT + 99 others); Mon, 12 Nov 2018 01:01:33 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:52534 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727101AbeKLGBd (ORCPT ); Mon, 12 Nov 2018 01:01:33 -0500 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLvtA-0000lF-6Y; Sun, 11 Nov 2018 19:59:20 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gLvsP-0001Qh-8A; Sun, 11 Nov 2018 19:58:33 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Tzung-Bi Shih" , "Takashi Iwai" Date: Sun, 11 Nov 2018 19:49:05 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 058/366] ALSA: core: Assure control device to be registered at last In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.61-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Takashi Iwai commit dc82e52492f684dcd5ed9e4773e72dbf2203d75e upstream. The commit 289ca025ee1d ("ALSA: Use priority list for managing device list") changed the way to register/disconnect/free devices via a single priority list. This helped to make behavior consistent, but it also changed a slight behavior change: namely, the control device is registered earlier than others, while it was supposed to be the very last one. I've put SNDRV_DEV_CONTROL in the current position as the release of ctl elements often conflict with the private ctl elements some PCM or other components may create, which often leads to a double-free. But, the order of register and disconnect should be indeed fixed as expected in the early days: the control device gets registered at last, and disconnected at first. This patch changes the priority list order to move SNDRV_DEV_CONTROL as the last guy to assure the register / disconnect order. Meanwhile, for keeping the messy resource release order, manually treat the control and lowlevel devices as last freed one. Additional note: The lowlevel device is the device where a card driver creates at probe. And, we still keep the release order control -> lowlevel, as there might be link from a control element back to a lowlevel object. Fixes: 289ca025ee1d ("ALSA: Use priority list for managing device list") Reported-by: Tzung-Bi Shih Tested-by: Tzung-Bi Shih Signed-off-by: Takashi Iwai Signed-off-by: Ben Hutchings --- include/sound/core.h | 2 +- sound/core/device.c | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) --- a/include/sound/core.h +++ b/include/sound/core.h @@ -51,7 +51,6 @@ struct completion; */ enum snd_device_type { SNDRV_DEV_LOWLEVEL, - SNDRV_DEV_CONTROL, SNDRV_DEV_INFO, SNDRV_DEV_BUS, SNDRV_DEV_CODEC, @@ -62,6 +61,7 @@ enum snd_device_type { SNDRV_DEV_SEQUENCER, SNDRV_DEV_HWDEP, SNDRV_DEV_JACK, + SNDRV_DEV_CONTROL, /* NOTE: this must be the last one */ }; enum snd_device_state { --- a/sound/core/device.c +++ b/sound/core/device.c @@ -219,6 +219,15 @@ void snd_device_free_all(struct snd_card if (snd_BUG_ON(!card)) return; + list_for_each_entry_safe_reverse(dev, next, &card->devices, list) { + /* exception: free ctl and lowlevel stuff later */ + if (dev->type == SNDRV_DEV_CONTROL || + dev->type == SNDRV_DEV_LOWLEVEL) + continue; + __snd_device_free(dev); + } + + /* free all */ list_for_each_entry_safe_reverse(dev, next, &card->devices, list) __snd_device_free(dev); }