From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E692C2D0C3 for ; Mon, 30 Dec 2019 07:12:28 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9BEFB20718 for ; Mon, 30 Dec 2019 07:12:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="iuUz12zh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9BEFB20718 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id D804516D3; Mon, 30 Dec 2019 08:11:35 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz D804516D3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1577689945; bh=vqWKNUXg397TUfAP2ux0Jtw6IGaU43AmkhlLLXZHu2A=; h=Date:From:To:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=iuUz12zh7OOWyfVokzCooVnVsUnsh6TDTt8brGf4Ot+JuRluZCgY42wpDleKsP/bh a0XBIq6c70ZIThmTB1o23o92FFcR9n/jWEQFddH2xLZHw8Javtdf9pv4PbFs5PijLr ZkArTWWhDshld57l8gNT1xyl9Qs+qVU4PCPM9G+s= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 48FC5F8015C; Mon, 30 Dec 2019 08:11:35 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 00C1FF8015D; Mon, 30 Dec 2019 08:11:33 +0100 (CET) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 8BB27F8011E for ; Mon, 30 Dec 2019 08:11:31 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 8BB27F8011E X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 8B7B9B26D; Mon, 30 Dec 2019 07:11:30 +0000 (UTC) Date: Mon, 30 Dec 2019 08:11:30 +0100 Message-ID: From: Takashi Iwai To: Dmitry Osipenko In-Reply-To: <20191229150454.2127-1-digetx@gmail.com> References: <20191229150454.2127-1-digetx@gmail.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Cc: Oder Chiou , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Takashi Iwai , Liam Girdwood , Mark Brown , Thierry Reding , linux-tegra@vger.kernel.org, Bard Liao , Jonathan Hunter Subject: Re: [alsa-devel] [PATCH v1] ASoC: rt5640: Fix NULL dereference on module unload X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" On Sun, 29 Dec 2019 16:04:54 +0100, Dmitry Osipenko wrote: > > The rt5640->jack is NULL if jack is already disabled at the time of > driver's module unloading. > > Unable to handle kernel NULL pointer dereference at virtual address 00000024 > ... > (rt5640_set_jack [snd_soc_rt5640]) from [] (snd_soc_component_set_jack+0x11/0x1c [snd_soc_core]) > (snd_soc_component_set_jack [snd_soc_core]) from [] (soc_remove_component+0x1b/0x54 [snd_soc_core]) > (soc_remove_component [snd_soc_core]) from [] (soc_cleanup_card_resources+0xad/0x1cc [snd_soc_core]) > (soc_cleanup_card_resources [snd_soc_core]) from [] (snd_soc_unregister_card+0x47/0x78 [snd_soc_core]) > (snd_soc_unregister_card [snd_soc_core]) from [] (tegra_rt5640_remove+0x13/0x1c [snd_soc_tegra_rt5640]) > (tegra_rt5640_remove [snd_soc_tegra_rt5640]) from [] (platform_drv_remove+0x17/0x24) > (platform_drv_remove) from [] (device_release_driver_internal+0x95/0x114) > (device_release_driver_internal) from [] (driver_detach+0x4d/0x90) > (driver_detach) from [] (bus_remove_driver+0x31/0x70) > (bus_remove_driver) from [] (tegra_rt5640_driver_exit+0x9/0xdf4 [snd_soc_tegra_rt5640]) > (tegra_rt5640_driver_exit [snd_soc_tegra_rt5640]) from [] (sys_delete_module+0xe7/0x184) > (sys_delete_module) from [] (ret_fast_syscall+0x1/0x28) > > Signed-off-by: Dmitry Osipenko > --- > sound/soc/codecs/rt5640.c | 22 ++++++++++++++-------- > 1 file changed, 14 insertions(+), 8 deletions(-) > > diff --git a/sound/soc/codecs/rt5640.c b/sound/soc/codecs/rt5640.c > index adbae1f36a8a..b245c44cafbc 100644 > --- a/sound/soc/codecs/rt5640.c > +++ b/sound/soc/codecs/rt5640.c > @@ -2432,16 +2432,22 @@ static void rt5640_disable_jack_detect(struct snd_soc_component *component) > { > struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component); > > - disable_irq(rt5640->irq); > - rt5640_cancel_work(rt5640); > + /* > + * soc_remove_component() force-disables jack and thus rt5640->jack > + * could be NULL at the time of driver's module unloading. > + */ > + if (rt5640->jack) { > + disable_irq(rt5640->irq); > + rt5640_cancel_work(rt5640); > > - if (rt5640->jack->status & SND_JACK_MICROPHONE) { > - rt5640_disable_micbias1_ovcd_irq(component); > - rt5640_disable_micbias1_for_ovcd(component); > - snd_soc_jack_report(rt5640->jack, 0, SND_JACK_BTN_0); > - } > + if (rt5640->jack->status & SND_JACK_MICROPHONE) { > + rt5640_disable_micbias1_ovcd_irq(component); > + rt5640_disable_micbias1_for_ovcd(component); > + snd_soc_jack_report(rt5640->jack, 0, SND_JACK_BTN_0); > + } > > - rt5640->jack = NULL; > + rt5640->jack = NULL; > + } > } I guess it's simpler just returning if rt5640->jack is already NULL. --- a/sound/soc/codecs/rt5640.c +++ b/sound/soc/codecs/rt5640.c @@ -2432,6 +2432,10 @@ static void rt5640_disable_jack_detect(struct snd_soc_component *component) { struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component); + /* already disabled? */ + if (!rt5640->jack) + return; + disable_irq(rt5640->irq); rt5640_cancel_work(rt5640); thanks, Takashi _______________________________________________ Alsa-devel mailing list Alsa-devel@alsa-project.org https://mailman.alsa-project.org/mailman/listinfo/alsa-devel