From: Ian Campbell Subject: Re: [RFC] libxc: check return values on mmap() and madvise() on xc_alloc_hypercall_buffer() Date: Thu, 8 May 2014 11:15:25 +0100 Message-ID: <1399544125.9513.37.camel@kazak.uk.xensource.com> References: <1399499244-4421-1-git-send-email-mcgrof@do-not-panic.com> <536AAF3F.3070700@citrix.com> <20140508050320.GD13289@wotan.suse.de> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WiLMS-0006Uk-0T for xen-devel@lists.xenproject.org; Thu, 08 May 2014 10:15:32 +0000 In-Reply-To: <20140508050320.GD13289@wotan.suse.de> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: "Luis R. Rodriguez" Cc: Andrew Cooper , Stefano Stabellini , Ian Jackson , xen-devel@lists.xenproject.org, "Luis R. Rodriguez" List-Id: xen-devel@lists.xenproject.org On Thu, 2014-05-08 at 07:03 +0200, Luis R. Rodriguez wrote: > > > BTW I see no ldconfig run after make install, where do we want to put it > > > given we have a few libs ? > > How about this? Isn't this conventionally the admin's responsibility? > > > > tools/libxc/xc_linux_osdep.c | 17 ++++++++++++++++- > > > 1 file changed, 16 insertions(+), 1 deletion(-) > > > > > > > > > diff --git a/tools/libxc/xc_linux_osdep.c b/tools/libxc/xc_linux_osdep.c > > > index 73860a2..32e5332 100644 > > > --- a/tools/libxc/xc_linux_osdep.c > > > +++ b/tools/libxc/xc_linux_osdep.c > > > @@ -92,14 +92,29 @@ static void *linux_privcmd_alloc_hypercall_buffer(xc_interface *xch, xc_osdep_ha > > > { > > > size_t size = npages * XC_PAGE_SIZE; > > > void *p; > > > + int rc, saved_errno; > > > > > > /* Address returned by mmap is page aligned. */ > > > p = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_LOCKED, -1, 0); > > > + if ( p == MAP_FAILED ) > > > + { > > > + PERROR("xc_alloc_hypercall_buffer: mmap failed"); > > > + return NULL; > > > + } > > > > > > /* Do not copy the VMA to child process on fork. Avoid the page being COW > > > on hypercall. */ > > > - madvise(p, npages * XC_PAGE_SIZE, MADV_DONTFORK); > > > + rc = madvise(p, npages * XC_PAGE_SIZE, MADV_DONTFORK); > > > + if ( rc < 0 ) > > > + goto out; > > > + > > > > This might be cleaner like: > > > > if ( rc == 0 ) > > return p; > > > > error cleanup; > > > > > > as it is small enough to do without an out; label. > > Sure, that makes sesnse. The out label idiom you have used is pretty conventional and will save faff if some other operation gets added here. I'm happy with the patch as it is. > > Also, you can do without 'rc' if you are happy putting the madvise() in the if statement > > itself. 'rc' isn't subsequently referenced. > > OK. > > Luis