[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 24/40] spapr/xive: Convert KVM device fd checks to assert()
From: |
David Gibson |
Subject: |
[PULL 24/40] spapr/xive: Convert KVM device fd checks to assert() |
Date: |
Tue, 18 Aug 2020 14:19:06 +1000 |
From: Greg Kurz <groug@kaod.org>
All callers guard these functions with an xive_in_kernel() helper. Make
it clear that they are only to be called when the KVM XIVE device exists.
Note that the check on xive is dropped in kvmppc_xive_disconnect(). It
really cannot be NULL since it comes from set_active_intc() which only
passes pointers to allocated objects.
Signed-off-by: Greg Kurz <groug@kaod.org>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Message-Id: <159679994169.876294.11026653581505077112.stgit@bahia.lan>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
hw/intc/spapr_xive_kvm.c | 35 +++++++----------------------------
1 file changed, 7 insertions(+), 28 deletions(-)
diff --git a/hw/intc/spapr_xive_kvm.c b/hw/intc/spapr_xive_kvm.c
index 6130882be6..82a6f99f02 100644
--- a/hw/intc/spapr_xive_kvm.c
+++ b/hw/intc/spapr_xive_kvm.c
@@ -79,10 +79,7 @@ void kvmppc_xive_cpu_set_state(XiveTCTX *tctx, Error **errp)
uint64_t state[2];
int ret;
- /* The KVM XIVE device is not in use yet */
- if (xive->fd == -1) {
- return;
- }
+ assert(xive->fd != -1);
/* word0 and word1 of the OS ring. */
state[0] = *((uint64_t *) &tctx->regs[TM_QW1_OS]);
@@ -101,10 +98,7 @@ void kvmppc_xive_cpu_get_state(XiveTCTX *tctx, Error **errp)
uint64_t state[2] = { 0 };
int ret;
- /* The KVM XIVE device is not in use */
- if (xive->fd == -1) {
- return;
- }
+ assert(xive->fd != -1);
ret = kvm_get_one_reg(tctx->cs, KVM_REG_PPC_VP_STATE, state);
if (ret != 0) {
@@ -156,10 +150,7 @@ void kvmppc_xive_cpu_connect(XiveTCTX *tctx, Error **errp)
unsigned long vcpu_id;
int ret;
- /* The KVM XIVE device is not in use */
- if (xive->fd == -1) {
- return;
- }
+ assert(xive->fd != -1);
/* Check if CPU was hot unplugged and replugged. */
if (kvm_cpu_is_enabled(tctx->cs)) {
@@ -245,10 +236,7 @@ int kvmppc_xive_source_reset_one(XiveSource *xsrc, int
srcno, Error **errp)
SpaprXive *xive = SPAPR_XIVE(xsrc->xive);
uint64_t state = 0;
- /* The KVM XIVE device is not in use */
- if (xive->fd == -1) {
- return -ENODEV;
- }
+ assert(xive->fd != -1);
if (xive_source_irq_is_lsi(xsrc, srcno)) {
state |= KVM_XIVE_LEVEL_SENSITIVE;
@@ -592,10 +580,7 @@ static void kvmppc_xive_change_state_handler(void *opaque,
int running,
void kvmppc_xive_synchronize_state(SpaprXive *xive, Error **errp)
{
- /* The KVM XIVE device is not in use */
- if (xive->fd == -1) {
- return;
- }
+ assert(xive->fd != -1);
/*
* When the VM is stopped, the sources are masked and the previous
@@ -622,10 +607,7 @@ int kvmppc_xive_pre_save(SpaprXive *xive)
{
Error *local_err = NULL;
- /* The KVM XIVE device is not in use */
- if (xive->fd == -1) {
- return 0;
- }
+ assert(xive->fd != -1);
/* EAT: there is no extra state to query from KVM */
@@ -845,10 +827,7 @@ void kvmppc_xive_disconnect(SpaprInterruptController *intc)
XiveSource *xsrc;
size_t esb_len;
- /* The KVM XIVE device is not in use */
- if (!xive || xive->fd == -1) {
- return;
- }
+ assert(xive->fd != -1);
/* Clear the KVM mapping */
xsrc = &xive->source;
--
2.26.2
- [PULL 10/40] ppc/xive: Fix some typos in comments, (continued)
- [PULL 10/40] ppc/xive: Fix some typos in comments, David Gibson, 2020/08/18
- [PULL 13/40] target/ppc: add vmulh{su}w instructions, David Gibson, 2020/08/18
- [PULL 18/40] spapr: Clarify error and documentation for broken KVM XICS, David Gibson, 2020/08/18
- [PULL 15/40] target/ppc: Fix SPE unavailable exception triggering, David Gibson, 2020/08/18
- [PULL 17/40] docs: Update POWER9 XIVE support for nested guests, David Gibson, 2020/08/18
- [PULL 19/40] spapr/xive: Fix xive->fd if kvm_create_device() fails, David Gibson, 2020/08/18
- [PULL 22/40] ppc/xive: Rework setup of XiveSource::esb_mmio, David Gibson, 2020/08/18
- [PULL 23/40] ppc/xive: Introduce dedicated kvm_irqchip_in_kernel() wrappers, David Gibson, 2020/08/18
- [PULL 20/40] spapr/xive: Simplify kvmppc_xive_disconnect(), David Gibson, 2020/08/18
- [PULL 21/40] target/ppc: Integrate icount to purr, vtb, and tbu40, David Gibson, 2020/08/18
- [PULL 24/40] spapr/xive: Convert KVM device fd checks to assert(),
David Gibson <=
- [PULL 27/40] spapr/xive: Rework error handling of kvmppc_xive_source_reset(), David Gibson, 2020/08/18
- [PULL 26/40] spapr/xive: Rework error handling of kvmppc_xive_cpu_connect(), David Gibson, 2020/08/18
- [PULL 25/40] spapr: Simplify error handling in spapr_phb_realize(), David Gibson, 2020/08/18
- [PULL 29/40] spapr/xive: Rework error handling of kvmppc_xive_cpu_[gs]et_state(), David Gibson, 2020/08/18
- [PULL 28/40] spapr/xive: Rework error handling of kvmppc_xive_mmap(), David Gibson, 2020/08/18
- [PULL 37/40] ppc/xive: Simplify error handling in xive_tctx_realize(), David Gibson, 2020/08/18
- [PULL 30/40] spapr/xive: Rework error handling of kvmppc_xive_[gs]et_queue_config(), David Gibson, 2020/08/18
- [PULL 31/40] spapr/xive: Rework error handling in kvmppc_xive_get_queues(), David Gibson, 2020/08/18
- [PULL 39/40] nvram: Exit QEMU if NVRAM cannot contain all -prom-env data, David Gibson, 2020/08/18
- [PULL 33/40] spapr/kvm: Fix error handling in kvmppc_xive_pre_save(), David Gibson, 2020/08/18