From 333a2a724af1665a5d40a08c2fabeb9e644f621a Mon Sep 17 00:00:00 2001 From: Laine Stump Date: Sun, 30 Jun 2013 23:51:00 -0400 Subject: [PATCH] pci: reorder static functions virPCIDeviceGetDriverPathAndName is a static function that will need to be called by another function that occurs above it in the file. This patch reorders the static functions so that a forward declaration isn't needed. --- src/util/virpci.c | 147 +++++++++++++++++++++++----------------------- 1 file changed, 75 insertions(+), 72 deletions(-) diff --git a/src/util/virpci.c b/src/util/virpci.c index 3fa4a3593..3f8625e2b 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -188,6 +188,81 @@ static int virPCIOnceInit(void) VIR_ONCE_GLOBAL_INIT(virPCI) + +static int +virPCIDriverDir(char **buffer, const char *driver) +{ + VIR_FREE(*buffer); + + return virAsprintf(buffer, PCI_SYSFS "drivers/%s", driver); +} + + +static int +virPCIDriverFile(char **buffer, const char *driver, const char *file) +{ + VIR_FREE(*buffer); + + return virAsprintf(buffer, PCI_SYSFS "drivers/%s/%s", driver, file); +} + + +static int +virPCIFile(char **buffer, const char *device, const char *file) +{ + VIR_FREE(*buffer); + + return virAsprintf(buffer, PCI_SYSFS "devices/%s/%s", device, file); +} + + +/* virPCIDeviceGetDriverPathAndName - put the path to the driver + * directory of the driver in use for this device in @path and the + * name of the driver in @name. Both could be NULL if it's not bound + * to any driver. + * + * Return 0 for success, -1 for error. + */ +static int +virPCIDeviceGetDriverPathAndName(virPCIDevicePtr dev, char **path, char **name) +{ + int ret = -1; + char *drvlink = NULL; + + *path = *name = NULL; + /* drvlink = "/sys/bus/pci/dddd:bb:ss.ff/driver" */ + if (virPCIFile(&drvlink, dev->name, "driver") < 0) + goto cleanup; + + if (virFileIsLink(drvlink) != 1) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Invalid device %s driver file %s is not a symlink"), + dev->name, drvlink); + goto cleanup; + } + if (virFileResolveLink(drvlink, path) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to resolve device %s driver symlink %s"), + dev->name, drvlink); + goto cleanup; + } + /* path = "/sys/bus/pci/drivers/${drivername}" */ + + if (VIR_STRDUP(*name, last_component(*path)) < 0) + goto cleanup; + /* name = "${drivername}" */ + + ret = 0; +cleanup: + VIR_FREE(drvlink); + if (ret < 0) { + VIR_FREE(*path); + VIR_FREE(*name); + } + return ret; +} + + static int virPCIDeviceConfigOpen(virPCIDevicePtr dev, bool fatal) { @@ -839,78 +914,6 @@ cleanup: } -static int -virPCIDriverDir(char **buffer, const char *driver) -{ - VIR_FREE(*buffer); - - return virAsprintf(buffer, PCI_SYSFS "drivers/%s", driver); -} - -static int -virPCIDriverFile(char **buffer, const char *driver, const char *file) -{ - VIR_FREE(*buffer); - - return virAsprintf(buffer, PCI_SYSFS "drivers/%s/%s", driver, file); -} - -static int -virPCIFile(char **buffer, const char *device, const char *file) -{ - VIR_FREE(*buffer); - - return virAsprintf(buffer, PCI_SYSFS "devices/%s/%s", device, file); -} - - -/* virPCIDeviceGetDriverPathAndName - put the path to the driver - * directory of the driver in use for this device in @path and the - * name of the driver in @name. Both could be NULL if it's not bound - * to any driver. - * - * Return 0 for success, -1 for error. - */ -static int -virPCIDeviceGetDriverPathAndName(virPCIDevicePtr dev, char **path, char **name) -{ - int ret = -1; - char *drvlink = NULL; - - *path = *name = NULL; - /* drvlink = "/sys/bus/pci/dddd:bb:ss.ff/driver" */ - if (virPCIFile(&drvlink, dev->name, "driver") < 0) - goto cleanup; - - if (virFileIsLink(drvlink) != 1) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Invalid device %s driver file %s is not a symlink"), - dev->name, drvlink); - goto cleanup; - } - if (virFileResolveLink(drvlink, path) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unable to resolve device %s driver symlink %s"), - dev->name, drvlink); - goto cleanup; - } - /* path = "/sys/bus/pci/drivers/${drivername}" */ - - if (VIR_STRDUP(*name, last_component(*path)) < 0) - goto cleanup; - /* name = "${drivername}" */ - - ret = 0; -cleanup: - VIR_FREE(drvlink); - if (ret < 0) { - VIR_FREE(*path); - VIR_FREE(*name); - } - return ret; -} - - static int virPCIProbeStubDriver(const char *driver) { -- 2.39.5