From nobody Tue Apr 28 06:25:56 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0D1CC43334 for ; Fri, 3 Jun 2022 20:23:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346334AbiFCUXK (ORCPT ); Fri, 3 Jun 2022 16:23:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240755AbiFCUXJ (ORCPT ); Fri, 3 Jun 2022 16:23:09 -0400 X-Greylist: delayed 484 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Fri, 03 Jun 2022 13:23:07 PDT Received: from mail.tpi.com (mail.tpi.com [50.126.108.186]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 998B743AE6; Fri, 3 Jun 2022 13:23:07 -0700 (PDT) Received: from sushi.tpi.com (sushi.tpi.com [10.0.0.212]) by mail.tpi.com (Postfix) with ESMTPA id 55DBD47EC7EC; Fri, 3 Jun 2022 13:15:01 -0700 (PDT) From: Dean Gehnert To: linux-kernel@vger.kernel.org Cc: Dean Gehnert , Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , alsa-devel@alsa-project.org, stable@vger.kernel.org Subject: [PATCH] ASoC: topology: Avoid card NULL deref in snd_soc_tplg_component_remove() Date: Fri, 3 Jun 2022 13:14:25 -0700 Message-Id: <20220603201425.2590-1-deang@tpi.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Don't deference card in comp->card->snd_card before checking for NULL card. During the unloading of ASoC kernel modules, there is a kernel oops in snd_soc_tplg_component_remove() that happens because comp->card is set to NULL in soc_cleanup_component(). Cc: Liam Girdwood Cc: Mark Brown Cc: Jaroslav Kysela Cc: Takashi Iwai Cc: alsa-devel@alsa-project.org Cc: linux-kernel@vger.kernel.org Cc: stable@vger.kernel.org Fixes: 7e567b5ae063 ("ASoC: topology: Add missing rwsem around snd_ctl_remo= ve() calls") Signed-off-by: Dean Gehnert --- sound/soc/soc-topology.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index 3f9d314fba16..cf0efe1147c2 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -2613,15 +2613,18 @@ EXPORT_SYMBOL_GPL(snd_soc_tplg_component_load); /* remove dynamic controls from the component driver */ int snd_soc_tplg_component_remove(struct snd_soc_component *comp) { - struct snd_card *card =3D comp->card->snd_card; + struct snd_card *card; struct snd_soc_dobj *dobj, *next_dobj; int pass; =20 /* process the header types from end to start */ for (pass =3D SOC_TPLG_PASS_END; pass >=3D SOC_TPLG_PASS_START; pass--) { =20 + card =3D (comp->card) ? comp->card->snd_card : NULL; + /* remove mixer controls */ - down_write(&card->controls_rwsem); + if (card) + down_write(&card->controls_rwsem); list_for_each_entry_safe(dobj, next_dobj, &comp->dobj_list, list) { =20 @@ -2660,7 +2663,8 @@ int snd_soc_tplg_component_remove(struct snd_soc_comp= onent *comp) break; } } - up_write(&card->controls_rwsem); + if (card) + up_write(&card->controls_rwsem); } =20 /* let caller know if FW can be freed when no objects are left */ --=20 2.17.1