From: "Jan Beulich" Subject: [PATCH] libxc: mmapbatch-v2 adjustments Date: Fri, 22 Jan 2010 07:53:09 +0000 Message-ID: <4B596775020000780002B7D2@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part567C4975.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part567C4975.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Just like the kernel, the fallback implementation of xc_map_foreign_bulk() should clear the error indication array upon success. Also, a few allocations were needlessly using calloc() instead of malloc(). Finally, in xc_domain_save() allocate the error indicator array once (along with the other arrays) instead of using realloc() (without error checking) in the loop body. Signed-off-by: Jan Beulich --- 2010-01-06.orig/tools/libxc/xc_domain_save.c 2010-01-12 = 10:22:58.000000000 +0100 +++ 2010-01-06/tools/libxc/xc_domain_save.c 2010-01-22 08:33:52.0000000= 00 +0100 @@ -1059,7 +1059,8 @@ int xc_domain_save(int xc_handle, int io pfn_type =3D xg_memalign(PAGE_SIZE, ROUNDUP( MAX_BATCH_SIZE * sizeof(*pfn_type), = PAGE_SHIFT)); pfn_batch =3D calloc(MAX_BATCH_SIZE, sizeof(*pfn_batch)); - if ( (pfn_type =3D=3D NULL) || (pfn_batch =3D=3D NULL) ) + pfn_err =3D malloc(MAX_BATCH_SIZE * sizeof(*pfn_err)); + if ( (pfn_type =3D=3D NULL) || (pfn_batch =3D=3D NULL) || (pfn_err = =3D=3D NULL) ) { ERROR("failed to alloc memory for pfn_type and/or pfn_batch = arrays"); errno =3D ENOMEM; @@ -1273,7 +1274,6 @@ int xc_domain_save(int xc_handle, int io if ( batch =3D=3D 0 ) goto skip; /* vanishingly unlikely... */ =20 - pfn_err =3D realloc(pfn_err, sizeof(int) * batch); region_base =3D xc_map_foreign_bulk( xc_handle, dom, PROT_READ, pfn_type, pfn_err, batch); if ( region_base =3D=3D NULL ) --- 2010-01-06.orig/tools/libxc/xc_linux.c 2010-01-14 14:05:14.0000000= 00 +0100 +++ 2010-01-06/tools/libxc/xc_linux.c 2010-01-22 08:38:41.000000000 = +0100 @@ -186,7 +186,7 @@ void *xc_map_foreign_bulk(int xc_handle, * IOCTL_PRIVCMD_MMAPBATCH_V2 is not supported - fall back to * IOCTL_PRIVCMD_MMAPBATCH. */ - xen_pfn_t *pfn =3D calloc(num, sizeof(*pfn)); + xen_pfn_t *pfn =3D malloc(num * sizeof(*pfn)); =20 if ( pfn ) { --- 2010-01-06.orig/tools/libxc/xc_misc.c 2010-01-08 15:38:59.0000000= 00 +0100 +++ 2010-01-06/tools/libxc/xc_misc.c 2010-01-22 08:39:22.000000000 = +0100 @@ -360,7 +360,7 @@ void *xc_map_foreign_pages(int xc_handle return NULL; } =20 - err =3D calloc(num, sizeof(*err)); + err =3D malloc(num * sizeof(*err)); if (!err) return NULL; =20 @@ -397,7 +397,7 @@ xc_map_foreign_bulk(int xc_handle, uint3 return NULL; } =20 - pfn =3D calloc(num, sizeof(*pfn)); + pfn =3D malloc(num * sizeof(*pfn)); if (!pfn) { errno =3D ENOMEM; return NULL; @@ -416,7 +416,8 @@ xc_map_foreign_bulk(int xc_handle, uint3 err[i] =3D -EINVAL; break; } - } + } else + memset(err, 0, num * sizeof(*err)); =20 free(pfn); =20 --=__Part567C4975.0__= Content-Type: text/plain; name="xen-libxc-privcmd-mmap-clear.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xen-libxc-privcmd-mmap-clear.patch" Just like the kernel, the fallback implementation of=0Axc_map_foreign_bulk(= ) should clear the error indication array upon=0Asuccess.=0A=0AAlso, a few = allocations were needlessly using calloc() instead of=0Amalloc().=0A=0AFina= lly, in xc_domain_save() allocate the error indicator array once=0A(along = with the other arrays) instead of using realloc() (without=0Aerror = checking) in the loop body.=0A=0ASigned-off-by: Jan Beulich =0A=0A--- 2010-01-06.orig/tools/libxc/xc_domain_save.c 2010-01-12 = 10:22:58.000000000 +0100=0A+++ 2010-01-06/tools/libxc/xc_domain_save.c = 2010-01-22 08:33:52.000000000 +0100=0A@@ -1059,7 +1059,8 @@ int xc_domain_s= ave(int xc_handle, int io=0A pfn_type =3D xg_memalign(PAGE_SIZE, = ROUNDUP(=0A MAX_BATCH_SIZE * sizeof(*pfn_type= ), PAGE_SHIFT));=0A pfn_batch =3D calloc(MAX_BATCH_SIZE, sizeof(*pfn_b= atch));=0A- if ( (pfn_type =3D=3D NULL) || (pfn_batch =3D=3D NULL) = )=0A+ pfn_err =3D malloc(MAX_BATCH_SIZE * sizeof(*pfn_err));=0A+ = if ( (pfn_type =3D=3D NULL) || (pfn_batch =3D=3D NULL) || (pfn_err =3D=3D = NULL) )=0A {=0A ERROR("failed to alloc memory for pfn_type = and/or pfn_batch arrays");=0A errno =3D ENOMEM;=0A@@ -1273,7 = +1274,6 @@ int xc_domain_save(int xc_handle, int io=0A if ( = batch =3D=3D 0 )=0A goto skip; /* vanishingly unlikely... = */=0A =0A- pfn_err =3D realloc(pfn_err, sizeof(int) * batch);=0A= region_base =3D xc_map_foreign_bulk(=0A = xc_handle, dom, PROT_READ, pfn_type, pfn_err, batch);=0A if ( = region_base =3D=3D NULL )=0A--- 2010-01-06.orig/tools/libxc/xc_linux.c = 2010-01-14 14:05:14.000000000 +0100=0A+++ 2010-01-06/tools/libxc/xc_linux.c= 2010-01-22 08:38:41.000000000 +0100=0A@@ -186,7 +186,7 @@ void = *xc_map_foreign_bulk(int xc_handle,=0A * IOCTL_PRIVCMD_MMAPBATCH_V= 2 is not supported - fall back to=0A * IOCTL_PRIVCMD_MMAPBATCH.=0A= */=0A- xen_pfn_t *pfn =3D calloc(num, sizeof(*pfn));=0A+ = xen_pfn_t *pfn =3D malloc(num * sizeof(*pfn));=0A =0A if ( = pfn )=0A {=0A--- 2010-01-06.orig/tools/libxc/xc_misc.c 2010-01-08 = 15:38:59.000000000 +0100=0A+++ 2010-01-06/tools/libxc/xc_misc.c 2010-01-22 = 08:39:22.000000000 +0100=0A@@ -360,7 +360,7 @@ void *xc_map_foreign_pages(i= nt xc_handle=0A return NULL;=0A }=0A =0A- err =3D calloc(num= , sizeof(*err));=0A+ err =3D malloc(num * sizeof(*err));=0A if = (!err)=0A return NULL;=0A =0A@@ -397,7 +397,7 @@ xc_map_foreign_bul= k(int xc_handle, uint3=0A return NULL;=0A }=0A =0A- pfn =3D = calloc(num, sizeof(*pfn));=0A+ pfn =3D malloc(num * sizeof(*pfn));=0A = if (!pfn) {=0A errno =3D ENOMEM;=0A return NULL;=0A@@ = -416,7 +416,8 @@ xc_map_foreign_bulk(int xc_handle, uint3=0A = err[i] =3D -EINVAL;=0A break;=0A }=0A- = }=0A+ } else=0A+ memset(err, 0, num * sizeof(*err));=0A =0A = free(pfn);=0A =0A --=__Part567C4975.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=__Part567C4975.0__=--