From patchwork Thu Oct 12 19:28:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 10002659 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E930760216 for ; Thu, 12 Oct 2017 19:29:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB0F62851A for ; Thu, 12 Oct 2017 19:29:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CFB33286BA; Thu, 12 Oct 2017 19:29:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE, RCVD_IN_SBL, T_DKIM_INVALID, URIBL_SBL autolearn=no version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 230AF28608 for ; Thu, 12 Oct 2017 19:29:17 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 47F84266A73; Thu, 12 Oct 2017 21:29:14 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 6972A266AE1; Thu, 12 Oct 2017 21:29:12 +0200 (CEST) Received: from bh-25.webhostbox.net (bh-25.webhostbox.net [208.91.199.152]) by alsa0.perex.cz (Postfix) with ESMTP id 65312266991 for ; Thu, 12 Oct 2017 21:29:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=roeck-us.net; s=default; h=Message-Id:Date:Subject:Cc:To:From:Sender: Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=5FcMDqpujE5wqdjdfmDDsFDJUHnPL7VvfchAnJB83Qo=; b=ncBxh/mJ4kqrBmJQmdU05f5Ova VGADywxlQtdeTKs9IHHm1R3TNp54ReuNY3A6RFw6J1xKn2u1Qh5vCVNTvaujE3H0HG+eLL4A7ENQA cLpau1QM7B/E+MvqH6TpG+H/7+7DbkaRJtJmCC4kz5kEo653bxLprn0DSy35sL48Cd7h88a+sPDqe t15q0kJUBgKTossmZXvwG+y3S+co5pecde7tIhZ8MeUhZMKgE0ANQaTkCl6KjZfeOLy2DtpneiBa7 IDWSs4yPAOeCa5B3P+2I6/4Wa2XOdaFuRE4QuYNbxO9Qdz/5+pze17Y+kikbfB6xuE0ndzyIiaIgd 3Lk/PijA==; Received: from 108-223-40-66.lightspeed.sntcca.sbcglobal.net ([108.223.40.66]:53754 helo=localhost) by bh-25.webhostbox.net with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.89) (envelope-from ) id 1e2jAD-002er8-Hl; Thu, 12 Oct 2017 19:29:03 +0000 From: Guenter Roeck To: Liam Girdwood Date: Thu, 12 Oct 2017 12:28:59 -0700 Message-Id: <1507836539-26587-1-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 2.7.4 X-Authenticated_sender: linux@roeck-us.net X-OutGoing-Spam-Status: No, score=-1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bh-25.webhostbox.net X-AntiAbuse: Original Domain - alsa-project.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - roeck-us.net X-Get-Message-Sender-Via: bh-25.webhostbox.net: authenticated_id: linux@roeck-us.net X-Authenticated-Sender: bh-25.webhostbox.net: linux@roeck-us.net X-Source: X-Source-Args: X-Source-Dir: Cc: alsa-devel@alsa-project.org, Mengdong Lin , linux-kernel@vger.kernel.org, Takashi Iwai , Mark Brown , Guenter Roeck Subject: [alsa-devel] [PATCH] ASoC: cht_bsw_max98090_ti: Fix NULL pointer dereference while accessing jack X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 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: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP From: Guenter Roeck Commit f2ed6b07645e ("ASoC: Make aux_dev more like a generic component") caused a regression on this driver, since now a kernel oops is seen when the driver is loaded, or more specifically when ts3a227e_enable_jack_detect() is called. That commit changed the probing of aux_devs before checking new DAI links, so cht_max98090_headset_init is now called before cht_codec_init. The kernel crashes due a NULL pointer dereference in cht_max98090_headset_init since there is a call that tries to access the jack pointer which has not been allocated yet. This patch moves the new jack object creation from cht_codec_init to cht_max98090_headset_init, making sure the jack is created before is accessed. Also see upstream commit 5f22449344d9 ("ASoC: rockchip-max98090: Fix NULL pointer dereference while accessing to jack.") for a similar fix in the rockchip-max98090 driver. Fixes: f2ed6b07645e ("ASoC: Make aux_dev more like a generic component") Cc: Mengdong Lin Signed-off-by: Guenter Roeck --- sound/soc/intel/boards/cht_bsw_max98090_ti.c | 55 ++++++++++++++-------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/sound/soc/intel/boards/cht_bsw_max98090_ti.c b/sound/soc/intel/boards/cht_bsw_max98090_ti.c index 20755ecc7f9e..c1518db7bb61 100644 --- a/sound/soc/intel/boards/cht_bsw_max98090_ti.c +++ b/sound/soc/intel/boards/cht_bsw_max98090_ti.c @@ -111,37 +111,12 @@ static struct notifier_block cht_jack_nb = { static int cht_codec_init(struct snd_soc_pcm_runtime *runtime) { - int ret; - int jack_type; struct cht_mc_private *ctx = snd_soc_card_get_drvdata(runtime->card); - struct snd_soc_jack *jack = &ctx->jack; - - /** - * TI supports 4 butons headset detection - * KEY_MEDIA - * KEY_VOICECOMMAND - * KEY_VOLUMEUP - * KEY_VOLUMEDOWN - */ - if (ctx->ts3a227e_present) - jack_type = SND_JACK_HEADPHONE | SND_JACK_MICROPHONE | - SND_JACK_BTN_0 | SND_JACK_BTN_1 | - SND_JACK_BTN_2 | SND_JACK_BTN_3; - else - jack_type = SND_JACK_HEADPHONE | SND_JACK_MICROPHONE; - - ret = snd_soc_card_jack_new(runtime->card, "Headset Jack", - jack_type, jack, NULL, 0); - - if (ret) { - dev_err(runtime->dev, "Headset Jack creation failed %d\n", ret); - return ret; - } if (ctx->ts3a227e_present) - snd_soc_jack_notifier_register(jack, &cht_jack_nb); + snd_soc_jack_notifier_register(&ctx->jack, &cht_jack_nb); - return ret; + return 0; } static int cht_codec_fixup(struct snd_soc_pcm_runtime *rtd, @@ -188,8 +163,32 @@ static int cht_max98090_headset_init(struct snd_soc_component *component) { struct snd_soc_card *card = component->card; struct cht_mc_private *ctx = snd_soc_card_get_drvdata(card); + struct snd_soc_jack *jack = &ctx->jack; + int jack_type; + int ret; + + /* + * TI supports 4 butons headset detection + * KEY_MEDIA + * KEY_VOICECOMMAND + * KEY_VOLUMEUP + * KEY_VOLUMEDOWN + */ + if (ctx->ts3a227e_present) + jack_type = SND_JACK_HEADPHONE | SND_JACK_MICROPHONE | + SND_JACK_BTN_0 | SND_JACK_BTN_1 | + SND_JACK_BTN_2 | SND_JACK_BTN_3; + else + jack_type = SND_JACK_HEADPHONE | SND_JACK_MICROPHONE; + + ret = snd_soc_card_jack_new(card, "Headset Jack", jack_type, jack, + NULL, 0); + if (ret) { + dev_err(card->dev, "Headset Jack creation failed %d\n", ret); + return ret; + } - return ts3a227e_enable_jack_detect(component, &ctx->jack); + return ts3a227e_enable_jack_detect(component, jack); } static const struct snd_soc_ops cht_aif1_ops = {