|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v2 08/13] libxc: Check xc_domain_maximum_gpfn for negative return values
Instead of assuming everything is always OK. We stash
the gpfns value as an parameter.
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>
---
tools/libxc/xc_core_arm.c | 17 ++++++++++++++---
tools/libxc/xc_core_x86.c | 24 ++++++++++++++++++++----
tools/libxc/xc_domain_save.c | 8 +++++++-
3 files changed, 41 insertions(+), 8 deletions(-)
diff --git a/tools/libxc/xc_core_arm.c b/tools/libxc/xc_core_arm.c
index 16508e7..26cec04 100644
--- a/tools/libxc/xc_core_arm.c
+++ b/tools/libxc/xc_core_arm.c
@@ -31,9 +31,16 @@ xc_core_arch_gpfn_may_present(struct xc_core_arch_context
*arch_ctxt,
}
-static int nr_gpfns(xc_interface *xch, domid_t domid)
+static int nr_gpfns(xc_interface *xch, domid_t domid, unsigned long *gpfns)
{
- return xc_domain_maximum_gpfn(xch, domid) + 1;
+ int rc = xc_domain_maximum_gpfn(xch, domid);
+
+ if ( rc >= 0 )
+ {
+ *gpfns = rc + 1;
+ rc = 0;
+ }
+ return rc;
}
int
@@ -48,9 +55,13 @@ xc_core_arch_memory_map_get(xc_interface *xch, struct
xc_core_arch_context *unus
xc_core_memory_map_t **mapp,
unsigned int *nr_entries)
{
- unsigned long p2m_size = nr_gpfns(xch, info->domid);
+ unsigned long p2m_size = 0;
+ int rc = nr_gpfns(xch, info->domid, &p2m_size);
xc_core_memory_map_t *map;
+ if ( rc < 0 )
+ return -1;
+
map = malloc(sizeof(*map));
if ( map == NULL )
{
diff --git a/tools/libxc/xc_core_x86.c b/tools/libxc/xc_core_x86.c
index d8846f1..02377e8 100644
--- a/tools/libxc/xc_core_x86.c
+++ b/tools/libxc/xc_core_x86.c
@@ -36,9 +36,16 @@ xc_core_arch_gpfn_may_present(struct xc_core_arch_context
*arch_ctxt,
}
-static int nr_gpfns(xc_interface *xch, domid_t domid)
+static int nr_gpfns(xc_interface *xch, domid_t domid, unsigned long *gpfns)
{
- return xc_domain_maximum_gpfn(xch, domid) + 1;
+ int rc = xc_domain_maximum_gpfn(xch, domid);
+
+ if ( rc >= 0 )
+ {
+ *gpfns = rc + 1;
+ rc = 0;
+ }
+ return rc;
}
int
@@ -53,9 +60,13 @@ xc_core_arch_memory_map_get(xc_interface *xch, struct
xc_core_arch_context *unus
xc_core_memory_map_t **mapp,
unsigned int *nr_entries)
{
- unsigned long p2m_size = nr_gpfns(xch, info->domid);
+ unsigned long p2m_size = 0;
+ int rc = nr_gpfns(xch, info->domid, &p2m_size);
xc_core_memory_map_t *map;
+ if ( rc < 0 )
+ return -1;
+
map = malloc(sizeof(*map));
if ( map == NULL )
{
@@ -88,7 +99,12 @@ xc_core_arch_map_p2m_rw(xc_interface *xch, struct
domain_info_context *dinfo, xc
int err;
int i;
- dinfo->p2m_size = nr_gpfns(xch, info->domid);
+ err = nr_gpfns(xch, info->domid, &dinfo->p2m_size);
+ if ( err < 0 )
+ {
+ ERROR("nr_gpfns returns errno: %d.", errno);
+ goto out;
+ }
if ( dinfo->p2m_size < info->nr_pages )
{
ERROR("p2m_size < nr_pages -1 (%lx < %lx", dinfo->p2m_size,
info->nr_pages - 1);
diff --git a/tools/libxc/xc_domain_save.c b/tools/libxc/xc_domain_save.c
index 254fdb3..6346c12 100644
--- a/tools/libxc/xc_domain_save.c
+++ b/tools/libxc/xc_domain_save.c
@@ -939,7 +939,13 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t
dom, uint32_t max_iter
}
/* Get the size of the P2M table */
- dinfo->p2m_size = xc_domain_maximum_gpfn(xch, dom) + 1;
+ rc = xc_domain_maximum_gpfn(xch, dom);
+ if ( rc < 0 )
+ {
+ ERROR("Could not get maximum GPFN!");
+ goto out;
+ }
+ dinfo->p2m_size = rc + 1;
if ( dinfo->p2m_size > ~XEN_DOMCTL_PFINFO_LTAB_MASK )
{
--
2.1.0
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |