Skip to content

Commit a844158

Browse files
hormsjbarnes993
authored andcommitted
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: Simon Horman <horms@verge.net.au> Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
1 parent abad2ec commit a844158

File tree

1 file changed

+38
-16
lines changed

1 file changed

+38
-16
lines changed

drivers/pci/probe.c

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,49 @@ EXPORT_SYMBOL(no_pci_devices);
5252
* Some platforms allow access to legacy I/O port and ISA memory space on
5353
* a per-bus basis. This routine creates the files and ties them into
5454
* their associated read, write and mmap files from pci-sysfs.c
55+
*
56+
* On error unwind, but don't propogate the error to the caller
57+
* as it is ok to set up the PCI bus without these files.
5558
*/
5659
static void pci_create_legacy_files(struct pci_bus *b)
5760
{
61+
int error;
62+
5863
b->legacy_io = kzalloc(sizeof(struct bin_attribute) * 2,
5964
GFP_ATOMIC);
60-
if (b->legacy_io) {
61-
b->legacy_io->attr.name = "legacy_io";
62-
b->legacy_io->size = 0xffff;
63-
b->legacy_io->attr.mode = S_IRUSR | S_IWUSR;
64-
b->legacy_io->read = pci_read_legacy_io;
65-
b->legacy_io->write = pci_write_legacy_io;
66-
device_create_bin_file(&b->dev, b->legacy_io);
67-
68-
/* Allocated above after the legacy_io struct */
69-
b->legacy_mem = b->legacy_io + 1;
70-
b->legacy_mem->attr.name = "legacy_mem";
71-
b->legacy_mem->size = 1024*1024;
72-
b->legacy_mem->attr.mode = S_IRUSR | S_IWUSR;
73-
b->legacy_mem->mmap = pci_mmap_legacy_mem;
74-
device_create_bin_file(&b->dev, b->legacy_mem);
75-
}
65+
if (!b->legacy_io)
66+
goto kzalloc_err;
67+
68+
b->legacy_io->attr.name = "legacy_io";
69+
b->legacy_io->size = 0xffff;
70+
b->legacy_io->attr.mode = S_IRUSR | S_IWUSR;
71+
b->legacy_io->read = pci_read_legacy_io;
72+
b->legacy_io->write = pci_write_legacy_io;
73+
error = device_create_bin_file(&b->dev, b->legacy_io);
74+
if (error)
75+
goto legacy_io_err;
76+
77+
/* Allocated above after the legacy_io struct */
78+
b->legacy_mem = b->legacy_io + 1;
79+
b->legacy_mem->attr.name = "legacy_mem";
80+
b->legacy_mem->size = 1024*1024;
81+
b->legacy_mem->attr.mode = S_IRUSR | S_IWUSR;
82+
b->legacy_mem->mmap = pci_mmap_legacy_mem;
83+
error = device_create_bin_file(&b->dev, b->legacy_mem);
84+
if (error)
85+
goto legacy_mem_err;
86+
87+
return;
88+
89+
legacy_mem_err:
90+
device_remove_bin_file(&b->dev, b->legacy_io);
91+
legacy_io_err:
92+
kfree(b->legacy_io);
93+
b->legacy_io = NULL;
94+
kzalloc_err:
95+
printk(KERN_WARNING "pci: warning: could not create legacy I/O port "
96+
"and ISA memory resources to sysfs\n");
97+
return;
7698
}
7799

78100
void pci_remove_legacy_files(struct pci_bus *b)

0 commit comments

Comments
 (0)