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 1022CC7EE30 for ; Fri, 3 Mar 2023 21:48:16 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id EFA3BE7E; Fri, 3 Mar 2023 22:47:18 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz EFA3BE7E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1677880089; bh=835pITj3L+K0+nJB6m2dMarsglz50CzJfHG+9XJm0Oc=; h=From:To:Subject:Date:In-Reply-To:References:CC:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=RWrIm/FHaPrcprirBz4PAcmp6aCacLvN2dytiT8Si3M5+ZFoVYtjQTRu7q7QATQ5D iRO136aEPFaiR4eQU6hHK3M16a/wE2OTsKKGOKPrJs9/HSOlzx7qX5UqdqpJNf0GxC QkHLRjhWA+zSnyMEXo3GO1WHZNtkzexX6Dy3YnKg= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 9DB97F804FE; Fri, 3 Mar 2023 22:47:18 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 18A79F804FE; Fri, 3 Mar 2023 22:47:16 +0100 (CET) Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 51FB2F80266 for ; Fri, 3 Mar 2023 22:47:14 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 51FB2F80266 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=c92s2Nps Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 417876195F; Fri, 3 Mar 2023 21:47:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 507EAC4339E; Fri, 3 Mar 2023 21:47:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1677880033; bh=835pITj3L+K0+nJB6m2dMarsglz50CzJfHG+9XJm0Oc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c92s2NpsHh8wy2e9kzPgzHhwP+Ok4JblK8opuYgbY/geuX/NqIsOu5/inkSZugxBh 2uKFdeODS9X8weOIoB0RL4k1+EPQ2Mr8vehrbiIozBDcQXj7ja/l5vXdsIHqWpITCY 2Zn6Ua22TleklAe6ttCNxQp8BDTUSgJi37f03OjjQUSddjYhap++BWmd8D09Lgg9aP 2+2qL10TdMKgrAY2rKJDezGgOgRdjQ5GwTkcIEqyPOipSuakOFNjjXxOVtWoG7T65G OURVY2xUKFiMytJi1HPyI15XFGt5hjHNYwVvRqnfGN/ekEkjK3eArSF82vqB5edDU1 2JvKHt2DDNQPw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH AUTOSEL 5.15 49/50] soundwire: cadence: Remove wasted space in response_buf Date: Fri, 3 Mar 2023 16:45:30 -0500 Message-Id: <20230303214531.1450154-49-sashal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230303214531.1450154-1-sashal@kernel.org> References: <20230303214531.1450154-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Message-ID-Hash: D2BFFQYWZTMUNMSRJNHTZFXWD55VIEZZ X-Message-ID-Hash: D2BFFQYWZTMUNMSRJNHTZFXWD55VIEZZ X-MailFrom: sashal@kernel.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Richard Fitzgerald , Pierre-Louis Bossart , Vinod Koul , Sasha Levin , yung-chuan.liao@linux.intel.com, alsa-devel@alsa-project.org X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Richard Fitzgerald [ Upstream commit 827c32d0df4bbe0d1c47d79f6a5eabfe9ac75216 ] The response_buf was declared much larger (128 entries) than the number of responses that could ever be written into it. The Cadence IP is configurable up to a maximum of 32 entries, and the datasheet says that RX_FIFO_AVAIL can be 2 larger than this. So allow up to 34 responses. Also add checking in cdns_read_response() to prevent overflowing reponse_buf if RX_FIFO_AVAIL contains an unexpectedly large number. Signed-off-by: Richard Fitzgerald Reviewed-by: Pierre-Louis Bossart Link: https://lore.kernel.org/r/20221202161812.4186897-3-rf@opensource.cirrus.com Signed-off-by: Vinod Koul Signed-off-by: Sasha Levin --- drivers/soundwire/cadence_master.c | 7 +++++++ drivers/soundwire/cadence_master.h | 13 ++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/soundwire/cadence_master.c b/drivers/soundwire/cadence_master.c index 18d2f9b3e2010..b229e1e0d7d97 100644 --- a/drivers/soundwire/cadence_master.c +++ b/drivers/soundwire/cadence_master.c @@ -769,8 +769,15 @@ static void cdns_read_response(struct sdw_cdns *cdns) u32 num_resp, cmd_base; int i; + /* RX_FIFO_AVAIL can be 2 entries more than the FIFO size */ + BUILD_BUG_ON(ARRAY_SIZE(cdns->response_buf) < CDNS_MCP_CMD_LEN + 2); + num_resp = cdns_readl(cdns, CDNS_MCP_FIFOSTAT); num_resp &= CDNS_MCP_RX_FIFO_AVAIL; + if (num_resp > ARRAY_SIZE(cdns->response_buf)) { + dev_warn(cdns->dev, "RX AVAIL %d too long\n", num_resp); + num_resp = ARRAY_SIZE(cdns->response_buf); + } cmd_base = CDNS_MCP_CMD_BASE; diff --git a/drivers/soundwire/cadence_master.h b/drivers/soundwire/cadence_master.h index e587aede63bf0..e437a604429fa 100644 --- a/drivers/soundwire/cadence_master.h +++ b/drivers/soundwire/cadence_master.h @@ -8,6 +8,12 @@ #define SDW_CADENCE_GSYNC_KHZ 4 /* 4 kHz */ #define SDW_CADENCE_GSYNC_HZ (SDW_CADENCE_GSYNC_KHZ * 1000) +/* + * The Cadence IP supports up to 32 entries in the FIFO, though implementations + * can configure the IP to have a smaller FIFO. + */ +#define CDNS_MCP_IP_MAX_CMD_LEN 32 + /** * struct sdw_cdns_pdi: PDI (Physical Data Interface) instance * @@ -119,7 +125,12 @@ struct sdw_cdns { struct sdw_bus bus; unsigned int instance; - u32 response_buf[0x80]; + /* + * The datasheet says the RX FIFO AVAIL can be 2 entries more + * than the FIFO capacity, so allow for this. + */ + u32 response_buf[CDNS_MCP_IP_MAX_CMD_LEN + 2]; + struct completion tx_complete; struct sdw_defer *defer; -- 2.39.2