[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Hurd: avoid using the deprecated RPC pci_get_ndevs()
From: |
Joan Lledó |
Subject: |
[PATCH] Hurd: avoid using the deprecated RPC pci_get_ndevs() |
Date: |
Sun, 3 Nov 2019 11:00:56 +0100 (CET) |
From: Joan Lledó <jlledom@member.fsf.org>
---
src/hurd_pci.c | 83 +++++++++++++++++++++-----------------------------
1 file changed, 34 insertions(+), 49 deletions(-)
diff --git a/src/hurd_pci.c b/src/hurd_pci.c
index 28bef16..98bf83e 100644
--- a/src/hurd_pci.c
+++ b/src/hurd_pci.c
@@ -304,8 +304,8 @@ pci_device_hurd_destroy(struct pci_device *dev)
/* Walk through the FS tree to see what is allowed for us */
static int
-enum_devices(const char *parent, struct pci_device_private **device,
- int domain, int bus, int dev, int func, tree_level lev)
+enum_devices(const char *parent, int domain,
+ int bus, int dev, int func, tree_level lev)
{
int err, ret;
DIR *dir;
@@ -315,6 +315,7 @@ enum_devices(const char *parent, struct pci_device_private
**device,
uint32_t reg;
size_t toread;
mach_port_t device_port;
+ struct pci_device_private *d, *devices;
dir = opendir(parent);
if (!dir)
@@ -353,11 +354,10 @@ enum_devices(const char *parent, struct
pci_device_private **device,
return -1;
}
- err = enum_devices(path, device, domain, bus, dev, func, lev+1);
- if (err == EPERM)
- continue;
- }
- else {
+ err = enum_devices(path, domain, bus, dev, func, lev+1);
+ if (err && err != EPERM && err != EACCES)
+ return err;
+ } else {
if (strncmp(entry->d_name, FILE_CONFIG_NAME, NAME_MAX))
/* We are looking for the config file */
continue;
@@ -378,12 +378,20 @@ enum_devices(const char *parent, struct
pci_device_private **device,
if (toread != sizeof(reg))
return -1;
- (*device)->base.domain = domain;
- (*device)->base.bus = bus;
- (*device)->base.dev = dev;
- (*device)->base.func = func;
- (*device)->base.vendor_id = PCI_VENDOR(reg);
- (*device)->base.device_id = PCI_DEVICE(reg);
+ devices = realloc(pci_sys->devices, (pci_sys->num_devices + 1)
+ * sizeof(struct pci_device_private));
+ if (!devices)
+ return ENOMEM;
+
+ d = devices + pci_sys->num_devices;
+ memset(d, 0, sizeof(struct pci_device_private));
+
+ d->base.domain = domain;
+ d->base.bus = bus;
+ d->base.dev = dev;
+ d->base.func = func;
+ d->base.vendor_id = PCI_VENDOR(reg);
+ d->base.device_id = PCI_DEVICE(reg);
toread = sizeof(reg);
err = pciclient_cfg_read(device_port, PCI_CLASS, (char*)®,
@@ -393,8 +401,8 @@ enum_devices(const char *parent, struct pci_device_private
**device,
if (toread != sizeof(reg))
return -1;
- (*device)->base.device_class = reg >> 8;
- (*device)->base.revision = reg & 0xFF;
+ d->base.device_class = reg >> 8;
+ d->base.revision = reg & 0xFF;
toread = sizeof(reg);
err = pciclient_cfg_read(device_port, PCI_SUB_VENDOR_ID,
@@ -404,12 +412,13 @@ enum_devices(const char *parent, struct
pci_device_private **device,
if (toread != sizeof(reg))
return -1;
- (*device)->base.subvendor_id = PCI_VENDOR(reg);
- (*device)->base.subdevice_id = PCI_DEVICE(reg);
+ d->base.subvendor_id = PCI_VENDOR(reg);
+ d->base.subdevice_id = PCI_DEVICE(reg);
- (*device)->device_port = device_port;
+ d->device_port = device_port;
- (*device)++;
+ pci_sys->devices = devices;
+ pci_sys->num_devices++;
}
}
@@ -441,11 +450,8 @@ static const struct pci_system_methods hurd_pci_methods = {
_pci_hidden int
pci_system_hurd_create(void)
{
- struct pci_device_private *device;
int err;
struct pci_system_hurd *pci_sys_hurd;
- size_t ndevs;
- mach_port_t pci_server_port;
/* If we can open pci cfg io ports on hurd,
* we are the arbiter, therefore try x86 method first */
@@ -462,35 +468,14 @@ pci_system_hurd_create(void)
pci_sys->methods = &hurd_pci_methods;
- pci_server_port = file_name_lookup(_SERVERS_BUS_PCI, 0, 0);
- if (!pci_server_port) {
- /* Fall back to x86 access method */
- return pci_system_x86_create();
- }
-
- /* The server gives us the number of available devices for us */
- err = pci_get_ndevs (pci_server_port, &ndevs);
+ pci_sys->num_devices = 0;
+ err = enum_devices(_SERVERS_BUS_PCI, -1, -1, -1, -1, LEVEL_DOMAIN);
if (err) {
- mach_port_deallocate (mach_task_self (), pci_server_port);
- /* Fall back to x86 access method */
- return pci_system_x86_create();
+ /* There was an error, but we don't know which devices have been
+ * initialized correctly, so call cleanup to free whatever is allocated
*/
+ pci_system_cleanup();
+ return err;
}
- mach_port_deallocate (mach_task_self (), pci_server_port);
-
- pci_sys->num_devices = ndevs;
- pci_sys->devices = calloc(ndevs, sizeof(struct pci_device_private));
- if (pci_sys->devices == NULL) {
- x86_disable_io();
- free(pci_sys_hurd);
- pci_sys = NULL;
- return ENOMEM;
- }
-
- device = pci_sys->devices;
- err = enum_devices(_SERVERS_BUS_PCI, &device, -1, -1, -1, -1,
- LEVEL_DOMAIN);
- if (err)
- return pci_system_x86_create();
return 0;
}
--
2.20.1
- [PATCH] libpciaccess: avoid using pci_get_ndevs(), Joan Lledó, 2019/11/03
- [PATCH] Hurd: avoid using the deprecated RPC pci_get_ndevs(),
Joan Lledó <=
- Re: [PATCH] Hurd: avoid using the deprecated RPC pci_get_ndevs(), Samuel Thibault, 2019/11/03
- Re: [PATCH] Hurd: avoid using the deprecated RPC pci_get_ndevs(), Joan Lledó, 2019/11/03
- Re: [PATCH] Hurd: avoid using the deprecated RPC pci_get_ndevs(), Samuel Thibault, 2019/11/03
- Re: [PATCH] Hurd: avoid using the deprecated RPC pci_get_ndevs(), Samuel Thibault, 2019/11/03
- Re: [PATCH] Hurd: avoid using the deprecated RPC pci_get_ndevs(), Samuel Thibault, 2019/11/03
- Re: [PATCH] Hurd: avoid using the deprecated RPC pci_get_ndevs(), Samuel Thibault, 2019/11/03
- Re: [PATCH] Hurd: avoid using the deprecated RPC pci_get_ndevs(), Samuel Thibault, 2019/11/03
- [PATCH] Hurd: avoid using the deprecated RPC pci_get_ndevs(), Joan Lledó, 2019/11/24
- [PATCH] Hurd: avoid using the deprecated RPC pci_get_ndevs(), Joan Lledó, 2019/11/24
- Re: [PATCH] Hurd: avoid using the deprecated RPC pci_get_ndevs(), Samuel Thibault, 2019/11/24