From: Martin Mares Date: Sat, 4 Mar 2023 16:23:06 +0000 (+0100) Subject: win32-cfgmgr32: Clean up initialization X-Git-Tag: v3.10.0~10 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=ea404c2a8800e1dfef2c4165edae15c82530da00;p=pciutils.git win32-cfgmgr32: Clean up initialization --- diff --git a/lib/init.c b/lib/init.c index ffb55e8..b38b8bb 100644 --- a/lib/init.c +++ b/lib/init.c @@ -420,8 +420,8 @@ pci_alloc(void) return a; } -void -pci_init_internal(struct pci_access *a, int throw_errors, int skip_method) +int +pci_init_internal(struct pci_access *a, int skip_method) { if (!a->error) a->error = pci_generic_error; @@ -432,14 +432,10 @@ pci_init_internal(struct pci_access *a, int throw_errors, int skip_method) if (!a->debugging) a->debug = pci_null_debug; - if (a->method) + if (a->method != PCI_ACCESS_AUTO) { if (a->method >= PCI_ACCESS_MAX || !pci_methods[a->method]) - { - if (throw_errors) - a->error("This access method is not supported."); - return; - } + a->error("This access method is not supported."); a->methods = pci_methods[a->method]; } else @@ -463,20 +459,18 @@ pci_init_internal(struct pci_access *a, int throw_errors, int skip_method) a->debug("...No.\n"); } if (!a->methods) - { - if (throw_errors) - a->error("Cannot find any working access method."); - return; - } + return 0; } a->debug("Decided to use %s\n", a->methods->name); a->methods->init(a); + return 1; } void pci_init_v35(struct pci_access *a) { - pci_init_internal(a, 1, -1); + if (!pci_init_internal(a, 1, -1)) + a->error("Cannot find any working access method."); } STATIC_ALIAS(void pci_init(struct pci_access *a), pci_init_v35(a)); @@ -484,6 +478,21 @@ DEFINE_ALIAS(void pci_init_v30(struct pci_access *a), pci_init_v35); SYMBOL_VERSION(pci_init_v30, pci_init@LIBPCI_3.0); SYMBOL_VERSION(pci_init_v35, pci_init@@LIBPCI_3.5); +struct pci_access * +pci_clone_access(struct pci_access *a) +{ + struct pci_access *b = pci_alloc(); + + b->writeable = a->writeable; + b->buscentric = a->buscentric; + b->debugging = a->debugging; + b->error = a->error; + b->warning = a->warning; + b->debug = a->debug; + + return b; +} + void pci_cleanup(struct pci_access *a) { diff --git a/lib/internal.h b/lib/internal.h index 7f19db4..a4eb39c 100644 --- a/lib/internal.h +++ b/lib/internal.h @@ -81,7 +81,8 @@ int pci_emulated_read(struct pci_dev *d, int pos, byte *buf, int len); void *pci_malloc(struct pci_access *, int); void pci_mfree(void *); char *pci_strdup(struct pci_access *a, const char *s); -void pci_init_internal(struct pci_access *a, int throw_errors, int skip_method); +struct pci_access *pci_clone_access(struct pci_access *a); +int pci_init_internal(struct pci_access *a, int skip_method); void pci_init_v30(struct pci_access *a) VERSIONED_ABI; void pci_init_v35(struct pci_access *a) VERSIONED_ABI; diff --git a/lib/win32-cfgmgr32.c b/lib/win32-cfgmgr32.c index d63756b..9743002 100644 --- a/lib/win32-cfgmgr32.c +++ b/lib/win32-cfgmgr32.c @@ -1735,40 +1735,32 @@ win32_cfgmgr32_init(struct pci_access *a) if (strcmp(cfgmethod, "") == 0 || strcmp(cfgmethod, "auto") == 0) { - acfg = pci_alloc(); + acfg = pci_clone_access(a); acfg->method = PCI_ACCESS_AUTO; } - else if (strcmp(cfgmethod, "none") != 0 && - strcmp(cfgmethod, "win32-cfgmgr32") != 0) - { - int m = pci_lookup_method(cfgmethod); - if (m < 0) - a->error("Option win32.cfgmethod is set to unknown access method \"%s\".", cfgmethod); - acfg = pci_alloc(); - acfg->method = m; - } - else + else if (strcmp(cfgmethod, "none") == 0 || + strcmp(cfgmethod, "win32-cfgmgr32") == 0) { if (a->writeable) a->error("Write access requested but option win32.cfgmethod was not set."); return; } - - acfg->writeable = a->writeable; - acfg->buscentric = a->buscentric; - acfg->debugging = a->debugging; - acfg->error = a->error; - acfg->warning = a->warning; - acfg->debug = a->debug; + else + { + int m = pci_lookup_method(cfgmethod); + if (m < 0) + a->error("Option win32.cfgmethod is set to an unknown access method \"%s\".", cfgmethod); + acfg = pci_clone_access(a); + acfg->method = m; + } a->debug("Loading config space access method...\n"); - pci_init_internal(acfg, 0, PCI_ACCESS_WIN32_CFGMGR32); - if (!acfg->methods) + if (!pci_init_internal(acfg, PCI_ACCESS_WIN32_CFGMGR32)) { pci_cleanup(acfg); a->debug("Cannot find any working config space access method.\n"); if (a->writeable) - a->error("Write access requested but no usable access method."); + a->error("Write access requested but no usable access method found."); return; } diff --git a/pcilib.man b/pcilib.man index 31c7ae0..91906d8 100644 --- a/pcilib.man +++ b/pcilib.man @@ -176,6 +176,8 @@ Config space access method to use with win32-cfgmgr32 on Windows systems. Value or an empty string selects the first access method which supports access to the config space on Windows. Value .I win32-cfgmgr32 +or +.I none only builds a read-only virtual emulated config space with information from the Configuration Manager.