mirror of https://github.com/xemu-project/xemu.git
spapr/xive: Fix xive->fd if kvm_create_device() fails
If the creation of the KVM XIVE device fails for some reasons, the negative errno ends up in xive->fd, but the rest of the code assumes that xive->fd either contains an open fd, ie. positive value, or -1. This doesn't cause any misbehavior except kvmppc_xive_disconnect() that will try to close(xive->fd) during rollback and likely be rewarded with an EBADF. Only set xive->fd with a open fd. Signed-off-by: Greg Kurz <groug@kaod.org> Message-Id: <159673296585.766512.15404407281299745442.stgit@bahia.lan> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
c55bcb1f47
commit
82f086b5e7
|
@ -745,6 +745,7 @@ int kvmppc_xive_connect(SpaprInterruptController *intc, uint32_t nr_servers,
|
||||||
size_t esb_len = (1ull << xsrc->esb_shift) * xsrc->nr_irqs;
|
size_t esb_len = (1ull << xsrc->esb_shift) * xsrc->nr_irqs;
|
||||||
size_t tima_len = 4ull << TM_SHIFT;
|
size_t tima_len = 4ull << TM_SHIFT;
|
||||||
CPUState *cs;
|
CPUState *cs;
|
||||||
|
int fd;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The KVM XIVE device already in use. This is the case when
|
* The KVM XIVE device already in use. This is the case when
|
||||||
|
@ -760,11 +761,12 @@ int kvmppc_xive_connect(SpaprInterruptController *intc, uint32_t nr_servers,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* First, create the KVM XIVE device */
|
/* First, create the KVM XIVE device */
|
||||||
xive->fd = kvm_create_device(kvm_state, KVM_DEV_TYPE_XIVE, false);
|
fd = kvm_create_device(kvm_state, KVM_DEV_TYPE_XIVE, false);
|
||||||
if (xive->fd < 0) {
|
if (fd < 0) {
|
||||||
error_setg_errno(errp, -xive->fd, "XIVE: error creating KVM device");
|
error_setg_errno(errp, -fd, "XIVE: error creating KVM device");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
xive->fd = fd;
|
||||||
|
|
||||||
/* Tell KVM about the # of VCPUs we may have */
|
/* Tell KVM about the # of VCPUs we may have */
|
||||||
if (kvm_device_check_attr(xive->fd, KVM_DEV_XIVE_GRP_CTRL,
|
if (kvm_device_check_attr(xive->fd, KVM_DEV_XIVE_GRP_CTRL,
|
||||||
|
|
Loading…
Reference in New Issue