Skip to content

Commit 4740e1e

Browse files
Harald MommerBartosz Golaszewski
authored andcommitted
gpio: virtio: Fix config space reading.
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 <[email protected]> Cc: [email protected] Fixes: 3a29355 ("gpio: Add virtio-gpio driver") Acked-by: Viresh Kumar <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Bartosz Golaszewski <[email protected]>
1 parent 678bae2 commit 4740e1e

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
@@ -527,7 +527,6 @@ static const char **virtio_gpio_get_names(struct virtio_gpio *vgpio,
527527

528528
static int virtio_gpio_probe(struct virtio_device *vdev)
529529
{
530-
struct virtio_gpio_config config;
531530
struct device *dev = &vdev->dev;
532531
struct virtio_gpio *vgpio;
533532
struct irq_chip *gpio_irq_chip;
@@ -540,9 +539,11 @@ static int virtio_gpio_probe(struct virtio_device *vdev)
540539
return -ENOMEM;
541540

542541
/* Read configuration */
543-
virtio_cread_bytes(vdev, 0, &config, sizeof(config));
544-
gpio_names_size = le32_to_cpu(config.gpio_names_size);
545-
ngpio = le16_to_cpu(config.ngpio);
542+
gpio_names_size =
543+
virtio_cread32(vdev, offsetof(struct virtio_gpio_config,
544+
gpio_names_size));
545+
ngpio = virtio_cread16(vdev, offsetof(struct virtio_gpio_config,
546+
ngpio));
546547
if (!ngpio) {
547548
dev_err(dev, "Number of GPIOs can't be zero\n");
548549
return -EINVAL;

0 commit comments

Comments
 (0)