[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v4] libxc: check for various libxc failures and pass them down
...in xc_cpuid_{pv,hvm}_policy. Coverity-ID: 1093050 Signed-off-by: Matthew Daley <mattjd@xxxxxxxxx> --- v2: Return actual error from xc_domain_get_guest_width v3: Return actual error from xc_cpuid_pv_policy as well, and add error checking to libxc calls in xc_cpuid_hvm_param as well v4: Use 'rc != 0' instead of just 'rc' in if checks tools/libxc/xc_cpuid_x86.c | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/tools/libxc/xc_cpuid_x86.c b/tools/libxc/xc_cpuid_x86.c index bbbf9b8..8373e73 100644 --- a/tools/libxc/xc_cpuid_x86.c +++ b/tools/libxc/xc_cpuid_x86.c @@ -268,28 +268,35 @@ static void xc_cpuid_config_xsave( } } -static void xc_cpuid_hvm_policy( +static int xc_cpuid_hvm_policy( xc_interface *xch, domid_t domid, const unsigned int *input, unsigned int *regs) { DECLARE_DOMCTL; + int rc; char brand[13]; unsigned long nestedhvm; unsigned long pae; int is_pae, is_nestedhvm; uint64_t xfeature_mask; - xc_get_hvm_param(xch, domid, HVM_PARAM_PAE_ENABLED, &pae); + rc = xc_get_hvm_param(xch, domid, HVM_PARAM_PAE_ENABLED, &pae); + if ( rc != 0 ) + return rc; is_pae = !!pae; /* Detecting Xen's atitude towards XSAVE */ memset(&domctl, 0, sizeof(domctl)); domctl.cmd = XEN_DOMCTL_getvcpuextstate; domctl.domain = domid; - do_domctl(xch, &domctl); + rc = do_domctl(xch, &domctl); + if ( rc != 0 ) + return rc; xfeature_mask = domctl.u.vcpuextstate.xfeature_mask; - xc_get_hvm_param(xch, domid, HVM_PARAM_NESTEDHVM, &nestedhvm); + rc = xc_get_hvm_param(xch, domid, HVM_PARAM_NESTEDHVM, &nestedhvm); + if ( rc != 0 ) + return rc; is_nestedhvm = !!nestedhvm; switch ( input[0] ) @@ -429,13 +436,15 @@ static void xc_cpuid_hvm_policy( else intel_xc_cpuid_policy(xch, domid, input, regs, is_pae, is_nestedhvm); + return rc; } -static void xc_cpuid_pv_policy( +static int xc_cpuid_pv_policy( xc_interface *xch, domid_t domid, const unsigned int *input, unsigned int *regs) { DECLARE_DOMCTL; + int rc; unsigned int guest_width; int guest_64bit, xen_64bit = hypervisor_is_64bit(xch); char brand[13]; @@ -443,7 +452,9 @@ static void xc_cpuid_pv_policy( xc_cpuid_brand_get(brand); - xc_domain_get_guest_width(xch, domid, &guest_width); + rc = xc_domain_get_guest_width(xch, domid, &guest_width); + if ( rc != 0 ) + return rc; guest_64bit = (guest_width == 8); /* Detecting Xen's atitude towards XSAVE */ @@ -547,23 +558,29 @@ static void xc_cpuid_pv_policy( regs[0] = regs[1] = regs[2] = regs[3] = 0; break; } + + return rc; } static int xc_cpuid_policy( xc_interface *xch, domid_t domid, const unsigned int *input, unsigned int *regs) { + int rc; xc_dominfo_t info; - if ( xc_domain_getinfo(xch, domid, 1, &info) == 0 ) + rc = xc_domain_getinfo(xch, domid, 1, &info); + if ( rc < 0 ) + return rc; + if ( rc == 0 ) return -EINVAL; if ( info.hvm ) - xc_cpuid_hvm_policy(xch, domid, input, regs); + rc = xc_cpuid_hvm_policy(xch, domid, input, regs); else - xc_cpuid_pv_policy(xch, domid, input, regs); + rc = xc_cpuid_pv_policy(xch, domid, input, regs); - return 0; + return rc; } static int xc_cpuid_do_domctl( @@ -632,12 +649,14 @@ int xc_cpuid_apply_policy(xc_interface *xch, domid_t domid) for ( ; ; ) { cpuid(input, regs); - xc_cpuid_policy(xch, domid, input, regs); + rc = xc_cpuid_policy(xch, domid, input, regs); + if ( rc != 0 ) + return rc; if ( regs[0] || regs[1] || regs[2] || regs[3] ) { rc = xc_cpuid_do_domctl(xch, domid, input, regs); - if ( rc ) + if ( rc != 0 ) return rc; } -- 1.7.10.4 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |