Skip to content

Commit 3060956

Browse files
yonghuahwenlingz
authored andcommitted
dm: fix possible null pointer dereference in pci_gvt_deinit
will access null pointer if 'gvt' is null. Tracked-On: #1479 Signed-off-by: Yonghua Huang <yonghua.huang@intel.com> Reviewed-by: He, Min <min.he@intel.com>
1 parent f991d17 commit 3060956

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

devicemodel/hw/pci/gvt.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -262,18 +262,20 @@ pci_gvt_deinit(struct vmctx *ctx, struct pci_vdev *pi, char *opts)
262262
int ret;
263263
struct pci_gvt *gvt = pi->arg;
264264

265-
if (gvt && gvt->host_config) {
266-
/* Free the allocated host_config */
267-
free(gvt->host_config);
268-
gvt->host_config = NULL;
265+
if (gvt) {
266+
if (gvt->host_config) {
267+
/* Free the allocated host_config */
268+
free(gvt->host_config);
269+
gvt->host_config = NULL;
270+
}
271+
272+
ret = gvt_destroy_instance(gvt);
273+
if (ret)
274+
WPRINTF(("GVT: %s: failed: errno=%d\n", __func__, ret));
275+
276+
free(gvt);
277+
pi->arg = NULL;
269278
}
270-
271-
ret = gvt_destroy_instance(gvt);
272-
if (ret)
273-
WPRINTF(("GVT: %s: failed: errno=%d\n", __func__, ret));
274-
275-
free(gvt);
276-
pi->arg = NULL;
277279
}
278280

279281
struct pci_vdev_ops pci_ops_gvt = {

0 commit comments

Comments
 (0)