Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7150481ybi; Mon, 8 Jul 2019 15:39:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqy4Lp30mZwa5e4h8L2miPCJxZN+eXLlm/76ZaBP85MELRWaT23BvC39vw2neaPbj1aVNckR X-Received: by 2002:a17:90a:7d09:: with SMTP id g9mr28083046pjl.38.1562625581810; Mon, 08 Jul 2019 15:39:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562625581; cv=none; d=google.com; s=arc-20160816; b=V+rwvb8/R3SQlPq5dHjBYVT+fBzhcAhrVD/cnVh8CDjkh6+c/TIBTHnolS8i0TNwzC l/nPkvMdVaAxJnQ79P2BlkDD5wrbYv+3IoQ74NALYjvw8rxkhjLH+oOFPFYxC8rmqOhR iu+DpAbWzxdt6cCGJxESXBpokqQlfCG7z3f0qjxqRYT9UQUmLWFWMOVg6McF6WQMwNgL r9QfDrmYjL9PAbWPJo5d03vtRtIG3UtVaFcat9+dv5HvXP+qotd11Rie5jD9mQiiZAeh 87yYqG57NGr4iF915z2WJoYj0REBdb3+Jtf6LMcRHVhcgb9W/JIlbD6XAMhOf0E1NW8J wwWA== 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=xJ7KebTeoYstOHwtY17RLUdaedkzGkRF5GcONCJO6kE=; b=jJkiT1QlOSoyMXqFn2fDPiVWeLMsSKxeKz1LKGaHe8ugP11T/fmDDygU1dFQ1knBQz 6GCcJzmJ05CUKe51AzjqvIUxAayGjyHPVGzutmPw9/ZYMqvF9mLX1+hvp6EavKebuCOL 8s3DmPEGHBpaugE5paEAKbpdLbD0PznbWmIwYA6quhWD94MBLcLM0d1fRxzh9+ZFjjGp pTG4Cd7siafJrmI4/Xx0/XC+lis6Lt8flFwtUMFLBQghyWgREIq6mPSOj2PHpRa/6VV2 C/7mBFlYnRIWMIY8U9bwLt1tUXIyVZ+9aUvsqWQj9CjgAmeEQ8C2NgIl+Ow0AUrydXs9 Kreg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qAAnvlLk; 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 m17si8137805pgg.539.2019.07.08.15.39.27; Mon, 08 Jul 2019 15:39:41 -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=qAAnvlLk; 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 S1732433AbfGHPcM (ORCPT + 99 others); Mon, 8 Jul 2019 11:32:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:33708 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390065AbfGHPcJ (ORCPT ); Mon, 8 Jul 2019 11:32:09 -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 BF3D6216C4; Mon, 8 Jul 2019 15:32:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562599928; bh=KTN/ndANs2Qeh0B+53eCPBQqeM5dLons4wh1sPJ3kY4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qAAnvlLkWqARdVOMD3Ke1ZMQem9jNTuJ+maAghtk41r8eifZX8davbhbhWXQx5Ta4 LgYTeb9gZ8g27dOmd3hwHiBA4UVQMzhcsmzCSO+Jwrj8vOeknGPDH4lAgvCRGhDO3j H+O7Q7jsCwcIn0NUMVedA18WEsYyZDgTG6ehHryU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tzung-Bi Shih , Mark Brown , Sasha Levin Subject: [PATCH 5.1 35/96] ASoC: core: move DAI pre-links initiation to snd_soc_instantiate_card Date: Mon, 8 Jul 2019 17:13:07 +0200 Message-Id: <20190708150528.462560432@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190708150526.234572443@linuxfoundation.org> References: <20190708150526.234572443@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 [ 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