diff options
author | Andrew Scull | 2022-04-21 16:11:14 +0000 |
---|---|---|
committer | Tom Rini | 2022-05-03 18:33:29 -0400 |
commit | c763e1e023cc08e6ec5fefc2be3ae28d685c0e21 (patch) | |
tree | 99e64cb14f47e4b6e4e980c6c2cf336cde00da7c /drivers | |
parent | 2635e3b50f8e646fc54c2bb15a017dea61a64a68 (diff) |
virtio: pci: Check virtio configs are mapped
Prepare for calls to `virtio_pci_map_capability()` failing by returning
NULL on error. If this happens, later accesses to the pointers would be
unsafe so cause the probe to fail if such an error occurs.
Signed-off-by: Andrew Scull <ascull@google.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/virtio/virtio_pci_modern.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/drivers/virtio/virtio_pci_modern.c b/drivers/virtio/virtio_pci_modern.c index bf92d9d3ba5..f1e64a34388 100644 --- a/drivers/virtio/virtio_pci_modern.c +++ b/drivers/virtio/virtio_pci_modern.c @@ -533,7 +533,19 @@ static int virtio_pci_probe(struct udevice *udev) return -EINVAL; } + /* Map configuration structures */ + priv->common = virtio_pci_map_capability(udev, &common_cap); + if (!priv->common) { + printf("(%s): could not map common config\n", udev->name); + return -EINVAL; + } + priv->notify_len = notify_cap.length; + priv->notify_base = virtio_pci_map_capability(udev, ¬ify_cap); + if (!priv->notify_base) { + printf("(%s): could not map notify config\n", udev->name); + return -EINVAL; + } /* * Device capability is only mandatory for devices that have @@ -545,11 +557,13 @@ static int virtio_pci_probe(struct udevice *udev) if (device) { priv->device_len = device_cap.length; priv->device = virtio_pci_map_capability(udev, &device_cap); + if (!priv->device) { + printf("(%s): could not map device config\n", + udev->name); + return -EINVAL; + } } - /* Map configuration structures */ - priv->common = virtio_pci_map_capability(udev, &common_cap); - priv->notify_base = virtio_pci_map_capability(udev, ¬ify_cap); debug("(%p): common @ %p, notify base @ %p, device @ %p\n", udev, priv->common, priv->notify_base, priv->device); |