@@ -1897,12 +1897,21 @@ void kvmppc_xive_free_sources(struct kvmppc_xive_src_block *sb)
static void kvmppc_xive_release(struct kvm_device *dev)
{
struct kvmppc_xive *xive = dev->private;
- struct kvm *kvm = xive->kvm;
+ struct kvm *kvm;
struct kvm_vcpu *vcpu;
int i;
pr_devel("Releasing xive device\n");
+ /*
+ * In case of failure (OPAL) at device creation, the device
+ * can be partially initialized.
+ */
+ if (!xive)
+ return;
+
+ kvm = xive->kvm;
+
/*
* Since this is the device release function, we know that
* userspace does not have any open fd referring to the
@@ -2001,7 +2010,6 @@ static int kvmppc_xive_create(struct kvm_device *dev, u32 type)
if (!xive)
return -ENOMEM;
- dev->private = xive;
xive->dev = dev;
xive->kvm = kvm;
mutex_init(&xive->lock);
@@ -2031,6 +2039,7 @@ static int kvmppc_xive_create(struct kvm_device *dev, u32 type)
if (ret)
return ret;
+ dev->private = xive;
return 0;
}
@@ -987,12 +987,21 @@ static int kvmppc_xive_native_has_attr(struct kvm_device *dev,
static void kvmppc_xive_native_release(struct kvm_device *dev)
{
struct kvmppc_xive *xive = dev->private;
- struct kvm *kvm = xive->kvm;
+ struct kvm *kvm;
struct kvm_vcpu *vcpu;
int i;
pr_devel("Releasing xive native device\n");
+ /*
+ * In case of failure (OPAL) at device creation, the device
+ * can be partially initialized.
+ */
+ if (!xive)
+ return;
+
+ kvm = xive->kvm;
+
/*
* Clear the KVM device file address_space which is used to
* unmap the ESB pages when a device is passed-through.
@@ -1076,7 +1085,6 @@ static int kvmppc_xive_native_create(struct kvm_device *dev, u32 type)
if (!xive)
return -ENOMEM;
- dev->private = xive;
xive->dev = dev;
xive->kvm = kvm;
kvm->arch.xive = xive;
@@ -1100,6 +1108,7 @@ static int kvmppc_xive_native_create(struct kvm_device *dev, u32 type)
if (ret)
return ret;
+ dev->private = xive;
return 0;
}