Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp616915ybz; Sat, 25 Apr 2020 00:29:58 -0700 (PDT) X-Google-Smtp-Source: APiQypIp2lT64kgcSloiLDbr24vKLHTtxvarGKc5TWG/lxvIroQiIZGih8v/LMbIou3o3L7Pa7iG X-Received: by 2002:a05:6402:752:: with SMTP id p18mr11108656edy.261.1587799798561; Sat, 25 Apr 2020 00:29:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587799798; cv=none; d=google.com; s=arc-20160816; b=OwMJWeRcrz7/gGnUoTgqsHBMjYEP3ej1zCjZvxsCeXmkhawmKt8EZh1E5oLX/DQBPB Pct9DxzhsXLxOVqLvNyzUI8KCZvV3EQDpKuK4DuvSOKrijcotQwwSXZOBcOlcprWEMT8 QRiCQKxiXlR08JQOmZCG/LHSeEShEKp0PMYvB3lYPFymPZKV5ddB4Vb4bOl+X9YZ4gZr iKNPYKeEWo6RgG210SPpk7haVkAsUQWOpHEO7tSFgEg/7J3ZUhSKSQWHQR1MWCJOlowI 5SuaE/WykJKIrT8AFQMC7hXqysqx7kaFrVfZZQp+nEkw6EjwZzZKNfCwZsU8qDuv1s1s +2RQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=st/rC8c5asrPeGCaTdiQZXdLYLTdyPGQJdKjiRXKI7k=; b=ixdYhx/P6L08JHCqfhlsPP8K6AVdHOvNuO4/KCfyO5DZn5iHYfaiW3a7hH18BXIuCJ nTbZlSnHvqNz/hEWbA5jPOBTFLRvjaOWLPzPJhHKF1vsKTmQFAG438AsG6u5HqUwzwT+ 4dCNPRVUCsKrm1R9jK0tZgua2DXA8/cET4tw5wMysaz+94ENzKF1o54784zOOUdupcRC DUSx6yxjdCMicjdnudJIiZu+IZ/fsmVCNy38fwjtBtGOiwI4P2Ju+iCfTVMRPh401ECh LH8r20R8vTCBxKzaWL80egQ1rngEQ301yRc0twmfJKje23+KnR4/ckcjVr5G6UDQS2Un GVLw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s15si4594712edr.462.2020.04.25.00.29.35; Sat, 25 Apr 2020 00:29:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726113AbgDYH2N (ORCPT + 99 others); Sat, 25 Apr 2020 03:28:13 -0400 Received: from inva020.nxp.com ([92.121.34.13]:60194 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725837AbgDYH2M (ORCPT ); Sat, 25 Apr 2020 03:28:12 -0400 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id A6E9C1A06DF; Sat, 25 Apr 2020 09:28:10 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 23C031A06D6; Sat, 25 Apr 2020 09:28:06 +0200 (CEST) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id 43266402D5; Sat, 25 Apr 2020 15:28:00 +0800 (SGT) From: Shengjiu Wang To: timur@kernel.org, nicoleotsuka@gmail.com, Xiubo.Lee@gmail.com, festevam@gmail.com, broonie@kernel.org, alsa-devel@alsa-project.org, lgirdwood@gmail.com, perex@perex.cz, tiwai@suse.com Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] ASoC: fsl_easrc: Check for null pointer before dereferencing "ctx" in fsl_easrc_hw_free() Date: Sat, 25 Apr 2020 15:19:29 +0800 Message-Id: X-Mailer: git-send-email 2.7.4 X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The patch 955ac624058f: "ASoC: fsl_easrc: Add EASRC ASoC CPU DAI drivers" from Apr 16, 2020, leads to the following Smatch complaint: sound/soc/fsl/fsl_easrc.c:1529 fsl_easrc_hw_free() warn: variable dereferenced before check 'ctx' (see line 1527) sound/soc/fsl/fsl_easrc.c 1526 struct fsl_asrc_pair *ctx = runtime->private_data; 1527 struct fsl_easrc_ctx_priv *ctx_priv = ctx->private; ^^^^^ Dereference 1528 1529 if (ctx && (ctx_priv->ctx_streams & BIT(substream->stream))) { ^^^ This check is too late, to prevent a NULL dereference. 1530 ctx_priv->ctx_streams &= ~BIT(substream->stream); 1531 fsl_easrc_release_context(ctx); Fixes: 955ac624058f ("ASoC: fsl_easrc: Add EASRC ASoC CPU DAI drivers") Reported-by: Dan Carpenter Signed-off-by: Shengjiu Wang --- sound/soc/fsl/fsl_easrc.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sound/soc/fsl/fsl_easrc.c b/sound/soc/fsl/fsl_easrc.c index 97658e1f4989..20326bffab64 100644 --- a/sound/soc/fsl/fsl_easrc.c +++ b/sound/soc/fsl/fsl_easrc.c @@ -1524,9 +1524,14 @@ static int fsl_easrc_hw_free(struct snd_pcm_substream *substream, { struct snd_pcm_runtime *runtime = substream->runtime; struct fsl_asrc_pair *ctx = runtime->private_data; - struct fsl_easrc_ctx_priv *ctx_priv = ctx->private; + struct fsl_easrc_ctx_priv *ctx_priv; - if (ctx && (ctx_priv->ctx_streams & BIT(substream->stream))) { + if (!ctx) + return -EINVAL; + + ctx_priv = ctx->private; + + if (ctx_priv->ctx_streams & BIT(substream->stream)) { ctx_priv->ctx_streams &= ~BIT(substream->stream); fsl_easrc_release_context(ctx); } -- 2.21.0