two (possibly bug) updates for spi-s3c644
Subsystems (3)
When doing some investigation into customer issues, I ran across a possble bug in the fifo flush code in spi-s3c64xx.c
PATCH 1/2 spi: s3c64xx: fix timeout counters in flush_fifo
In the s3c64xx_flush_fifo() code, the loops counter is post-decremented in the do { } while(test && loops--) condition. This means the loops is left at the unsigned equivalent of -1 if the loop times out. The test after will never pass as if tests for loops == 0.
--- drivers/spi/spi-s3c64xx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/spi/spi-s3c64xx.c +2 -2
@@ -245,7 +245,7 @@ static void s3c64xx_flush_fifo(struct s3c64xx_spi_driver_data *sdd) loops =msecs_to_loops (1 );do { val =readl (regs +S3C64XX_SPI_STATUS ); - }while (TX_FIFO_LVL (val, sdd) && loops--); + }while (TX_FIFO_LVL (val, sdd) && --loops);if (loops ==0 )dev_warn (&sdd->pdev->dev,"Timed out flushing TX FIFO\n" );
@@ -258,7 +258,7 @@ static void s3c64xx_flush_fifo(struct s3c64xx_spi_driver_data *sdd)readl (regs +S3C64XX_SPI_RX_DATA ); else break; - }while (loops--); + }while (--loops);if (loops ==0 )dev_warn (&sdd->pdev->dev,"Timed out flushing RX FIFO\n" );
Signature · 1 line
2.37.2.352.g3c44437643
Re: [PATCH 1/2] spi: s3c64xx: fix timeout counters in flush_fifo
Hi Ben,
Quoted 6 lines · Ben Dooks
In the
s3c64xx_flush_fifo()code, the loops counter is post-decremented in the do { }while(test && loops--)condition. This means the loops is left at the unsigned equivalent of -1 if the loop times out. The test after will never pass as if tests for loops == 0.Signed-off-by Ben Dooks <[email protected]>
Quoted 9 lines
--- drivers/spi/spi-s3c64xx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/spi/spi-s3c64xx.c +0
-0
drivers/spi/spi-s3c64xx.c static void s3c64xx_flush_fifo(struct s3c64xx_spi_driver_data *sdd) · line 248
Quoted 5 lines
drivers/spi/spi-s3c64xx.c +1
-1@@ -245,7 +245,7 @@ static void s3c64xx_flush_fifo(struct s3c64xx_spi_driver_data *sdd) loops =msecs_to_loops (1 );do { val =readl (regs +S3C64XX_SPI_STATUS ); - }while (TX_FIFO_LVL (val, sdd) && loops--); + }while (TX_FIFO_LVL (val, sdd) && --loops);
Do you think a better fix would be to have a "long loops" as I don't think we need such a big data type for basically 4 * HZ.
And this becomes (loops >= 0);
The same below.
BTW, it's good you sent these patches separately as this needs to be ported to the stable kernels.
In any case,
Thanks,
Andi
Quoted 15 lines
drivers/spi/spi-s3c64xx.c +1
-1if (loops ==0 )dev_warn (&sdd->pdev->dev,"Timed out flushing TX FIFO\n" );@@ -258,7 +258,7 @@ static void s3c64xx_flush_fifo(struct s3c64xx_spi_driver_data *sdd)readl (regs +S3C64XX_SPI_RX_DATA ); else break; - }while (loops--); + }while (--loops);if (loops ==0 )dev_warn (&sdd->pdev->dev,"Timed out flushing RX FIFO\n" );Signature · 1 line
2.37.2.352.g3c44437643
Mark Brown
maintainerRe: (subset) [PATCH 1/2] spi: s3c64xx: fix timeout counters in flush_fifo
In reply to Ben DooksQuoted 6 lines · Ben Dooks
In the
s3c64xx_flush_fifo()code, the loops counter is post-decremented in the do { }while(test && loops--)condition. This means the loops is left at the unsigned equivalent of -1 if the loop times out. The test after will never pass as if tests for loops == 0.
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next
Thanks!
[1/2] spi: s3c64xx: fix timeout counters in flush_fifo
commit: 68a16708d2503b6303d67abd43801e2ca40c208d
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
Andi Shyti
maintainerRe: (subset) [PATCH 1/2] spi: s3c64xx: fix timeout counters in flush_fifo
Hi Mark,
Quoted 8 lines · Mark Brown
Quoted 6 lines · Ben Dooks
In the
s3c64xx_flush_fifo()code, the loops counter is post-decremented in the do { }while(test && loops--)condition. This means the loops is left at the unsigned equivalent of -1 if the loop times out. The test after will never pass as if tests for loops == 0.
Quoted 8 lines
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next
Thanks!
[1/2] spi: s3c64xx: fix timeout counters in
flush_fifocommit: 68a16708d2503b6303d67abd43801e2ca40c208d
This still had some pending comments, besides I think it also needed the Fixes tag.
Andi
Mark Brown
maintainerRe: (subset) [PATCH 1/2] spi: s3c64xx: fix timeout counters in flush_fifo
Quoted 6 lines · Andi Shyti
Quoted 2 lines · Mark Brown
[1/2] spi: s3c64xx: fix timeout counters in
flush_fifocommit: 68a16708d2503b6303d67abd43801e2ca40c208dThis still had some pending comments, besides I think it also
There were some suggestions for stylistic changes in the code but nothing that can't be done incrementally (and which expand the scope of the change).
Quoted 1 line
needed the Fixes tag.
I'd raise the fixes issue with Konstaintin, that's b4 not picking things up. I don't generally worry too much about stable tagging given how eager the AUTOSEL stuff is.
PATCH 2/2 spi: s3c64xx: update flush_fifo timeout code
In reply to Ben DooksThe code that checks for loops in the s3c6xx_flush_fifo() checks for loops being non-zero as a timeout, however the code /could/ finish with loops being zero and the fifo being flushed...
Also, it would be useful to know what is left in the fifo for this error case, so update the checks to see what is left, and then also print the number of entries.
--- drivers/spi/spi-s3c64xx.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/spi/spi-s3c64xx.c +4 -4
@@ -247,8 +247,8 @@ static void s3c64xx_flush_fifo(struct s3c64xx_spi_driver_data *sdd) val =readl (regs +S3C64XX_SPI_STATUS ); }while (TX_FIFO_LVL (val, sdd) && --loops); -if (loops ==0 ) -dev_warn (&sdd->pdev->dev,"Timed out flushing TX FIFO\n" ); +if (TX_FIFO_LVL (val, sdd)) +dev_warn (&sdd->pdev->dev,"Timed out flushing TX FIFO (%d left)\n" ,TX_FIFO_LVL (val, sdd));/* Flush RxFIFO*/ loops =msecs_to_loops (1 );
@@ -260,8 +260,8 @@ static void s3c64xx_flush_fifo(struct s3c64xx_spi_driver_data *sdd)break ; }while (--loops); -if (loops ==0 ) -dev_warn (&sdd->pdev->dev,"Timed out flushing RX FIFO\n" ); +if (RX_FIFO_LVL (val, sdd)) +dev_warn (&sdd->pdev->dev,"Timed out flushing RX FIFO (%d left)\n" ,RX_FIFO_LVL (val, sdd)); val =readl (regs +S3C64XX_SPI_CH_CFG ); val &= ~S3C64XX_SPI_CH_SW_RST ;
Signature · 1 line
2.37.2.352.g3c44437643
Andi Shyti
maintainerRe: [PATCH 2/2] spi: s3c64xx: update flush_fifo timeout code
Quoted 3 lines · Ben Dooks
The code that checks for loops in the
s3c6xx_flush_fifo()checks for loops being non-zero as a timeout, however the code /could/ finish with loops being zero and the fifo being flushed...
what is the possibility of this case?
Quoted 25 lines
Also, it would be useful to know what is left in the fifo for this error case, so update the checks to see what is left, and then also print the number of entries.
Signed-off-by Ben Dooks <[email protected]>--- drivers/spi/spi-s3c64xx.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/spi/spi-s3c64xx.c +2
-2@@ -247,8 +247,8 @@ static void s3c64xx_flush_fifo(struct s3c64xx_spi_driver_data *sdd) val =readl (regs +S3C64XX_SPI_STATUS ); }while (TX_FIFO_LVL (val, sdd) && --loops); -if (loops ==0 ) -dev_warn (&sdd->pdev->dev,"Timed out flushing TX FIFO\n" ); +if (TX_FIFO_LVL (val, sdd)) +dev_warn (&sdd->pdev->dev,"Timed out flushing TX FIFO (%d left)\n" ,TX_FIFO_LVL (val, sdd));/* Flush RxFIFO*/ loops =msecs_to_loops (1 );
drivers/spi/spi-s3c64xx.c static void s3c64xx_flush_fifo(struct s3c64xx_spi_driver_data *sdd) · line 264
Quoted 7 lines
drivers/spi/spi-s3c64xx.c +2
-2@@ -260,8 +260,8 @@ static void s3c64xx_flush_fifo(struct s3c64xx_spi_driver_data *sdd)break ; }while (--loops); -if (loops ==0 ) -dev_warn (&sdd->pdev->dev,"Timed out flushing RX FIFO\n" ); +if (RX_FIFO_LVL (val, sdd)) +dev_warn (&sdd->pdev->dev,"Timed out flushing RX FIFO (%d left)\n" ,RX_FIFO_LVL (val, sdd));
This change doesn't super excite me, but it's fine. Please add a comment explaining the case when loops is '0' and the FIFO is flushed.
With the comment given, you can have my r-b.
Thanks,
Andi
Quoted 5 lines
drivers/spi/spi-s3c64xx.c +0
-0val =readl (regs +S3C64XX_SPI_CH_CFG ); val &= ~S3C64XX_SPI_CH_SW_RST ;Signature · 1 line
2.37.2.352.g3c44437643
Re: [PATCH 2/2] spi: s3c64xx: update flush_fifo timeout code
Quoted 6 lines · Andi Shyti
Quoted 3 lines · Ben Dooks
The code that checks for loops in the
s3c6xx_flush_fifo()checks for loops being non-zero as a timeout, however the code /could/ finish with loops being zero and the fifo being flushed...what is the possibility of this case?
Not sure, currently we're trying to debug a customer's setup where we're seeing some weird issues with SPI. This was found during a look into the code awaiting hardware access.
The flush count was simply an inspection and it seemed like a good idea to fix the initial issue and then if there was an issue to print something more useful than a simple error message.
Quoted 37 lines
Quoted 25 lines
Also, it would be useful to know what is left in the fifo for this error case, so update the checks to see what is left, and then also print the number of entries.
Signed-off-by Ben Dooks <[email protected]>--- drivers/spi/spi-s3c64xx.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/spi/spi-s3c64xx.c +2
-2@@ -247,8 +247,8 @@ static void s3c64xx_flush_fifo(struct s3c64xx_spi_driver_data *sdd) val =readl (regs +S3C64XX_SPI_STATUS ); }while (TX_FIFO_LVL (val, sdd) && --loops); -if (loops ==0 ) -dev_warn (&sdd->pdev->dev,"Timed out flushing TX FIFO\n" ); +if (TX_FIFO_LVL (val, sdd)) +dev_warn (&sdd->pdev->dev,"Timed out flushing TX FIFO (%d left)\n" ,TX_FIFO_LVL (val, sdd));/* Flush RxFIFO*/ loops =msecs_to_loops (1 );drivers/spi/spi-s3c64xx.c static void s3c64xx_flush_fifo(struct s3c64xx_spi_driver_data *sdd) · line 264
Quoted 7 lines
drivers/spi/spi-s3c64xx.c +2
-2@@ -260,8 +260,8 @@ static void s3c64xx_flush_fifo(struct s3c64xx_spi_driver_data *sdd)break ; }while (--loops); -if (loops ==0 ) -dev_warn (&sdd->pdev->dev,"Timed out flushing RX FIFO\n" ); +if (RX_FIFO_LVL (val, sdd)) +dev_warn (&sdd->pdev->dev,"Timed out flushing RX FIFO (%d left)\n" ,RX_FIFO_LVL (val, sdd));This change doesn't super excite me, but it's fine. Please add a comment explaining the case when loops is '0' and the FIFO is flushed.
Quoted 1 line
With the comment given, you can have my r-b.
Ok, will look at sending a second version later this week.
Quoted 10 lines
Thanks,
AndiQuoted 5 lines
drivers/spi/spi-s3c64xx.c +0
-0val =readl (regs +S3C64XX_SPI_CH_CFG ); val &= ~S3C64XX_SPI_CH_SW_RST ;Signature · 1 line
2.37.2.352.g3c44437643
Signature · 4 lines
Ben Dooks http://www.codethink.co.uk/ Senior Engineer Codethink - Providing Genius https://www.codethink.co.uk/privacy.html
Andi Shyti
maintainerRe: [PATCH 2/2] spi: s3c64xx: update flush_fifo timeout code
Hi Ben,
Quoted 50 lines · Ben Dooks
Quoted 6 lines · Andi Shyti
Quoted 3 lines · Ben Dooks
The code that checks for loops in the
s3c6xx_flush_fifo()checks for loops being non-zero as a timeout, however the code /could/ finish with loops being zero and the fifo being flushed...what is the possibility of this case?
Not sure, currently we're trying to debug a customer's setup where we're seeing some weird issues with SPI. This was found during a look into the code awaiting hardware access.
The flush count was simply an inspection and it seemed like a good idea to fix the initial issue and then if there was an issue to print something more useful than a simple error message.
Quoted 34 lines
Quoted 23 lines
Also, it would be useful to know what is left in the fifo for this error case, so update the checks to see what is left, and then also print the number of entries.
Signed-off-by Ben Dooks <[email protected]>--- drivers/spi/spi-s3c64xx.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/spi/spi-s3c64xx.c +2
-2@@ -247,8 +247,8 @@ static void s3c64xx_flush_fifo(struct s3c64xx_spi_driver_data *sdd) val =readl (regs +S3C64XX_SPI_STATUS ); }while (TX_FIFO_LVL (val, sdd) && --loops); -if (loops ==0 ) -dev_warn (&sdd->pdev->dev,"Timed out flushing TX FIFO\n" ); +if (TX_FIFO_LVL (val, sdd)) +dev_warn (&sdd->pdev->dev,"Timed out flushing TX FIFO (%d left)\n" ,TX_FIFO_LVL (val, sdd));/* Flush RxFIFO*/ loops =msecs_to_loops (1 );drivers/spi/spi-s3c64xx.c static void s3c64xx_flush_fifo(struct s3c64xx_spi_driver_data *sdd) · line 263
Quoted 6 lines
drivers/spi/spi-s3c64xx.c +2
-2@@ -260,8 +260,8 @@ static void s3c64xx_flush_fifo(struct s3c64xx_spi_driver_data *sdd)break ; }while (--loops); -if (loops ==0 ) -dev_warn (&sdd->pdev->dev,"Timed out flushing RX FIFO\n" ); +if (RX_FIFO_LVL (val, sdd)) +dev_warn (&sdd->pdev->dev,"Timed out flushing RX FIFO (%d left)\n" ,RX_FIFO_LVL (val, sdd));This change doesn't super excite me, but it's fine. Please add a comment explaining the case when loops is '0' and the FIFO is flushed.
Quoted 3 lines
Quoted 1 line
With the comment given, you can have my r-b.
Ok, will look at sending a second version later this week.
I actually think that these two patches can be squashed into a single one, I don't see much reason for having it double.
Even better, I think the first patch is not needed at all with this new one. Right?
Andi
Quoted 17 lines
Quoted 10 lines
Thanks,
AndiQuoted 5 lines
drivers/spi/spi-s3c64xx.c +0
-0val =readl (regs +S3C64XX_SPI_CH_CFG ); val &= ~S3C64XX_SPI_CH_SW_RST ;Signature · 1 line
2.37.2.352.g3c44437643Signature · 4 lines
Ben Dooks http://www.codethink.co.uk/ Senior Engineer Codethink - Providing Genius https://www.codethink.co.uk/privacy.html