[PATCH libpciaccess] Support for 32-bit domains
Keith Busch
keith.busch at intel.com
Fri Aug 12 16:51:18 UTC 2016
On Fri, Aug 12, 2016 at 11:43:52AM +0200, Mark Kettenis wrote:
> 'struct pci_device' isn't an opaque struct, and the "documentation"
> never says that you can't build your own. It isn't unreasonable to
> expect to be able to fill in the domain, bus, device and function
> yourself and be able to call pci_device_cfg_read(). It also means
> that code can copy a 'struct pci_device' instance around. Code using
> the old ABI would lose the new 32-bit domain field in that case.
Hm, that also has potential memory corruption if a program allocates
their own with the older, smaller sized struct.
Unless versioning the symbols is ok (yikes!), I think ignoring these types
of domains in Linux is the simplest thing we can do. It's certainly okay
with us and infinitely better than the current behavior. :)
Here's the alternate proposal, assuming this is more readily acceptable:
https://lists.x.org/archives/xorg-devel/2016-August/050593.html
Inlined here for convenience:
---
diff --git a/src/linux_sysfs.c b/src/linux_sysfs.c
index 6367b11..f09a832 100644
--- a/src/linux_sysfs.c
+++ b/src/linux_sysfs.c
@@ -119,18 +119,28 @@ pci_system_linux_sysfs_create( void )
/**
- * Filter out the names "." and ".." from the scanned sysfs entries.
+ * Filter out the names "." and ".." from the scanned sysfs entries, and
+ * domains requiring 32-bits.
*
* \param d Directory entry being processed by \c scandir.
*
* \return
- * Zero if the entry name matches either "." or "..", non-zero otherwise.
+ * Zero if the entry name matches either "." or "..", or the domain requires
+ * 32 bits, non-zero otherwise.
*
* \sa scandir, populate_entries
*/
static int
scan_sys_pci_filter( const struct dirent * d )
{
+ if (d->d_name[0] != '.') {
+ unsigned dom = 0;
+
+ sscanf(d->d_name, "%x:", &dom);
+ if (dom > USHRT_MAX)
+ return 0;
+ }
+
return !((strcmp( d->d_name, "." ) == 0)
|| (strcmp( d->d_name, ".." ) == 0));
}
--
More information about the xorg-devel
mailing list