From patchwork Tue Apr 26 18:33:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Louis Bossart X-Patchwork-Id: 566139 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id B208EC433F5 for ; Tue, 26 Apr 2022 18:35:13 +0000 (UTC) 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 861B51720; Tue, 26 Apr 2022 20:34:21 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 861B51720 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1650998111; bh=66AUjFfOYOINHgJZ0XxksJPSJ2sDpeMdRDRemZLSKCA=; h=From:To:Subject:Date:Cc:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=NMabGpgvfQvr6/oqhJu7gBbQSTcI4f3lgwtTuZnqIEDdTxMOM0KUq8XVxCSSvJ1SI +ta3encDbI2p5n3uU2Aqu5K647zA/nWGwXmU/92+UvlE4ZEesjdfbgI2RjYBUZdUj7 4iVqpQ+sN54KthvmpPmBGeHi9DlsXHxFf3HGn+LE= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 2CAD9F8014B; Tue, 26 Apr 2022 20:34:21 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 46D49F800FA; Tue, 26 Apr 2022 20:34:20 +0200 (CEST) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id B901AF800FA for ; Tue, 26 Apr 2022 20:34:11 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz B901AF800FA Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="aCOPqf9u" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650998054; x=1682534054; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=66AUjFfOYOINHgJZ0XxksJPSJ2sDpeMdRDRemZLSKCA=; b=aCOPqf9uqDLIN9rlnVhFx014eYvAff/ubJVZ48I0hwvBlny0LCbZDjME uhbpXuPnhUS8BiuND+D2sakUUvUJCmmBK/BFOii5id7qx6Wu09b6BvY+t +6kNQ8iyBAdJ+rZthmKMwt6T76O5UHAUW2dBadNgx008DMZE1ZkK26IkV HW8pGy5Ntm2aRB2n8sTe9yhjIMHMDxBKj8/i+h1ZaoHFJJwcPa88MLjY6 inssYB+6dSgY+vinfA1ZpE/7lgn7si7rz0l8/WAXkaWwsY7E2kE5N5UFD M6EDFO0TaWZEkxpEtvg+Sj02Wxx7rFkqkpvPLr/2tUmMNDjwR9ZQmeC0G Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10329"; a="246249372" X-IronPort-AV: E=Sophos;i="5.90,291,1643702400"; d="scan'208";a="246249372" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2022 11:34:09 -0700 X-IronPort-AV: E=Sophos;i="5.90,291,1643702400"; d="scan'208";a="628656575" Received: from jzhang96-mobl.amr.corp.intel.com (HELO pbossart-mobl3.amr.corp.intel.com) ([10.212.151.202]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2022 11:34:08 -0700 From: Pierre-Louis Bossart To: alsa-devel@alsa-project.org Subject: [PATCH] ASoC: SOF: Fix NULL pointer exception in sof_pci_probe callback Date: Tue, 26 Apr 2022 13:33:57 -0500 Message-Id: <20220426183357.102155-1-pierre-louis.bossart@linux.intel.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Cc: tiwai@suse.de, broonie@kernel.org, Ranjani Sridharan , Ajit Kumar Pandey , Pierre-Louis Bossart 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: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" From: Ajit Kumar Pandey We are accessing "desc->ops" in sof_pci_probe without checking "desc" pointer. This results in NULL pointer exception if pci_id->driver_data i.e desc pointer isn't defined in sof device probe: BUG: kernel NULL pointer dereference, address: 0000000000000060 PGD 0 P4D 0 Oops: 0000 [#1] PREEMPT SMP NOPTI RIP: 0010:sof_pci_probe+0x1e/0x17f [snd_sof_pci] Code: Unable to access opcode bytes at RIP 0xffffffffc043dff4. RSP: 0018:ffffac4b03b9b8d8 EFLAGS: 00010246 Add NULL pointer check for sof_dev_desc pointer to avoid such exception. Reviewed-by: Ranjani Sridharan Signed-off-by: Ajit Kumar Pandey Signed-off-by: Pierre-Louis Bossart --- sound/soc/sof/sof-pci-dev.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sound/soc/sof/sof-pci-dev.c b/sound/soc/sof/sof-pci-dev.c index cd90da7c92c24..8fe8f75446787 100644 --- a/sound/soc/sof/sof-pci-dev.c +++ b/sound/soc/sof/sof-pci-dev.c @@ -187,6 +187,11 @@ int sof_pci_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) dev_dbg(&pci->dev, "PCI DSP detected"); + if (!desc) { + dev_err(dev, "error: no matching PCI descriptor\n"); + return -ENODEV; + } + if (!desc->ops) { dev_err(dev, "error: no matching PCI descriptor ops\n"); return -ENODEV;