]> git.baikalelectronics.ru Git - kernel.git/commitdiff
soundwire: cadence: Remove wasted space in response_buf
authorRichard Fitzgerald <rf@opensource.cirrus.com>
Fri, 2 Dec 2022 16:18:11 +0000 (16:18 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 11 Mar 2023 12:55:40 +0000 (13:55 +0100)
[ Upstream commit c3b054e9bb1889e3f237065cb4735c3c964850dd ]

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 <rf@opensource.cirrus.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://lore.kernel.org/r/20221202161812.4186897-3-rf@opensource.cirrus.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/soundwire/cadence_master.c
drivers/soundwire/cadence_master.h

index b65cdf2a7593e732b142595317f4c5f3c471f4ec..6cd9db19758c9fe1e28133f6b3101f1346ac75dc 100644 (file)
@@ -774,8 +774,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;
 
index ca9e805bab88f383fdd5d1a8e2acae535389c0a0..51e6ecc027cbcd040378f80c4ed6b9ec351ac0fc 100644 (file)
@@ -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
  *
@@ -114,7 +120,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;