From patchwork Sun Dec 16 18:49:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephan Gerhold X-Patchwork-Id: 10732573 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E0B5F1399 for ; Sun, 16 Dec 2018 18:57:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C5D2F29A2E for ; Sun, 16 Dec 2018 18:57:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B963529A31; Sun, 16 Dec 2018 18:57:54 +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=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham 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 EE69C29A2E for ; Sun, 16 Dec 2018 18:57:52 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id BDA21267865; Sun, 16 Dec 2018 19:51:03 +0100 (CET) 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 14B0526796C; Sun, 16 Dec 2018 19:51:01 +0100 (CET) Received: from mo4-p00-ob.smtp.rzone.de (mo4-p00-ob.smtp.rzone.de [81.169.146.217]) by alsa0.perex.cz (Postfix) with ESMTP id 17D1F2677E4 for ; Sun, 16 Dec 2018 19:50:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1544986258; s=strato-dkim-0002; d=gerhold.net; h=Message-Id:Date:Subject:Cc:To:From:X-RZG-CLASS-ID:X-RZG-AUTH:From: Subject:Sender; bh=eZub23VE+sNG1GKDGyzW8sAe71+WlW1bPV07M7jOpGc=; b=lnD0NN9zR22N7LmG9ub+ma4B/yeNwGi6L35a0tu254cIxyhCVYvb9F9YsqOPaRwyNy 6NGBM+yxy1CTJYBenf3Gls4JHAMkKCBz0QfE/Gib+frRDadgkeLiDlEg0F/ZfN7Yujna ymhPrE2se7Rhz1AZaZmBlDi6PQJ5awpho1TUXixT3cw7t4fp3H92z9lvg/RRTJShnE98 05Gqnvq+zvoqHSF6YpMrYS2MPqwPJgSs+TiFSeNm6QxukAFPitlCaP8m9iMx3A3BUrmH MHGzck5KqS+j/jbQVfsSagfUl8G9Lq9mgd2Auq3e3EkdJbdWi6SD7zXwXt4Ei6U3826Y x+Bg== X-RZG-AUTH: ":P3gBZUipdd93FF5ZZvYFPugejmSTVR2nRPhVORvLd4SsytBXQrEOHTIXsMrxqxFbAyY=" X-RZG-CLASS-ID: mo00 Received: from localhost.localdomain by smtp.strato.de (RZmta 44.8 AUTH) with ESMTPSA id D088fauBGIouCCS (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Sun, 16 Dec 2018 19:50:56 +0100 (CET) From: Stephan Gerhold To: Pierre-Louis Bossart , Mark Brown Date: Sun, 16 Dec 2018 19:49:56 +0100 Message-Id: <20181216184955.20192-1-stephan@gerhold.net> X-Mailer: git-send-email 2.20.0 MIME-Version: 1.0 Cc: Liam Girdwood , Hans de Goede , alsa-devel@alsa-project.org, Jie Yang , Stephan Gerhold Subject: [alsa-devel] [PATCH] ASoC: Intel: sst: Delay machine device creation until after initialization 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: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP Right now, the machine devices are created early, before the SST context is initialized. This means that SST might not be fully initialized if sst_acpi_probe() fails later on (e.g. after sst_platform_get_resources() if the IRQ does not exist). However, at least sst-mfld-platform assumes that sst_register_dsp() was called to set the (global) "sst" device pointer, which happens only later in sst_acpi_probe() when sst_context_init() is called. This may cause a NULL pointer dereference later when the ALSA device is first opened: BUG: unable to handle kernel NULL pointer dereference at 0000000000000008 PGD 0 P4D 0 Oops: 0000 [#1] PREEMPT SMP PTI CPU: 0 PID: 790 Comm: pulseaudio Not tainted 4.20.0-rc6-mainline-00161-g6531e115b7ab #1 Hardware name: ASUSTeK COMPUTER INC. ME176C/ME176C, BIOS 5.6.5 09/16/2015 RIP: 0010:sst_handle_vb_timer+0x61/0x1b0 [snd_soc_sst_atom_hifi2_platform] Code: 44 24 04 e9 84 00 00 00 31 c9 c7 04 24 ff ff ff ff 66 89 4c 24 06 84 db 0f 84 90 00 00 00 48 8b 05 c4 23 01 00 be 01 00 00 00 <48> 8b 78 08 48 8b 40 10 48 8b 40 48 e8 2e 5e d7 f0 89 c3 85 c0 78 RSP: 0018:ffff9d968099fa30 EFLAGS: 00010202 RAX: 0000000000000000 RBX: 0000000000000001 RCX: 0000000000000000 RDX: 0000000080000001 RSI: 0000000000000001 RDI: 00000000ffffffff RBP: ffff968d33384618 R08: 0000000000000001 R09: 00000000000002e3 R10: ffff968d333a0800 R11: 0000000000000000 R12: ffff968d34bc7c00 R13: ffff968d333a3eb0 R14: 0000000000000001 R15: ffff968d333a08c0 FS: 00007f63a7e7b200(0000) GS:ffff968d37600000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000008 CR3: 00000000297b8000 CR4: 00000000001006f0 Call Trace: sst_enable_ssp+0x24/0x40 [snd_soc_sst_atom_hifi2_platform] soc_pcm_open+0xeb/0x960 [snd_soc_core] ? __debugfs_create_file+0xcd/0x120 dpcm_be_dai_startup+0x183/0x3c0 [snd_soc_core] dpcm_fe_dai_open+0x10c/0xab0 [snd_soc_core] snd_pcm_open_substream+0x7f/0x140 [snd_pcm] snd_pcm_open+0xe6/0x220 [snd_pcm] ? wake_up_q+0x70/0x70 snd_pcm_playback_open+0x3d/0x70 [snd_pcm] chrdev_open+0xa3/0x1b0 ? cdev_put.part.0+0x20/0x20 do_dentry_open+0x12f/0x350 path_openat+0x2d1/0x14e0 ? inotify_handle_event+0x17b/0x1e0 do_filp_open+0x93/0x100 ? snd_card_file_remove+0x14b/0x170 [snd] ? __check_object_size+0x102/0x189 ? _raw_spin_unlock+0x12/0x30 do_sys_open+0x186/0x210 do_syscall_64+0x55/0x160 entry_SYSCALL_64_after_hwframe+0x44/0xa9 RIP: 0033:0x7f63a992f4c2 Code: 25 00 00 41 00 3d 00 00 41 00 74 4c 48 8d 05 85 70 0d 00 8b 00 85 c0 75 6d 89 f2 b8 01 01 00 00 48 89 fe bf 9c ff ff ff 0f 05 <48> 3d 00 f0 ff ff 0f 87 a2 00 00 00 48 8b 4c 24 28 64 48 33 0c 25 RSP: 002b:00007ffe71196b70 EFLAGS: 00000246 ORIG_RAX: 0000000000000101 RAX: ffffffffffffffda RBX: 0000000000080802 RCX: 00007f63a992f4c2 RDX: 0000000000080802 RSI: 00007ffe71196d20 RDI: 00000000ffffff9c RBP: 00000000ffffffff R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 00007ffe71196c00 R13: 0000000000000004 R14: 00007ffe71196d20 R15: 0000558466055a80 CR2: 0000000000000008 ---[ end trace 34534a02650ee26c ]--- This can be avoided if the machine device creation is delayed in sst_acpi_probe() until after sst_context_init(), when sst_register_dsp() is guaranteed to have already been called. Signed-off-by: Stephan Gerhold --- An other option to fix this would be to add proper NULL checks in the probe method of sst-mfld-platform and/or sst_enable_ssp(). Maybe this should be done additionally, but at least in my opinion there is not much point in registering the machine devices if they end up being broken anyway. sound/soc/intel/atom/sst/sst_acpi.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/sound/soc/intel/atom/sst/sst_acpi.c b/sound/soc/intel/atom/sst/sst_acpi.c index ac542535b9d5..493d32923815 100644 --- a/sound/soc/intel/atom/sst/sst_acpi.c +++ b/sound/soc/intel/atom/sst/sst_acpi.c @@ -345,6 +345,18 @@ static int sst_acpi_probe(struct platform_device *pdev) mach->mach_params.acpi_ipc_irq_index = pdata->res_info->acpi_ipc_irq_index; + /* Fill sst platform data */ + ctx->pdata = pdata; + strcpy(ctx->firmware_name, mach->fw_filename); + + ret = sst_platform_get_resources(ctx); + if (ret) + return ret; + + ret = sst_context_init(ctx); + if (ret < 0) + return ret; + plat_dev = platform_device_register_data(dev, pdata->platform, -1, NULL, 0); if (IS_ERR(plat_dev)) { @@ -365,18 +377,6 @@ static int sst_acpi_probe(struct platform_device *pdev) return PTR_ERR(mdev); } - /* Fill sst platform data */ - ctx->pdata = pdata; - strcpy(ctx->firmware_name, mach->fw_filename); - - ret = sst_platform_get_resources(ctx); - if (ret) - return ret; - - ret = sst_context_init(ctx); - if (ret < 0) - return ret; - sst_configure_runtime_pm(ctx); platform_set_drvdata(pdev, ctx); return ret;