Re: [PATCH] export PCI resources in sysfs

From: Jesse Barnes
Date: Tue Dec 21 2004 - 14:23:19 EST


On Tuesday, December 21, 2004 10:43 am, Greg KH wrote:
> 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.

Yeah, that sounds good. I really don't like adding these ifdefs, and limiting
their scope to a function somewhere up above would be nicer. I'll do that
and respin.

Thanks,
Jesse
-
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/