Re: [PATCH] export PCI resources in sysfs

From: Greg KH
Date: Tue Dec 21 2004 - 13:47:25 EST


On Tue, Dec 21, 2004 at 09:43:39AM -0800, Jesse Barnes wrote:
> int pci_create_sysfs_dev_files (struct pci_dev *pdev)
> {
> +#ifdef HAVE_PCI_MMAP
> + int i;
> +#endif
> +
> if (!sysfs_initialized)
> return -EACCES;
>
> @@ -269,6 +300,31 @@
> else
> sysfs_create_bin_file(&pdev->dev.kobj, &pcie_config_attr);
>
> +#ifdef HAVE_PCI_MMAP
> + /* Expose the PCI resources from this device as files */
> + for (i = 0; i < PCI_ROM_RESOURCE; i++) {
> + struct bin_attribute *res_attr;
> +
> + /* skip empty resources */
> + if (!pci_resource_len(pdev, i))
> + continue;
> +
> + res_attr = kmalloc(sizeof(*res_attr) + 10, GFP_ATOMIC);
> + if (res_attr) {
> + pdev->res_attr[i] = res_attr;
> + /* Allocated above after the res_attr struct */
> + res_attr->attr.name = (char *)(res_attr + 1);
> + sprintf(res_attr->attr.name, "resource%d", i);
> + res_attr->size = pci_resource_len(pdev, i);
> + res_attr->attr.mode = S_IRUSR | S_IWUSR;
> + res_attr->attr.owner = THIS_MODULE;
> + res_attr->mmap = pci_mmap_resource;
> + res_attr->private = &pdev->resource[i];
> + sysfs_create_bin_file(&pdev->dev.kobj, res_attr);
> + }
> + }
> +#endif /* HAVE_PCI_MMAP */

How about wrapping these two #ifdef blocks into one function, and moving
it up in the file under the other #ifdef. Do that for the other cleanup
function, and it will drop a bunch of #ifdefs.

thanks,

greg k-h
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/