Skip to content

Commit 3f63b4c

Browse files
jasowangmstsirkin
authored andcommitted
vhost: check the existence of vhost_set_iotlb_callback
Add the check of vhost_set_iotlb_callback before calling Signed-off-by: Jason Wang <[email protected]> Signed-off-by: Cindy Lu <[email protected]> Message-Id: <[email protected]> Reviewed-by: Michael S. Tsirkin <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Acked-by: Jason Wang <[email protected]>
1 parent f19bcdf commit 3f63b4c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

hw/virtio/vhost.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,8 +1686,9 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev)
16861686
}
16871687
}
16881688

1689-
if (vhost_dev_has_iommu(hdev)) {
1690-
hdev->vhost_ops->vhost_set_iotlb_callback(hdev, true);
1689+
if (vhost_dev_has_iommu(hdev) &&
1690+
hdev->vhost_ops->vhost_set_iotlb_callback) {
1691+
hdev->vhost_ops->vhost_set_iotlb_callback(hdev, true);
16911692

16921693
/* Update used ring information for IOTLB to work correctly,
16931694
* vhost-kernel code requires for this.*/
@@ -1730,7 +1731,9 @@ void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev)
17301731
}
17311732

17321733
if (vhost_dev_has_iommu(hdev)) {
1733-
hdev->vhost_ops->vhost_set_iotlb_callback(hdev, false);
1734+
if (hdev->vhost_ops->vhost_set_iotlb_callback) {
1735+
hdev->vhost_ops->vhost_set_iotlb_callback(hdev, false);
1736+
}
17341737
memory_listener_unregister(&hdev->iommu_listener);
17351738
}
17361739
vhost_log_put(hdev, true);

0 commit comments

Comments
 (0)