Commit a844158a authored by Simon Horman's avatar Simon Horman Committed by Jesse Barnes

PCI: check the return value of device_create_bin_file() in pci_create_bus()

Check the return value of device_create_bin_file in pci_create_bus and
unwind if necessary. Don't propagate error to caller, as failure to create
these files shouldn't prevent PCI from being initialised. Instead, just
log a warning.

Cc: Sven Wegener <sven.wegener@stealer.net>
Cc: Michael Ellerman <michael@ellerman.id.au>
Cc: Matthew Wilcox <matthew@wil.cx>
Signed-off-by: default avatarSimon Horman <horms@verge.net.au>
Signed-off-by: default avatarJesse Barnes <jbarnes@virtuousgeek.org>
parent abad2ec9
...@@ -52,27 +52,49 @@ EXPORT_SYMBOL(no_pci_devices); ...@@ -52,27 +52,49 @@ EXPORT_SYMBOL(no_pci_devices);
* Some platforms allow access to legacy I/O port and ISA memory space on * Some platforms allow access to legacy I/O port and ISA memory space on
* a per-bus basis. This routine creates the files and ties them into * a per-bus basis. This routine creates the files and ties them into
* their associated read, write and mmap files from pci-sysfs.c * their associated read, write and mmap files from pci-sysfs.c
*
* On error unwind, but don't propogate the error to the caller
* as it is ok to set up the PCI bus without these files.
*/ */
static void pci_create_legacy_files(struct pci_bus *b) static void pci_create_legacy_files(struct pci_bus *b)
{ {
int error;
b->legacy_io = kzalloc(sizeof(struct bin_attribute) * 2, b->legacy_io = kzalloc(sizeof(struct bin_attribute) * 2,
GFP_ATOMIC); GFP_ATOMIC);
if (b->legacy_io) { if (!b->legacy_io)
b->legacy_io->attr.name = "legacy_io"; goto kzalloc_err;
b->legacy_io->size = 0xffff;
b->legacy_io->attr.mode = S_IRUSR | S_IWUSR; b->legacy_io->attr.name = "legacy_io";
b->legacy_io->read = pci_read_legacy_io; b->legacy_io->size = 0xffff;
b->legacy_io->write = pci_write_legacy_io; b->legacy_io->attr.mode = S_IRUSR | S_IWUSR;
device_create_bin_file(&b->dev, b->legacy_io); b->legacy_io->read = pci_read_legacy_io;
b->legacy_io->write = pci_write_legacy_io;
/* Allocated above after the legacy_io struct */ error = device_create_bin_file(&b->dev, b->legacy_io);
b->legacy_mem = b->legacy_io + 1; if (error)
b->legacy_mem->attr.name = "legacy_mem"; goto legacy_io_err;
b->legacy_mem->size = 1024*1024;
b->legacy_mem->attr.mode = S_IRUSR | S_IWUSR; /* Allocated above after the legacy_io struct */
b->legacy_mem->mmap = pci_mmap_legacy_mem; b->legacy_mem = b->legacy_io + 1;
device_create_bin_file(&b->dev, b->legacy_mem); b->legacy_mem->attr.name = "legacy_mem";
} b->legacy_mem->size = 1024*1024;
b->legacy_mem->attr.mode = S_IRUSR | S_IWUSR;
b->legacy_mem->mmap = pci_mmap_legacy_mem;
error = device_create_bin_file(&b->dev, b->legacy_mem);
if (error)
goto legacy_mem_err;
return;
legacy_mem_err:
device_remove_bin_file(&b->dev, b->legacy_io);
legacy_io_err:
kfree(b->legacy_io);
b->legacy_io = NULL;
kzalloc_err:
printk(KERN_WARNING "pci: warning: could not create legacy I/O port "
"and ISA memory resources to sysfs\n");
return;
} }
void pci_remove_legacy_files(struct pci_bus *b) void pci_remove_legacy_files(struct pci_bus *b)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment