[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH] misc/xenmicrocode: Upload /lib/firmware/<some blob> to the hypervisor



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

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.