From mboxrd@z Thu Jan 1 00:00:00 1970 From: Boris Ostrovsky Subject: Re: [PATCH] misc/xenmicrocode: Upload /lib/firmware/ to the hypervisor Date: Tue, 27 Jan 2015 16:25:09 -0500 Message-ID: <54C80235.2020302@oracle.com> References: <1422389461-19333-1-git-send-email-mcgrof@do-not-panic.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; Format="flowed" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YGDds-0003nA-7g for xen-devel@lists.xenproject.org; Tue, 27 Jan 2015 21:25:48 +0000 In-Reply-To: <1422389461-19333-1-git-send-email-mcgrof@do-not-panic.com> 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" , stefano.stabellini@eu.citrix.com Cc: Juergen Gross , Michal Marek , Jason Douglas , Takashi Iwai , mcgrof@suse.com, Henrique de Moraes Holschuh , david.vrabel@citrix.com, Jan Beulich , xen-devel@lists.xenproject.org, Borislav Petkov , Olaf Hering List-Id: xen-devel@lists.xenproject.org On 01/27/2015 03:11 PM, Luis R. Rodriguez wrote: > + fbuf = mmap(0, len, PROT_READ, MAP_PRIVATE, fd, 0); > + > + if ((xc_handle = xc_interface_open(0,0,0)) == 0) > + { > + fprintf(stderr, "Error opening xc interface: %d (%s)\n", > + errno, strerror(errno)); > + return 1; > + } > + > + if (fbuf == MAP_FAILED) > + { > + printf("Could not map: error: %d(%s)\n", errno, > + strerror(errno)); > + return errno; > + } Shouldn't this 'if' block directly follow the mmap()? > + > + uc = xc_hypercall_buffer_alloc(xc_handle, uc, len); > + memcpy(uc, fbuf, len); > + > + set_xen_guest_handle(op.u.microcode.data, uc); > + op.cmd = XENPF_microcode_update; > + op.interface_version = XENPF_INTERFACE_VERSION; > + op.u.microcode.length = len; > + xc_platform_op(xc_handle, &op); > + > + xc_hypercall_buffer_free(xc_handle, uc); > + xc_interface_close(xc_handle); > + > + if (munmap(fbuf, len)) > + { > + printf("Could not unmap: %d(%s)\n", errno, strerror(errno)); > + return errno; > + } > + > + close(fd); Given that you never close the file on errors this is not really necessary. Or you should close it on errors for consistency. -boris