Jan Beulich
2012-Jan-03 10:19 UTC
[PATCH] qemu-xen: fix sequence of operations in pt_msix_init()
Checking the return value of mmap() must be done before adjusting the value, otherwise failure may not be detected. Closing the file handle, on the other hand, can be done before checking the return value. Finally, printing the errno value without knowing whether the previous function actually failed is bogus (and superfluous since a subsequent message prints the strerror() representaton anyway). Signed-off-by: Jan Beulich <jbeulich@suse.com> --- a/hw/pt-msi.c +++ b/hw/pt-msi.c @@ -537,7 +537,6 @@ int pt_msix_init(struct pt_dev *dev, int int i, total_entries, table_off, bar_index; struct pci_dev *pd = dev->pci_dev; int fd; - int err; id = pci_read_byte(pd, pos + PCI_CAP_LIST_ID); @@ -585,17 +584,14 @@ int pt_msix_init(struct pt_dev *dev, int dev->msix->phys_iomem_base = mmap(0, total_entries * 16 + dev->msix->table_offset_adjust, PROT_READ, MAP_SHARED | MAP_LOCKED, fd, dev->msix->table_base + table_off - dev->msix->table_offset_adjust); - dev->msix->phys_iomem_base = (void *)((char *)dev->msix->phys_iomem_base + - dev->msix->table_offset_adjust); - err = errno; - PT_LOG("errno = %d\n",err); + close(fd); if ( dev->msix->phys_iomem_base == MAP_FAILED ) { PT_LOG("Error: Can''t map physical MSI-X table: %s\n", strerror(errno)); - close(fd); goto error_out; } - close(fd); + + dev->msix->phys_iomem_base += dev->msix->table_offset_adjust; PT_LOG("mapping physical MSI-X table to %lx\n", (unsigned long)dev->msix->phys_iomem_base); _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Stefano Stabellini
2012-Jan-04 14:39 UTC
Re: [PATCH] qemu-xen: fix sequence of operations in pt_msix_init()
On Tue, 3 Jan 2012, Jan Beulich wrote:> Checking the return value of mmap() must be done before adjusting the > value, otherwise failure may not be detected. > > Closing the file handle, on the other hand, can be done before checking > the return value. > > Finally, printing the errno value without knowing whether the previous > function actually failed is bogus (and superfluous since a subsequent > message prints the strerror() representaton anyway). > > Signed-off-by: Jan Beulich <jbeulich@suse.com>acked
Ian Jackson
2012-Jan-05 17:16 UTC
Re: [PATCH] qemu-xen: fix sequence of operations in pt_msix_init()
Stefano Stabellini writes ("Re: [Xen-devel] [PATCH] qemu-xen: fix sequence of operations in pt_msix_init()"):> On Tue, 3 Jan 2012, Jan Beulich wrote: > > Checking the return value of mmap() must be done before adjusting the > > value, otherwise failure may not be detected. > > > > Closing the file handle, on the other hand, can be done before checking > > the return value. > > > > Finally, printing the errno value without knowing whether the previous > > function actually failed is bogus (and superfluous since a subsequent > > message prints the strerror() representaton anyway). > > > > Signed-off-by: Jan Beulich <jbeulich@suse.com> > > ackedCommitted-by: Ian Jackson <ian.jackson@eu.citrix.com>