Skip to content

Commit fd182da

Browse files
CV-Bowenxiaoxiang781216
authored andcommitted
drivers/pci: add error handle for pci_alloc_bus/device()
Signed-off-by: Bowen Wang <[email protected]>
1 parent e8f6b1e commit fd182da

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

drivers/pci/pci.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,10 @@ static FAR struct pci_bus_s *pci_alloc_bus(void)
556556
FAR struct pci_bus_s *bus;
557557

558558
bus = kmm_zalloc(sizeof(*bus));
559+
if (bus == NULL)
560+
{
561+
return NULL;
562+
}
559563

560564
list_initialize(&bus->node);
561565
list_initialize(&bus->children);
@@ -580,6 +584,10 @@ static FAR struct pci_device_s *pci_alloc_device(void)
580584
FAR struct pci_device_s *dev;
581585

582586
dev = kmm_zalloc(sizeof(*dev));
587+
if (dev == NULL)
588+
{
589+
return NULL;
590+
}
583591

584592
list_initialize(&dev->node);
585593
list_initialize(&dev->bus_list);
@@ -2069,6 +2077,11 @@ int pci_register_controller(FAR struct pci_controller_s *ctrl)
20692077
}
20702078

20712079
bus = pci_alloc_bus();
2080+
if (bus == NULL)
2081+
{
2082+
return -ENOMEM;
2083+
}
2084+
20722085
bus->ctrl = ctrl;
20732086

20742087
ctrl->bus = bus;

0 commit comments

Comments
 (0)