mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-01 20:05:30 +00:00
virtio: add virtio callbacks check
This patch is back porting from mainline: We can only call these callbacks when they are not NULL. Tracked-On: #5357 Signed-off-by: Jie Deng <jie.deng@intel.com> Acked-by: Wang, Yu1 <yu1.wang@intel.com>
This commit is contained in:
parent
772ab3a95c
commit
e778acc3e0
@ -763,7 +763,7 @@ virtio_pci_legacy_read(struct vmctx *ctx, int vcpu, struct pci_vdev *dev,
|
||||
const char *name;
|
||||
uint32_t newoff;
|
||||
uint32_t value;
|
||||
int error;
|
||||
int error = -1;
|
||||
|
||||
|
||||
if (base->mtx)
|
||||
@ -791,8 +791,11 @@ virtio_pci_legacy_read(struct vmctx *ctx, int vcpu, struct pci_vdev *dev,
|
||||
max = vops->cfgsize ? vops->cfgsize : 0x100000000;
|
||||
if (newoff + size > max)
|
||||
goto bad;
|
||||
error = (*vops->cfgread)(DEV_STRUCT(base), newoff,
|
||||
size, &value);
|
||||
|
||||
if (vops->cfgread) {
|
||||
error = (*vops->cfgread)(DEV_STRUCT(base), newoff,
|
||||
size, &value);
|
||||
}
|
||||
if (!error)
|
||||
goto done;
|
||||
}
|
||||
@ -873,7 +876,7 @@ virtio_pci_legacy_write(struct vmctx *ctx, int vcpu, struct pci_vdev *dev,
|
||||
uint64_t virtio_config_size, max;
|
||||
const char *name;
|
||||
uint32_t newoff;
|
||||
int error;
|
||||
int error = -1;
|
||||
|
||||
|
||||
if (base->mtx)
|
||||
@ -899,8 +902,10 @@ virtio_pci_legacy_write(struct vmctx *ctx, int vcpu, struct pci_vdev *dev,
|
||||
max = vops->cfgsize ? vops->cfgsize : 0x100000000;
|
||||
if (newoff + size > max)
|
||||
goto bad;
|
||||
error = (*vops->cfgwrite)(DEV_STRUCT(base), newoff,
|
||||
size, value);
|
||||
if (vops->cfgwrite) {
|
||||
error = (*vops->cfgwrite)(DEV_STRUCT(base), newoff,
|
||||
size, value);
|
||||
}
|
||||
if (!error)
|
||||
goto done;
|
||||
}
|
||||
@ -962,7 +967,7 @@ bad:
|
||||
base->status = value;
|
||||
if (vops->set_status)
|
||||
(*vops->set_status)(DEV_STRUCT(base), value);
|
||||
if (value == 0)
|
||||
if ((value == 0) && (vops->reset))
|
||||
(*vops->reset)(DEV_STRUCT(base));
|
||||
if ((value & VIRTIO_CONFIG_S_DRIVER_OK) &&
|
||||
base->backend_type == BACKEND_VBSU &&
|
||||
@ -1390,7 +1395,7 @@ virtio_common_cfg_write(struct pci_vdev *dev, uint64_t offset, int size,
|
||||
base->status = value & 0xff;
|
||||
if (vops->set_status)
|
||||
(*vops->set_status)(DEV_STRUCT(base), value);
|
||||
if (base->status == 0)
|
||||
if ((base->status == 0) && (vops->reset))
|
||||
(*vops->reset)(DEV_STRUCT(base));
|
||||
/* TODO: virtio poll mode for modern devices */
|
||||
break;
|
||||
@ -1487,7 +1492,7 @@ virtio_device_cfg_read(struct pci_vdev *dev, uint64_t offset, int size)
|
||||
const char *name;
|
||||
uint32_t value;
|
||||
uint64_t max;
|
||||
int error;
|
||||
int error = -1;
|
||||
|
||||
vops = base->vops;
|
||||
name = vops->name;
|
||||
@ -1500,7 +1505,9 @@ virtio_device_cfg_read(struct pci_vdev *dev, uint64_t offset, int size)
|
||||
return value;
|
||||
}
|
||||
|
||||
error = (*vops->cfgread)(DEV_STRUCT(base), offset, size, &value);
|
||||
if (vops->cfgread) {
|
||||
error = (*vops->cfgread)(DEV_STRUCT(base), offset, size, &value);
|
||||
}
|
||||
if (error) {
|
||||
pr_err("%s: reading from 0x%lx size %d failed %d\r\n",
|
||||
name, offset, size, error);
|
||||
@ -1518,7 +1525,7 @@ virtio_device_cfg_write(struct pci_vdev *dev, uint64_t offset, int size,
|
||||
struct virtio_ops *vops;
|
||||
const char *name;
|
||||
uint64_t max;
|
||||
int error;
|
||||
int error = -1;
|
||||
|
||||
vops = base->vops;
|
||||
name = vops->name;
|
||||
@ -1530,7 +1537,9 @@ virtio_device_cfg_write(struct pci_vdev *dev, uint64_t offset, int size,
|
||||
return;
|
||||
}
|
||||
|
||||
error = (*vops->cfgwrite)(DEV_STRUCT(base), offset, size, value);
|
||||
if (vops->cfgwrite) {
|
||||
error = (*vops->cfgwrite)(DEV_STRUCT(base), offset, size, value);
|
||||
}
|
||||
if (error)
|
||||
pr_err("%s: writing ot 0x%lx size %d failed %d\r\n",
|
||||
name, offset, size, error);
|
||||
|
Loading…
Reference in New Issue
Block a user