Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp249639ybd; Tue, 25 Jun 2019 20:43:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqyhaKJ4em289Y1CZ9B05gnong6SVJRXPhrAd42UXFIaPBgWh4GxZwnTwuRMdXpnR1d5LwYW X-Received: by 2002:a17:902:7581:: with SMTP id j1mr2562668pll.23.1561520627013; Tue, 25 Jun 2019 20:43:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561520627; cv=none; d=google.com; s=arc-20160816; b=blfdzh22v+HKUof1dX2+cdp22vATlHvx3U5KsvxVwumkLutrO8oCIHOhWb9RAdKydO ul21wEdLFYl2SjLFDD3eCtWX1AuMHkjwKdgGEmNqOcPRR5GPMKnTFtcCkIGNgNfCNbYk YE4WIX5NjSyTQoyjMAKO0J3ULZ9NvcWWbHo98VgwOybSXoVtQAP5ZotSO+1pmW1dr7uq C77bLngw7f8xuvvZ1NbPlbU+I6eK1MMByg70upImePSaw6KXKeDqIvZp1S8WDmIzBCtw +dyGSmsHGLyoayINSTZQqcBlxfCCBEqHvuSqpsCvB+zRWxJ4zi7wwm1tUQ6wrx32IoEa UfmA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=BvRkMdk5ppxE7Ne7wU77wCMzySP0EVx+q7cdfp/wJvU=; b=odm16HIwgldPMpib6XRRv6dtTzWH0R9ko2rhYMMLw4VJxDAKidnGMjK7w2Mx7mIRNB 4ohXFwA0UG8Qh8K0OXLPKXRpqtSe0vlJP3PMLktevQ0k09Tac75Cm9HxQFr5T3ZV9end /Rj3lrLJNF+/cK9nu9RuhDbpmdlFuKmscmFOhASyiD6nirwetqVpnmxwvgAtrSkNIted h7UNYTG5vkfIZ7yrcvw6FziGRqxdXoH+InWM+tH7YPCxCCPmYKZR7jTNtICTcrGymqVt 48Pw1Wa1k9bK9UOKxB62WfH8dwm1Rp2HDbb0OKnrR8ADSI3Vl7CgB5JcB6DoKbhSSp8i c1/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nYhNeNv2; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f9si16811801pfd.110.2019.06.25.20.43.31; Tue, 25 Jun 2019 20:43:47 -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=nYhNeNv2; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727175AbfFZDmu (ORCPT + 99 others); Tue, 25 Jun 2019 23:42:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:53754 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727168AbfFZDmq (ORCPT ); Tue, 25 Jun 2019 23:42:46 -0400 Received: from sasha-vm.mshome.net (mobile-107-77-172-74.mobile.att.net [107.77.172.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9B0E72147A; Wed, 26 Jun 2019 03:42:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561520565; bh=oEKTGtKAmDrp8J0H+rxtRfGHW5GodEDDpVgWvfDwCe8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nYhNeNv2Rhoeg083igXz5RhnQ+tt3rxBft9ANYMK/m7u7kil8fdisQOiRPxWRTE55 ajxL9OloUNkSRqftjcGdHFlnXO3ft0bv7VC5M2aVj/AwNluvwbLzmJh5PzA9wgFFYD qII1TJKfDLKaYVfoANyn5d7Nh/OHjya8NRF0GSpk= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Tzung-Bi Shih , Mark Brown , Sasha Levin Subject: [PATCH AUTOSEL 5.1 31/51] ASoC: core: move DAI pre-links initiation to snd_soc_instantiate_card Date: Tue, 25 Jun 2019 23:40:47 -0400 Message-Id: <20190626034117.23247-31-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190626034117.23247-1-sashal@kernel.org> References: <20190626034117.23247-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tzung-Bi Shih [ Upstream commit 70fc53734e71ce51f46dfcfd1a1c319e1cfe080c ] Kernel crashes when an ASoC component rebinding. The dai_link->platforms has been reset to NULL by soc_cleanup_platform() in soc_cleanup_card_resources() when un-registering component. However, it has no chance to re-allocate the dai_link->platforms when registering the component again. Move the DAI pre-links initiation from snd_soc_register_card() to snd_soc_instantiate_card() to make sure all DAI pre-links get initiated when component rebinding. As an example, by using the following commands: - echo -n max98357a > /sys/bus/platform/drivers/max98357a/unbind - echo -n max98357a > /sys/bus/platform/drivers/max98357a/bind Got the error message: "Unable to handle kernel NULL pointer dereference at virtual address". The call trace: snd_soc_is_matching_component+0x30/0x6c soc_bind_dai_link+0x16c/0x240 snd_soc_bind_card+0x1e4/0xb10 snd_soc_add_component+0x270/0x300 snd_soc_register_component+0x54/0x6c Signed-off-by: Tzung-Bi Shih Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- sound/soc/soc-core.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index a4668a788ed5..9df3bdeb5c47 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -2069,6 +2069,16 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card) int ret, i, order; mutex_lock(&client_mutex); + for_each_card_prelinks(card, i, dai_link) { + ret = soc_init_dai_link(card, dai_link); + if (ret) { + soc_cleanup_platform(card); + dev_err(card->dev, "ASoC: failed to init link %s: %d\n", + dai_link->name, ret); + mutex_unlock(&client_mutex); + return ret; + } + } mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT); card->dapm.bias_level = SND_SOC_BIAS_OFF; @@ -2793,26 +2803,9 @@ static int snd_soc_bind_card(struct snd_soc_card *card) */ int snd_soc_register_card(struct snd_soc_card *card) { - int i, ret; - struct snd_soc_dai_link *link; - if (!card->name || !card->dev) return -EINVAL; - mutex_lock(&client_mutex); - for_each_card_prelinks(card, i, link) { - - ret = soc_init_dai_link(card, link); - if (ret) { - soc_cleanup_platform(card); - dev_err(card->dev, "ASoC: failed to init link %s\n", - link->name); - mutex_unlock(&client_mutex); - return ret; - } - } - mutex_unlock(&client_mutex); - dev_set_drvdata(card->dev, card); snd_soc_initialize_card_lists(card); -- 2.20.1