From: Peng Fan <[email protected]>

We enable the virtio_ivshmem driver and add
shared memory region including pci devices in cell file. But we not
start backend.

There might be garbage data in "vi_dev->virtio_header", so we need to
check peer_state to abort the probe earlier.

Signed-off-by: Peng Fan <[email protected]>
---
 drivers/virtio/virtio_ivshmem.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/virtio/virtio_ivshmem.c b/drivers/virtio/virtio_ivshmem.c
index bf62377790b1..7132cf0e25fe 100644
--- a/drivers/virtio/virtio_ivshmem.c
+++ b/drivers/virtio/virtio_ivshmem.c
@@ -846,6 +846,10 @@ static int virtio_ivshmem_probe(struct pci_dev *pci_dev,
                return -ENOMEM;
 
        vi_dev->peer_state = &state_table[vi_dev->peer_id];
+       if (*vi_dev->peer_state != VIRTIO_STATE_READY) {
+               dev_err(&pci_dev->dev, "backend not ready\n");
+               return -ENODEV;
+       }
 
        section_addr += section_sz;
 
@@ -898,11 +902,6 @@ static int virtio_ivshmem_probe(struct pci_dev *pci_dev,
 
        set_dma_ops(&pci_dev->dev, &virtio_ivshmem_dma_ops);
 
-       if (*vi_dev->peer_state != VIRTIO_STATE_READY) {
-               dev_err(&pci_dev->dev, "backend not ready\n");
-               return -ENODEV;
-       }
-
        pci_set_master(pci_dev);
        pci_write_config_byte(pci_dev, vendor_cap + IVSHM_CFG_PRIV_CNTL, 0);
 
-- 
2.28.0

-- 
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jailhouse-dev/20210113103946.359-1-peng.fan%40oss.nxp.com.

Reply via email to