From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Luis R. Rodriguez" Subject: Re: [PATCH] misc/xenmicrocode: Upload /lib/firmware/ to the hypervisor Date: Tue, 27 Jan 2015 22:54:21 +0100 Message-ID: <20150127215421.GD19988@wotan.suse.de> References: <1422389461-19333-1-git-send-email-mcgrof@do-not-panic.com> <54C80235.2020302@oracle.com> 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 1YGE5Z-0005rf-38 for xen-devel@lists.xenproject.org; Tue, 27 Jan 2015 21:54:25 +0000 Content-Disposition: inline In-Reply-To: <54C80235.2020302@oracle.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: Boris Ostrovsky Cc: Juergen Gross , Michal Marek , Jason Douglas , stefano.stabellini@eu.citrix.com, Takashi Iwai , Henrique de Moraes Holschuh , david.vrabel@citrix.com, Jan Beulich , xen-devel@lists.xenproject.org, "Luis R. Rodriguez" , Borislav Petkov , Olaf Hering List-Id: xen-devel@lists.xenproject.org On Tue, Jan 27, 2015 at 04:25:09PM -0500, Boris Ostrovsky wrote: > 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()? Sure. >> + >> + 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. Its not required but I'll do this as I think its better, and while at it I'll also add a check for xc_hypercall_buffer_alloc() failure as no check is there for it now. Will send out a v2. Luis