[PATCH v2 2/3] regmap: spi-avmm: start with the last SOP on phy rx buffer parsing

From: Xu Yilun
Date: Thu Jul 16 2020 - 06:46:24 EST


From: Matthew Gerlach <matthew.gerlach@xxxxxxxxxxxxxxx>

This patch works around a bug in the SPI Slave to Avalon Master bridge.
The SPI slave will send an unexpected extra SOP in the following case.

One in approximately one million read requests results in an apparant
stall on the avalon bus where the SPI slave inserts IDLE characters. When
the stall is over, the slave sends an extra SOP character instead of the
0x7c indicating channel. The other characters are correct.

To eliminate the impact of the bug, this patch changes to look for the
last SOP as the start point of the valid phy rx data.

Signed-off-by: Matthew Gerlach <matthew.gerlach@xxxxxxxxxxxxxxx>
Signed-off-by: Xu Yilun <yilun.xu@xxxxxxxxx>
Signed-off-by: Luis Claudio R. Goncalves <lgoncalv@xxxxxxxxxx>
Signed-off-by: Tom Rix <trix@xxxxxxxxxx>
---
v2: no change.
---
drivers/base/regmap/regmap-spi-avmm.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/base/regmap/regmap-spi-avmm.c b/drivers/base/regmap/regmap-spi-avmm.c
index ab329d2..632e018 100644
--- a/drivers/base/regmap/regmap-spi-avmm.c
+++ b/drivers/base/regmap/regmap-spi-avmm.c
@@ -433,14 +433,14 @@ static int pkt_phy_rx_parse(struct device *dev,
{
char *b, *p;

- b = phy_buf;
p = trans_buf;

- /* Find the SOP */
- while (b < phy_buf + phy_len && *b != PKT_SOP)
- b++;
+ /* Find the last SOP */
+ b = (phy_buf + phy_len) - 1;
+ while (b >= phy_buf && *b != PKT_SOP)
+ b--;

- if (b >= phy_buf + phy_len) {
+ if (b < phy_buf) {
dev_err(dev, "%s no SOP\n", __func__);
return -EINVAL;
}
--
2.7.4