QNX: GateMP: Check Number of Resources for Gates Before Mapping
authorAngela Stegmaier <angelabaker@ti.com>
Thu, 22 Oct 2015 22:00:05 +0000 (17:00 -0500)
committerAngela Stegmaier <angelabaker@ti.com>
Thu, 29 Oct 2015 21:53:43 +0000 (16:53 -0500)
A recent change to the BIOS-side GateMPSupportNull exposed an issue in
the GateMP module in which it may attempt to map an address of 0x0.
Previously, when GateMPSupportNull was used, the number of resources
was set as 1 and a valid address was obtained. With the update,
the number of resources for GateMPSupportNull is now 0. In this case,
the GateMP code will attempt to map an address of 0x0, of size 0,
which will fail.

This patch fixes the code to first check that the number of resources
is not 0, and only then proceed with the mapping. If the number of
resources is 0, then we skip the mapping for that remote gate.

This patch also makes a minor update to the LOGs for the failure
cases for mapping remoteCustom1InUse and remoteCustom2InUse to
print the proper remote InUse array.

Signed-off-by: Angela Stegmaier <angelabaker@ti.com>
qnx/src/ipc3x_dev/ti/syslink/ipc/hlos/knl/GateMP_daemon.c

index 9cc7c1616bb30aa2f36e447cd70931c81b07c4a7..c3fa5dcd3cf577f5c0ac1f301603efc54b377475 100644 (file)
@@ -206,17 +206,21 @@ Int GateMP_setup(Int32 * sr0ProcId)
             GateMP_module->numRemoteCustom2 = nsValue[5];
 
             /* Map InUse arrays to daemon's address space */
-            GateMP_module->remoteSystemInUse = mmap(NULL,
-                GateMP_module->numRemoteSystem * sizeof (UInt8),
-                (PROT_READ|PROT_WRITE|PROT_NOCACHE),
-                (MAP_PHYS|MAP_SHARED), NOFD, (off_t)nsValue[0]);
-            if (GateMP_module->remoteSystemInUse == MAP_FAILED) {
-                 GateMP_module->remoteSystemInUse = NULL;
-                 status = GateMP_E_MEMORY;
-                 LOG0("Failed to map remoteSystemInUse to host address space!");
+            if (GateMP_module->numRemoteSystem != 0) {
+                GateMP_module->remoteSystemInUse = mmap(NULL,
+                    GateMP_module->numRemoteSystem * sizeof (UInt8),
+                    (PROT_READ|PROT_WRITE|PROT_NOCACHE),
+                    (MAP_PHYS|MAP_SHARED), NOFD, (off_t)nsValue[0]);
+                if (GateMP_module->remoteSystemInUse == MAP_FAILED) {
+                    GateMP_module->remoteSystemInUse = NULL;
+                    status = GateMP_E_MEMORY;
+                    LOG0("Failed to map remoteSystemInUse to host address" \
+                         " space!");
+                }
             }
 
-            if (status == GateMP_S_SUCCESS) {
+            if ((status == GateMP_S_SUCCESS) &&
+                (GateMP_module->numRemoteCustom1 != 0)) {
                 GateMP_module->remoteCustom1InUse = mmap(NULL,
                     GateMP_module->numRemoteCustom1 * sizeof (UInt8),
                     (PROT_READ|PROT_WRITE|PROT_NOCACHE),
@@ -224,12 +228,13 @@ Int GateMP_setup(Int32 * sr0ProcId)
                 if (GateMP_module->remoteCustom1InUse == MAP_FAILED) {
                     GateMP_module->remoteCustom1InUse = NULL;
                     status = GateMP_E_MEMORY;
-                    LOG0("Failed to map remoteSystemInUse to host address" \
+                    LOG0("Failed to map remoteCustom1InUse to host address" \
                         " space!");
                 }
             }
 
-            if (status == GateMP_S_SUCCESS) {
+            if ((status == GateMP_S_SUCCESS) &&
+                (GateMP_module->numRemoteCustom2 != 0)) {
                 GateMP_module->remoteCustom2InUse = mmap(NULL,
                     GateMP_module->numRemoteCustom2 * sizeof (UInt8),
                     (PROT_READ|PROT_WRITE|PROT_NOCACHE),
@@ -237,7 +242,7 @@ Int GateMP_setup(Int32 * sr0ProcId)
                 if (GateMP_module->remoteCustom2InUse == MAP_FAILED) {
                     GateMP_module->remoteCustom2InUse = NULL;
                     status = GateMP_E_MEMORY;
-                    LOG0("Failed to map remoteSystemInUse to host address" \
+                    LOG0("Failed to map remoteCustom2InUse to host address" \
                         " space!");
                 }
             }