[PATCH] libpci: fix pci device allocation

Daniel Hellstrom daniel at gaisler.com
Wed Aug 30 14:22:45 UTC 2017


The refactoring of pci_dev_create() was incorrect since the code relied on
different defines before including pci/cfg.h. This reverts back to the
original code having two pci_dev_create() one in auto and one in read library.
confdefs.h selectes between the two libraries so both there is no link
conflict.

Updates #3029
---
 cpukit/libpci/Makefile.am      |  1 -
 cpukit/libpci/pci_cfg_auto.c   | 16 ++++++++++++++++
 cpukit/libpci/pci_cfg_read.c   | 16 ++++++++++++++++
 cpukit/libpci/pci_dev_create.c | 33 ---------------------------------
 cpukit/libpci/pci_internal.h   |  3 ---
 5 files changed, 32 insertions(+), 37 deletions(-)
 delete mode 100644 cpukit/libpci/pci_dev_create.c

diff --git a/cpukit/libpci/Makefile.am b/cpukit/libpci/Makefile.am
index cf336ed..cff25b3 100644
--- a/cpukit/libpci/Makefile.am
+++ b/cpukit/libpci/Makefile.am
@@ -28,7 +28,6 @@ libpci_a_SOURCES += pci_cfg_print_code.c
 libpci_a_SOURCES += pci_cfg_read.c
 libpci_a_SOURCES += pci_cfg_static.c
 libpci_a_SOURCES += pci_cfg_peripheral.c
-libpci_a_SOURCES += pci_dev_create.c
 libpci_a_SOURCES += pci_find.c
 libpci_a_SOURCES += pci_find_dev.c
 libpci_a_SOURCES += pci_for_each.c
diff --git a/cpukit/libpci/pci_cfg_auto.c b/cpukit/libpci/pci_cfg_auto.c
index 2f227b1..51e5765 100644
--- a/cpukit/libpci/pci_cfg_auto.c
+++ b/cpukit/libpci/pci_cfg_auto.c
@@ -267,6 +267,22 @@ static void pci_dev_free(struct pci_dev *dev)
 }
 #endif
 
+struct pci_dev *pci_dev_create(int isbus)
+{
+	void *ptr;
+	int size;
+
+	if (isbus)
+		size = sizeof(struct pci_bus);
+	else
+		size = sizeof(struct pci_dev);
+
+	ptr = calloc(1, size);
+	if (!ptr)
+		rtems_fatal_error_occurred(RTEMS_NO_MEMORY);
+	return ptr;
+}
+
 static void pci_find_devs(struct pci_bus *bus)
 {
 	uint32_t id, tmp;
diff --git a/cpukit/libpci/pci_cfg_read.c b/cpukit/libpci/pci_cfg_read.c
index 16c2928..f6cacfb 100644
--- a/cpukit/libpci/pci_cfg_read.c
+++ b/cpukit/libpci/pci_cfg_read.c
@@ -36,6 +36,22 @@
 /* The Host Bridge bus is initialized here */
 extern struct pci_bus pci_hb;
 
+struct pci_dev *pci_dev_create(int isbus)
+{
+	void *ptr;
+	int size;
+
+	if (isbus)
+		size = sizeof(struct pci_bus);
+	else
+		size = sizeof(struct pci_dev);
+
+	ptr = calloc(1, size);
+	if (!ptr)
+		rtems_fatal_error_occurred(RTEMS_NO_MEMORY);
+	return ptr;
+}
+
 /* Check if address is accessible from host */
 static int pci_read_addressable(struct pci_dev *dev, struct pci_res *res)
 {
diff --git a/cpukit/libpci/pci_dev_create.c b/cpukit/libpci/pci_dev_create.c
deleted file mode 100644
index 4e84397..0000000
--- a/cpukit/libpci/pci_dev_create.c
+++ /dev/null
@@ -1,33 +0,0 @@
-/*  Device allocator helper used by PCI Auto/Read Configuration Library
- *
- *  COPYRIGHT (c) 2010 Cobham Gaisler AB.
- *
- *  The license and distribution terms for this file may be
- *  found in the file LICENSE in this distribution or at
- *  http://www.rtems.org/license/LICENSE.
- */
-
-#include <rtems.h>
-#include <stdlib.h>
-#include <rtems/bspIo.h>
-
-#include <pci.h>
-#include <pci/cfg.h>
-
-#include "pci_internal.h"
-
-struct pci_dev *pci_dev_create(int isbus)
-{
-	void *ptr;
-	int size;
-
-	if (isbus)
-		size = sizeof(struct pci_bus);
-	else
-		size = sizeof(struct pci_dev);
-
-	ptr = calloc(1, size);
-	if (!ptr)
-		rtems_fatal_error_occurred(RTEMS_NO_MEMORY);
-	return ptr;
-}
diff --git a/cpukit/libpci/pci_internal.h b/cpukit/libpci/pci_internal.h
index a89e8f1..d0bb83c 100644
--- a/cpukit/libpci/pci_internal.h
+++ b/cpukit/libpci/pci_internal.h
@@ -9,6 +9,3 @@
 
 /* Number of buses */
 extern int pci_bus_cnt;
-
-/* Allocate a PCI device for a standard device or a bridge device */
-struct pci_dev *pci_dev_create(int isbus);
-- 
2.7.4



More information about the devel mailing list