Linux virtualization list
 help / color / mirror / Atom feed
* [PATCH] spi: virtio: fix mode bits propagation from device to driver
@ 2026-11-29 20:32 Francesco Valla
  2026-11-29 20:36 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Francesco Valla @ 2026-11-29 20:32 UTC (permalink / raw)
  To: Mark Brown; +Cc: virtualization, linux-spi, stable, Francesco Valla

The initial value of the device's mode_bits is set with an incorrect
mask, because VIRTIO_SPI_CS_HIGH and VIRTIO_SPI_MODE_LSB_FIRST are not
meant for the propagation of device capabilities but for transfers.
This has the effect of:

  - setting SPI_CS_HIGH when the device advertises support for CPOL=0;
  - setting SPI_LSB_FIRST when the device advertises support for CPOL=1;
  - completely ignoring the CS_HIGH support advertised by the device.

Use the correct VIRTIO_SPI_MF_ macros instead.

While at it, use the correct macros also for the mode_bits assignments
that follow, selecting the ones from the spi namespace (no functional
change there, since their value is the same as the corresponding ones
from the virtio namespace).

Fixes: f98cabe3f6cf ("SPI: Add virtio SPI driver")
Cc: stable@vger.kernel.org
Signed-off-by: Francesco Valla <francesco@valla.it>
---
 drivers/spi/spi-virtio.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/spi/spi-virtio.c b/drivers/spi/spi-virtio.c
index 2eeb79ff5aa2..66edc4dae02a 100644
--- a/drivers/spi/spi-virtio.c
+++ b/drivers/spi/spi-virtio.c
@@ -265,12 +265,13 @@ static void virtio_spi_read_config(struct virtio_device *vdev)
 	mode_func_supported =
 		virtio_cread32(vdev, offsetof(struct virtio_spi_config,
 					      mode_func_supported));
-	ctrl->mode_bits = mode_func_supported &
-			  (VIRTIO_SPI_CS_HIGH | VIRTIO_SPI_MODE_LSB_FIRST);
+	ctrl->mode_bits = 0;
+	if (mode_func_supported & VIRTIO_SPI_MF_SUPPORT_CS_HIGH)
+		ctrl->mode_bits |= SPI_CS_HIGH;
 	if (mode_func_supported & VIRTIO_SPI_MF_SUPPORT_CPHA_1)
-		ctrl->mode_bits |= VIRTIO_SPI_CPHA;
+		ctrl->mode_bits |= SPI_CPHA;
 	if (mode_func_supported & VIRTIO_SPI_MF_SUPPORT_CPOL_1)
-		ctrl->mode_bits |= VIRTIO_SPI_CPOL;
+		ctrl->mode_bits |= SPI_CPOL;
 	if (mode_func_supported & VIRTIO_SPI_MF_SUPPORT_LSB_FIRST)
 		ctrl->mode_bits |= SPI_LSB_FIRST;
 	if (mode_func_supported & VIRTIO_SPI_MF_SUPPORT_LOOPBACK)

---
base-commit: ca20d5a011d35fc25e328fe31ac47f7aae557c5a
change-id: 20261129-spi-virtio-modebits-fix-10c734535167

Best regards,
--  
Francesco Valla <francesco@valla.it>


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] spi: virtio: fix mode bits propagation from device to driver
  2026-11-29 20:32 [PATCH] spi: virtio: fix mode bits propagation from device to driver Francesco Valla
@ 2026-11-29 20:36 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-29 20:36 UTC (permalink / raw)
  To: Francesco Valla; +Cc: virtualization, Michael S. Tsirkin, Eugenio Perez

> The initial value of the device's mode_bits is set with an incorrect
> mask, because VIRTIO_SPI_CS_HIGH and VIRTIO_SPI_MODE_LSB_FIRST are not
> meant for the propagation of device capabilities but for transfers.
> This has the effect of:
> 
>   - setting SPI_CS_HIGH when the device advertises support for CPOL=0;
>   - setting SPI_LSB_FIRST when the device advertises support for CPOL=1;
>   - completely ignoring the CS_HIGH support advertised by the device.
> 
> Use the correct VIRTIO_SPI_MF_ macros instead.
> 
> While at it, use the correct macros also for the mode_bits assignments
> that follow, selecting the ones from the spi namespace (no functional
> change there, since their value is the same as the corresponding ones
> from the virtio namespace).
> 
> Fixes: f98cabe3f6cf ("SPI: Add virtio SPI driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Francesco Valla <francesco@valla.it>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261129-spi-virtio-modebits-fix-v1-1-0a406aff25f7@valla.it?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-29 20:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 20:32 [PATCH] spi: virtio: fix mode bits propagation from device to driver Francesco Valla
2026-11-29 20:36 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox