From patchwork Sat Sep 5 19:26:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Rix X-Patchwork-Id: 251126 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=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 77BA4C43461 for ; Sat, 5 Sep 2020 19:27:23 +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 DE7D620757 for ; Sat, 5 Sep 2020 19:27:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="ZLG9U/j2"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="P0QsSNVr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DE7D620757 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.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 12E12187D; Sat, 5 Sep 2020 21:26:30 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 12E12187D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1599334040; bh=zHRy5LjMBHe7xy2lmWGbKR36yvxGbIjufDIZMPZ5EVo=; h=From:To:Subject:Date:Cc:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=ZLG9U/j2++E+V7fOuPetaTM7IsKo33Qg8uepuEYIINumsbSXK1qi4j92P1rGxG4ds tJ1ffv1cboyEL5Ze9VHOJ0lmW3tCnpONtQ/zfZwqT6VhSknDlfVzw7swuOmiC+YUf1 y953q1+54FQMad8J7+fR+uqHThWlpo8uvUCQoD3U= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 9388DF800B4; Sat, 5 Sep 2020 21:26:29 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id B6ABDF80217; Sat, 5 Sep 2020 21:26:27 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id B4AEEF801DA for ; Sat, 5 Sep 2020 21:26:24 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz B4AEEF801DA Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="P0QsSNVr" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599333982; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type; bh=pFLFpRHDE4JFudYeKR0yB2Nja5ud5d8SymFz+afFxk4=; b=P0QsSNVrH7hdMUsY1av/mh6b11sA0xInL65BhO7Ls4beKQsZLKgxny5JTO4ibkwfKShUIL 4lO+IWpdgUMPUcjfDs9t3UbJdzev0EMldxu2ZwtK11ZLZi2NSF1DA3VhtZxHIaZ1ADXeaG st8i0Q2VUF+3uap7WT12iil9qlytP40= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-116-DkEe7tcfO7CUlDkgAWwuVg-1; Sat, 05 Sep 2020 15:26:20 -0400 X-MC-Unique: DkEe7tcfO7CUlDkgAWwuVg-1 Received: by mail-qv1-f72.google.com with SMTP id h9so686341qvr.3 for ; Sat, 05 Sep 2020 12:26:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=pFLFpRHDE4JFudYeKR0yB2Nja5ud5d8SymFz+afFxk4=; b=iYdjWhvWyD0HwitBsYIkC2mHi11yiyE8iqBejCSW+IAWzsX1LFIy0cPEwwA55L0RRY wo36eWsN/Rg5bZK2BT5qj/Pw/EbvTXHZeN2rR2UdtpYJ+BX8fvsomjs5NxSdx83T8N5L I03YS1RDtAZWNpxKckL3TVfGEkQMa6npC65ou3lmssutZB53ZNs6b0gpaLJvAFk90PgJ +NDMGC6/f+DxLJu5uiuV/lg1M0E6hzXLHQAxklo5bhTqzcIYbbwZMUwJ/z5swqO6d90V AVdz8CskKNZufky0EGaUhnlPqH9DqueIpXtE8droejAI1xpRciM6esQJEidWg/QGIYOU HNEQ== X-Gm-Message-State: AOAM5309rsMIt+snN+23jJhYvbDHsQPfCPzgdYs/M1CzVVO6Vm0sdQ/V ZQs58q9sssY4yncGlqV+8N0kZry5m2OXBuvDgLOZ39Ta3SLKavuth9bZxwfJgGnFj6y2O05snCa RMjpxU0MJpN4ycBtQRuXG3EY= X-Received: by 2002:ac8:34f2:: with SMTP id x47mr14259678qtb.282.1599333979981; Sat, 05 Sep 2020 12:26:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxpdiOw+3OCNQl3hZuFU+GukyxntgmDBJOZyso2aT1TQk3zSgsC1G1xvVExkVKxfw9qtEFPhQ== X-Received: by 2002:ac8:34f2:: with SMTP id x47mr14259643qtb.282.1599333979497; Sat, 05 Sep 2020 12:26:19 -0700 (PDT) Received: from trix.remote.csb (075-142-250-213.res.spectrum.com. [75.142.250.213]) by smtp.gmail.com with ESMTPSA id 134sm2389199qkj.53.2020.09.05.12.26.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Sep 2020 12:26:18 -0700 (PDT) From: trix@redhat.com To: vkoul@kernel.org, yung-chuan.liao@linux.intel.com, pierre-louis.bossart@linux.intel.com, sanyog.r.kale@intel.com, natechancellor@gmail.com, ndesaulniers@google.com, guennadi.liakhovetski@linux.intel.com, kai.vehmanen@linux.intel.com Subject: [PATCH] soundwire: stream: fix an invalid free Date: Sat, 5 Sep 2020 12:26:13 -0700 Message-Id: <20200905192613.420-1-trix@redhat.com> X-Mailer: git-send-email 2.18.1 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=trix@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Cc: clang-built-linux@googlegroups.com, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Tom Rix 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: Tom Rix clang static analyzer reports this problem stream.c:872:2: warning: Argument to kfree() is a constant address (18446744073709551092), which is not memory allocated by malloc() kfree(stream); ^~~~~~~~~~~~~ In sdw_shutdown_stream() the stream to free is set by a call to snd_soc_dai_get_sdw_stream(). The problem block is the check if the call was successful. if (!sdw_stream) { dev_err(rtd->dev, "no stream found... return; } When snd_soc_dai_get_sdw_stream() fails, it does not always return null, sometimes it returns -ENOTSUPP. So also check for error codes. Fixes: 4550569bd779 ("soundwire: stream: add helper to startup/shutdown streams") Signed-off-by: Tom Rix --- drivers/soundwire/stream.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c index 6e36deb505b1..950231d593c2 100644 --- a/drivers/soundwire/stream.c +++ b/drivers/soundwire/stream.c @@ -1913,7 +1913,7 @@ void sdw_shutdown_stream(void *sdw_substream) sdw_stream = snd_soc_dai_get_sdw_stream(dai, substream->stream); - if (!sdw_stream) { + if (IS_ERR_OR_NULL(sdw_stream)) { dev_err(rtd->dev, "no stream found for DAI %s", dai->name); return; }