Skip to content

Commit 5d6c696

Browse files
Harald Mommergregkh
authored andcommitted
gpio: virtio: Fix config space reading.
commit 4740e1e upstream. Quote from the virtio specification chapter 4.2.2.2: "For the device-specific configuration space, the driver MUST use 8 bit wide accesses for 8 bit wide fields, 16 bit wide and aligned accesses for 16 bit wide fields and 32 bit wide and aligned accesses for 32 and 64 bit wide fields." Signed-off-by: Harald Mommer <harald.mommer@oss.qualcomm.com> Cc: stable@vger.kernel.org Fixes: 3a29355 ("gpio: Add virtio-gpio driver") Acked-by: Viresh Kumar <viresh.kumar@linaro.org> Link: https://lore.kernel.org/r/20250724143718.5442-2-harald.mommer@oss.qualcomm.com Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b3f7932 commit 5d6c696

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

drivers/gpio/gpio-virtio.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,6 @@ static const char **virtio_gpio_get_names(struct virtio_gpio *vgpio,
539539

540540
static int virtio_gpio_probe(struct virtio_device *vdev)
541541
{
542-
struct virtio_gpio_config config;
543542
struct device *dev = &vdev->dev;
544543
struct virtio_gpio *vgpio;
545544
u32 gpio_names_size;
@@ -551,9 +550,11 @@ static int virtio_gpio_probe(struct virtio_device *vdev)
551550
return -ENOMEM;
552551

553552
/* Read configuration */
554-
virtio_cread_bytes(vdev, 0, &config, sizeof(config));
555-
gpio_names_size = le32_to_cpu(config.gpio_names_size);
556-
ngpio = le16_to_cpu(config.ngpio);
553+
gpio_names_size =
554+
virtio_cread32(vdev, offsetof(struct virtio_gpio_config,
555+
gpio_names_size));
556+
ngpio = virtio_cread16(vdev, offsetof(struct virtio_gpio_config,
557+
ngpio));
557558
if (!ngpio) {
558559
dev_err(dev, "Number of GPIOs can't be zero\n");
559560
return -EINVAL;

0 commit comments

Comments
 (0)