In pci_create_sysfs_dev_files of Linux's drivers/pci/pci-sysfs.c, the sysfs "rom" file can be created with a zero size (the (pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW) case). The resulting file in sysfs may still be read for a valid rom image.
libpciaccess' pci_device_linux_sysfs_read_rom uses the size returned by fstat to determine how many bytes to read, and so in this case reads nothing (and still returns 0 for success).
Ideally pci_device_linux_sysfs_read_rom needs adaptation to avoid the fstat result, but falling through to pci_device_linux_devmem_read_rom would also work.
*** Bug 8698 has been marked as a duplicate of this bug. ***
Created attachment 14736 [details] [review]
Proposed patch. Please review.
Created attachment 15015 [details] [review]
Fix the original problem, and a similar bug in the devmem path
The previous patch doesn't work, due to a very similar bug in the handling of zero reported size ROMs in the devmem path. This patch fixes the error in the devmem path, and avoids the fall-through from sysfs to devmem for this particular case by applying the trivial fix that is in the devmem path to the sysfs path.
With these fixes, both paths work.
My name is ajax, and I approve this message.
Fixed in git, will be in the next pciaccess release. Thanks!