From patchwork Wed Nov 27 11:06:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gabbasov, Andrew" X-Patchwork-Id: 11263849 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6A54E6C1 for ; Wed, 27 Nov 2019 11:07:56 +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 85FC92053B for ; Wed, 27 Nov 2019 11:07:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="ILVXqhxU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 85FC92053B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=mentor.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 DA56C16FB; Wed, 27 Nov 2019 12:07:02 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz DA56C16FB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1574852873; bh=NvlVQyg40knZWqXXhStcvwM0WVAdveOTLhu9e7rqFCE=; h=From:To:Date:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=ILVXqhxUBque7oHDuY1cSSorbhV3KwORo1OGfOCw2/UUPv0BK8Tbj5+RN34iGX0lN VYx7CX9xoqAJumAXpePXwm5gIG0YArPwID+bw4/4mRggltIZljpKLNXEgYH5Ou97CB 2Ou/V7lYGQ+1cbXFMOl2sQv23MMjXT6Dyh3Lrz8Q= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 4FA78F800CE; Wed, 27 Nov 2019 12:07:02 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id BEA9BF8014D; Wed, 27 Nov 2019 12:07:00 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on alsa1.perex.cz X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=PRX_BODY_76,SPF_HELO_NONE, SPF_PASS autolearn=disabled version=3.4.0 Received: from esa3.mentor.iphmx.com (esa3.mentor.iphmx.com [68.232.137.180]) (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 37F06F800CE for ; Wed, 27 Nov 2019 12:06:56 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 37F06F800CE IronPort-SDR: Ffl5xjbWYZSJTNusHvJ1OX412QmOISR0YJSAAJVejLXTMqCFa4Ax2V1h0IMwSOebCBEC4gZ37p Zg0qFO5XQzvKeIrSB8gHNdaGVAVSmc6WfZqQAESgVgWaF4vpcDQGVnAe1vkhR2ieY8hDcYkk0+ XmgNIS8UsTpFGPzzz1ECDiSf7X5Jg/JT8AMZ3RrEO9rAtM+Av7hgmwbwEHT4YodSLiD8ti7YBd gzhi8BA8GsEhJqcZTVCPhN173pXaV2ec/6TTbLIVHdUAP/CEXT/mr1fJaLqAKgdXColYsdwusC xC4= X-IronPort-AV: E=Sophos;i="5.69,249,1571731200"; d="scan'208";a="43561050" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 27 Nov 2019 03:06:53 -0800 IronPort-SDR: u9bLZta3qFDdDn6N2mrrxy/SSduvpuQXHCs4GzEAimH8hT9GV/ZDtuYTMeaNTxiKsxAJe7CtJP zUihfbkrxFMmtK5aDg68fMXYy/NQ1FAx7FzEsguO69B+ZeJn//7bunzdnv0ZcUmPEx0P1xp9iJ HJZLf2XdThAbRjL0eKSq4qBai6cke5owvWvF105W965Olfp6EzEnvtW7yHhyAeE3wuAHTi369n SG+QXifuJMQ2gL3iR7fr16+D9IKsU3c4jA/fnY5MXsGDbm6fCHmcZHXdYQ0TIqkWqEB1f9iPVT 9X8= From: Andrew Gabbasov To: , , Jaroslav Kysela , Takashi Iwai , Eugeniu Rosca , Timo Wischer , Andrew Gabbasov Date: Wed, 27 Nov 2019 05:06:22 -0600 Message-ID: <20191127110622.26105-1-andrew_gabbasov@mentor.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-02.mgc.mentorg.com (139.181.222.2) To svr-ies-mbx-02.mgc.mentorg.com (139.181.222.2) Subject: [alsa-devel] [PATCH] ALSA: aloop: Avoid pointer dereference before null-check 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" Static analysis tools (cppcheck and PVS Studio) report an error in loopback_snd_timer_period_elapsed() regarding dpcm_play pointer dereference earlier than its null-check. And although this is a result of a formal check, and the pointer correctness is also protected by having a corresponding bit set in the "running" mask, re-ordering of the lines can imake the code even formally correct and eliminate those static analysis error reports. Fixes: 26c53379f98d ("ALSA: aloop: Support selection of snd_timer instead of jiffies") Reported-by: Eugeniu Rosca Signed-off-by: Andrew Gabbasov --- sound/drivers/aloop.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sound/drivers/aloop.c b/sound/drivers/aloop.c index 0ebfbe70db00..6bb46423f5ae 100644 --- a/sound/drivers/aloop.c +++ b/sound/drivers/aloop.c @@ -727,10 +727,6 @@ static void loopback_snd_timer_period_elapsed(struct loopback_cable *cable, dpcm_play = cable->streams[SNDRV_PCM_STREAM_PLAYBACK]; dpcm_capt = cable->streams[SNDRV_PCM_STREAM_CAPTURE]; - substream_play = (running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) ? - dpcm_play->substream : NULL; - substream_capt = (running & (1 << SNDRV_PCM_STREAM_CAPTURE)) ? - dpcm_capt->substream : NULL; if (event == SNDRV_TIMER_EVENT_MSTOP) { if (!dpcm_play || @@ -741,6 +737,10 @@ static void loopback_snd_timer_period_elapsed(struct loopback_cable *cable, } } + substream_play = (running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) ? + dpcm_play->substream : NULL; + substream_capt = (running & (1 << SNDRV_PCM_STREAM_CAPTURE)) ? + dpcm_capt->substream : NULL; valid_runtime = (running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) ? dpcm_play->substream->runtime : dpcm_capt->substream->runtime;