From fd182dad6414bc614d6efb3f6deabb0d7e4543a7 Mon Sep 17 00:00:00 2001 From: Bowen Wang Date: Wed, 29 May 2024 13:55:00 +0800 Subject: [PATCH] drivers/pci: add error handle for pci_alloc_bus/device() Signed-off-by: Bowen Wang --- drivers/pci/pci.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 568bfb464e2e2..231e43a68cb6c 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -556,6 +556,10 @@ static FAR struct pci_bus_s *pci_alloc_bus(void) FAR struct pci_bus_s *bus; bus = kmm_zalloc(sizeof(*bus)); + if (bus == NULL) + { + return NULL; + } list_initialize(&bus->node); list_initialize(&bus->children); @@ -580,6 +584,10 @@ static FAR struct pci_device_s *pci_alloc_device(void) FAR struct pci_device_s *dev; dev = kmm_zalloc(sizeof(*dev)); + if (dev == NULL) + { + return NULL; + } list_initialize(&dev->node); list_initialize(&dev->bus_list); @@ -2069,6 +2077,11 @@ int pci_register_controller(FAR struct pci_controller_s *ctrl) } bus = pci_alloc_bus(); + if (bus == NULL) + { + return -ENOMEM; + } + bus->ctrl = ctrl; ctrl->bus = bus;