Coverity Fixes: Several fixes to coverity issues in some sysbios-rpmsg files.
authorG Anthony <a0783926@ti.com>
Sat, 16 Mar 2013 01:08:37 +0000 (18:08 -0700)
committerChris Ring <cring@ti.com>
Sun, 17 Mar 2013 18:18:28 +0000 (11:18 -0700)
The coverity fixes address (or supress) the errors reported by coverity.

NOTE: the virtio_ring.h file copyright header triggers a tisb filter check;
but this is copyrighted by Rusty Russel, so commit was entered with the check
disabled.

Signed-off-by: G Anthony <a0783926@ti.com>
Signed-off-by: Chris Ring <cring@ti.com>
packages/ti/grcm/RcmServer.c
packages/ti/ipc/family/omap54xx/VirtQueue.c
packages/ti/ipc/rpmsg/virtio_ring.h
packages/ti/ipc/transports/TransportVirtio.c
packages/ti/pm/IpcPower.c
packages/ti/srvmgr/ServiceMgr.c
packages/ti/trace/SysMin.c

index 27c2910b7b07458362c22e33205f9ec798e34467..6ed7b5108ecbcfee143bd087de7ad0000221ddb1 100644 (file)
@@ -363,6 +363,13 @@ Int RcmServer_create(String name, RcmServer_Params *params,
 
     /* initialize the error block */
     Error_init(&eb);
+
+    if (NULL == handle) {
+        Log_error0(FXNN": Invalid pointer");
+        status = RcmServer_E_FAIL;
+        goto leave;
+    }
+
     *handle = (RcmServer_Handle)NULL;
 
     /* check for valid params */
@@ -371,11 +378,6 @@ Int RcmServer_create(String name, RcmServer_Params *params,
         status = RcmServer_E_FAIL;
         goto leave;
     }
-    if (NULL == handle) {
-        Log_error0(FXNN": Invalid pointer");
-        status = RcmServer_E_FAIL;
-        goto leave;
-    }
     if (NULL == name) {
         Log_error0(FXNN": name passed is NULL!");
         status = RcmServer_E_FAIL;
@@ -1178,7 +1180,7 @@ Int RcmServer_addSymbol(RcmServer_Object *obj, String funcName,
         slot->addr.fxn = addr;
         len = _strlen(funcName) + 1;
         slot->name = (String)xdc_runtime_Memory_alloc(
-            RcmServer_Module_heap(), len, sizeof(Char *), &eb);
+            RcmServer_Module_heap(), len, 0, &eb);
 
         if (Error_check(&eb)) {
             Log_error0(FXNN": unable to allocate function name");
index 6916a93e2eeea7f972233941f45730a476a4e361..778d368cdc3287d59b38abb3bd9d16b633568c58 100644 (file)
@@ -169,8 +169,8 @@ enum {
 #define ID_A9_TO_SYSM3      ID_A9_TO_SELF
 #define ID_DSP_TO_A9        ID_SELF_TO_A9
 #define ID_A9_TO_DSP        ID_A9_TO_SELF
-#define ID_APPM3_TO_A9      200
-#define ID_A9_TO_APPM3      201
+#define ID_APPM3_TO_A9      2
+#define ID_A9_TO_APPM3      3
 
 typedef struct VirtQueue_Object {
     /* Id for this VirtQueue_Object */
@@ -377,8 +377,11 @@ Void VirtQueue_isr(UArg msg)
 
             case (UInt)RP_MBOX_ABORT_REQUEST:
                 {
+                    /* Suppress Coverity Error: FORWARD_NULL: */
+                    // coverity[assign_zero]
                     Fxn f = (Fxn)0x0;
                     Log_print0(Diags_USER1, "Crash on demand ...\n");
+                    // coverity[var_deref_op]
                     f();
                 }
                 return;
@@ -469,7 +472,7 @@ VirtQueue_Handle VirtQueue_create(UInt16 remoteProcId, VirtQueue_Params *params,
     Void *vringAddr;
 
     vq = Memory_alloc(NULL, sizeof(VirtQueue_Object), 0, eb);
-    if (!vq) {
+    if (NULL == vq) {
         return (NULL);
     }
 
@@ -482,7 +485,7 @@ VirtQueue_Handle VirtQueue_create(UInt16 remoteProcId, VirtQueue_Params *params,
     if (MultiProc_self() == appm3ProcId) {
         /* vqindices that belong to AppM3 should be big so they don't
          * collide with SysM3's virtqueues */
-        vq->id += 200;
+         vq->id += 2;
     }
 #endif
 
@@ -506,12 +509,16 @@ VirtQueue_Handle VirtQueue_create(UInt16 remoteProcId, VirtQueue_Params *params,
             vringAddr = (struct vring *) IPC_MEM_VRING3;
             break;
 #endif
+        default:
+            return (NULL);
     }
 
     Log_print3(Diags_USER1,
             "vring: %d 0x%x (0x%x)\n", vq->id, (IArg)vringAddr,
             RP_MSG_RING_SIZE);
 
+    /* See coverity related comment in vring_init() */
+    // coverity[overrun-call]
     vring_init(&(vq->vring), RP_MSG_NUM_BUFS, vringAddr, RP_MSG_VRING_ALIGN);
 
     /*
index dc06f96adb073607c5f388087a798c7b6b1a8600..be722a9e8e06efc8820ee0de7a897c91d68f9773 100644 (file)
@@ -132,6 +132,11 @@ static inline void vring_init(struct vring *vr, unsigned int num, void *p,
     vr->desc = p;
     vr->avail = (struct vring_avail *)
                     ((unsigned)p + (num * sizeof(struct vring_desc)));
+    /*
+     * Suppress Coverity Error: Indexing "vr->avail->ring" with "num".
+     * This should be OK, because this is just address calculation:
+     */
+    // coverity[index_parm]
     vr->used = (void *)(((unsigned long)&vr->avail->ring[num] + pagesize-1)
                 & ~(pagesize - 1));
 }
index 42680a93a050f273dd7c8e197b50a3e2c4e7b97f..4775608a0368f3dd80057ba29b6dc309f778416e 100644 (file)
@@ -90,7 +90,7 @@ Int TransportVirtio_Instance_init(TransportVirtio_Object *obj,
         UInt16 remoteProcId, const TransportVirtio_Params *params,
         Error_Block *eb)
 {
-    Bool        flag;
+    Bool        flag = FALSE;
     UInt32      myEndpoint = 0;
 
     Log_print1(Diags_INFO, FXNN": remoteProc: %d\n", remoteProcId);
index 5834b592676cee27bc8ed6c79d3522650a0abd77..f52d873dafeedf22fb08ab12a7da6bde3d273f8d 100644 (file)
@@ -147,6 +147,7 @@ static inline Void IpcPower_sleepMode(IpcPower_SleepMode opt)
             if (refWakeLockCnt) {
                 refWakeLockCnt--;
             }
+            /* Fall through: */
         case IpcPower_SLEEP_MODE_DEEPSLEEP:
             if (!refWakeLockCnt) {
                 IpcPower_deepSleep = TRUE;
index 4f609b34092e6e440dbe3b597782c3b657cac1f3..add304df1cf5c00b127b128669dabec017c4a10e 100644 (file)
@@ -146,7 +146,8 @@ Bool ServiceMgr_registerSrvTask(UInt16 reserved, Task_FuncPtr func,
         if (!serviceTasks[i].taken) {
             st = &serviceTasks[i];
             st->fxn = func;
-            strcpy(st->name, taskParams->instance->name);
+            strncpy(st->name, taskParams->instance->name, MAX_NAMELEN-1);
+            st->name[MAX_NAMELEN-1] = '\0';
 
             /* Deal with the Task_Params to avoid IInstance mismatch */
             params = &st->params;
index 339ce46c80b3dc2026836a74ade585e205586d97..6e0db82ae68555c19675a4d6025bfab13b6f1bb0 100644 (file)
@@ -188,7 +188,7 @@ Void SysMin_putch(Char ch)
 #else
         if (module->getTime == TRUE) {
 #endif
-            uSec  = Clock_getTicks() * Clock_tickPeriod;
+            uSec  = Clock_getTicks() * (UInt64)Clock_tickPeriod;
             SysMin_output('[');
             if (uSec) {
                 sprintf(timeStamp, "%17llu\0", uSec);