From patchwork Wed Mar 31 01:02:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liao, Bard" X-Patchwork-Id: 412907 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=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 79A1EC433C1 for ; Wed, 31 Mar 2021 01:04:37 +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 CE87C61883 for ; Wed, 31 Mar 2021 01:04:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CE87C61883 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com 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 A21961673; Wed, 31 Mar 2021 03:03:43 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz A21961673 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1617152673; bh=iX2kwWgSk1/QC87XkRwNrdEmKai8Hhjb6rIW8C4dOPc=; h=From:To:Subject:Date:Cc:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=WhNM228UauHQgg8F+8mTStueNk6skmhaEjA+RM70hH5ji4NXSbc2VOuutkWNcjH7g 3SwjrDsnwrN7FH1vhFWavePTfCxIEeH0Ce/rGnSnI22kRoQ8tbHUnCzO8QDnpLtNHF JKjOiqGCnVGgHvReEbG3KymfauUfu7XA1cyDGVXY= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 36D8EF8023E; Wed, 31 Mar 2021 03:03:43 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 2A315F80240; Wed, 31 Mar 2021 03:03:42 +0200 (CEST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 76F55F80141 for ; Wed, 31 Mar 2021 03:03:29 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 76F55F80141 IronPort-SDR: BzfYW5oJ1qSGzyL5+GBjNcVNaH/T9ys9uttx+XbOpu9wxoCqN6IG5vqHEuWxRtR59ZcMZ4AA68 M0pWnoLAixZQ== X-IronPort-AV: E=McAfee;i="6000,8403,9939"; a="188628359" X-IronPort-AV: E=Sophos;i="5.81,291,1610438400"; d="scan'208";a="188628359" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2021 18:03:01 -0700 IronPort-SDR: W1H3FstvuZ72pE56Mky52VbKZbMWhYDK+3MgGyltDYYnwwU8LDJ+6sWPg9quL2uj7xLN6c8Wm4 ClcYGJk2KMNQ== X-IronPort-AV: E=Sophos;i="5.81,291,1610438400"; d="scan'208";a="411887968" Received: from bard-ubuntu.sh.intel.com ([10.239.13.33]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2021 18:02:58 -0700 From: Bard Liao To: alsa-devel@alsa-project.org, vkoul@kernel.org Subject: [PATCH] soundwire: intel_init: test link->cdns Date: Wed, 31 Mar 2021 09:02:50 +0800 Message-Id: <20210331010250.14151-1-yung-chuan.liao@linux.intel.com> X-Mailer: git-send-email 2.17.1 Cc: vinod.koul@linaro.org, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, pierre-louis.bossart@linux.intel.com, hui.wang@canonical.com, sanyog.r.kale@intel.com, rander.wang@linux.intel.com, bard.liao@intel.com 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" intel_link_probe() could return error and dev_get_drvdata() will return null in such case. So we have to test link->cdns after link->cdns = dev_get_drvdata(&ldev->auxdev.dev); Otherwise, we will meet the "kernel NULL pointer dereference" error. Signed-off-by: Bard Liao Reviewed-by: Ranjani Sridharan Reviewed-by: Rander Wang Reviewed-by: Pierre-Louis Bossart --- drivers/soundwire/intel_init.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/soundwire/intel_init.c b/drivers/soundwire/intel_init.c index 5b32a2ffd376..5ef5bd0defab 100644 --- a/drivers/soundwire/intel_init.c +++ b/drivers/soundwire/intel_init.c @@ -250,6 +250,15 @@ static struct sdw_intel_ctx link = &ldev->link_res; link->cdns = dev_get_drvdata(&ldev->auxdev.dev); + if (!link->cdns) { + dev_err(&adev->dev, "failed to get link->cdns\n"); + /* + * 1 will be subtracted from i in the err label, but we need to call + * intel_link_dev_unregister for this ldev, so plus 1 now + */ + i++; + goto err; + } list_add_tail(&link->list, &ctx->link_list); bus = &link->cdns->bus; /* Calculate number of slaves */