[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH v2 4/4] libxl: Add interface for querying hypervisor about PCI topology



On Mon, Jan 05, 2015 at 09:18:57PM -0500, Boris Ostrovsky wrote:
[...]
> +int libxl__pci_topology_init(libxl__gc *gc,
> +                             xen_sysctl_pcitopo_t *pcitopo,
> +                             int numdev)
> +{
> +
> +    DIR *dir;
> +    struct dirent *entry;
> +    int i;
> +
> +    dir = opendir("/sys/bus/pci/devices");
> +    if (!dir) {
> +        LOGEV(ERROR, errno, "Cannot open /sys/bus/pci/devices");
> +        return ERROR_FAIL;
> +    }
> +
> +    i = 0;
> +    while ((entry = readdir(dir))) {
> +        unsigned int dom, bus, dev, func;
> +
> +        /* ".", ".." or a special non-device perhaps */
> +        if (entry->d_name[0] == '.')
> +            continue;
> +
> +        if (i == numdev) {
> +            LOGE(ERROR, "Too many devices\n");
> +            closedir(dir);
> +            return ERROR_FAIL;

Please use "goto out" idiom.

Wei.

> +        }
> +
> +        if (sscanf(entry->d_name, "%x:%x:%x.%d", &dom, &bus, &dev, &func) < 
> 4) {
> +            LOGEV(ERROR, errno, "Error processing /sys/bus/pci/devices");
> +            closedir(dir);
> +            return ERROR_FAIL;
> +        }
> +

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.