diff mbox series

[v2] spi: spi-imx: fix off-by-one in mx51 CPU mode burst length

Message ID 20240313210258.5990-1-adam@jessamine.co.uk (mailing list archive)
State Superseded
Headers show
Series [v2] spi: spi-imx: fix off-by-one in mx51 CPU mode burst length | expand

Commit Message

Adam Butcher March 13, 2024, 8:58 p.m. UTC
From: Adam Butcher <adam@jessamine.co.uk>

992e1211dc91 ("spi: imx: fix the burst length at DMA mode and CPU mode")
corrects three cases of setting the ECSPI burst length but erroneously
leaves the in-range CPU case one bit to big (in that field a value of
0 means 1 bit).  The effect was that transmissions that should have been
8-bit bytes appeared as 9-bit causing failed communication with SPI
devices.

Link: https://lore.kernel.org/all/20240201105451.507005-1-carlos.song@nxp.com/
Link: https://lore.kernel.org/all/20240204091912.36488-1-carlos.song@nxp.com/
Fixes: 992e1211dc91 ("spi: imx: fix the burst length at DMA mode and CPU mode")
Signed-off-by: Adam Butcher <adam@jessamine.co.uk>
---

This is a cleaned up version of my earlier emails after the mess webmail
and I made of the previous re-address.  The patch itself is no different,
but I've moved the discussion part here and sent with git send-email so
hopefully no more issues.

The original patch submission up to v4 (first link above) did not contain
the bug that this patch fixes.  It was introduced in the v5 update (second
link).

---
 drivers/spi/spi-imx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Mark Brown March 18, 2024, 3:55 p.m. UTC | #1
On Wed, Mar 13, 2024 at 08:58:19PM +0000, Adam Butcher wrote:
> From: Adam Butcher <adam@jessamine.co.uk>
> 
> 992e1211dc91 ("spi: imx: fix the burst length at DMA mode and CPU mode")
> corrects three cases of setting the ECSPI burst length but erroneously
> leaves the in-range CPU case one bit to big (in that field a value of
> 0 means 1 bit).  The effect was that transmissions that should have been
> 8-bit bytes appeared as 9-bit causing failed communication with SPI
> devices.

This doesn't apply against current code, please check and resend.
Adam Butcher March 18, 2024, 5:21 p.m. UTC | #2
On Mon, March 18, 2024 3:55 pm, Mark Brown wrote:
> On Wed, Mar 13, 2024 at 08:58:19PM +0000, Adam Butcher wrote:
>> From: Adam Butcher <adam@jessamine.co.uk>
>>
>> 992e1211dc91 ("spi: imx: fix the burst length at DMA mode and CPU
>> mode") corrects three cases of setting the ECSPI burst length but
>> erroneously leaves the in-range CPU case one bit to big (in that
>> field a value of 0 means 1 bit).  The effect was that transmissions
>> that should have been 8-bit bytes appeared as 9-bit causing failed
>> communication with SPI devices.
>
> This doesn't apply against current code, please check and resend.
>

That refers to the commit my patch fixes.  On looking it up I found it
was no longer reachable
(https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git/commit/?id=992e1211dc91).
The corresponding upstream commit that is reachable from both
torvalds/linux.git/master and broonie/spi.git/spi-next is c712c05e46c8.

Though it was made against 6.8.y, I was able to apply my patch with
git-am to both the latest broonie/spi.git/for-next (593c0afc18d) and
torvalds/linux.git/master (0a7b0acecea2) without conflicts.

Shall I send a v3 correcting the hash mentioned in the commit message?
Mark Brown March 18, 2024, 5:33 p.m. UTC | #3
On Mon, Mar 18, 2024 at 05:21:48PM +0000, Adam Butcher wrote:

> Shall I send a v3 correcting the hash mentioned in the commit message?

Yes, please.
Mark Brown March 19, 2024, 11:47 a.m. UTC | #4
On Wed, 13 Mar 2024 20:58:19 +0000, Adam Butcher wrote:
> 992e1211dc91 ("spi: imx: fix the burst length at DMA mode and CPU mode")
> corrects three cases of setting the ECSPI burst length but erroneously
> leaves the in-range CPU case one bit to big (in that field a value of
> 0 means 1 bit).  The effect was that transmissions that should have been
> 8-bit bytes appeared as 9-bit causing failed communication with SPI
> devices.
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[1/1] spi: spi-imx: fix off-by-one in mx51 CPU mode burst length
      commit: cf6d79a0f5769b5f4d9579ddaf88d2c30b03b873

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark
diff mbox series

Patch

diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index 7c1fcd5ed52f7..100552e6c56bc 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -743,8 +743,8 @@  static int mx51_ecspi_prepare_transfer(struct spi_imx_data *spi_imx,
 				ctrl |= (MX51_ECSPI_CTRL_MAX_BURST * BITS_PER_BYTE - 1)
 						<< MX51_ECSPI_CTRL_BL_OFFSET;
 			else
-				ctrl |= spi_imx->count / DIV_ROUND_UP(spi_imx->bits_per_word,
-						BITS_PER_BYTE) * spi_imx->bits_per_word
+				ctrl |= (spi_imx->count / DIV_ROUND_UP(spi_imx->bits_per_word,
+						BITS_PER_BYTE) * spi_imx->bits_per_word - 1)
 						<< MX51_ECSPI_CTRL_BL_OFFSET;
 		}
 	}