Coverity fixes
authorJustin Sobota <jsobota@ti.com>
Tue, 9 Apr 2013 22:48:03 +0000 (18:48 -0400)
committerJustin Sobota <jsobota@ti.com>
Tue, 9 Apr 2013 22:48:03 +0000 (18:48 -0400)
include/rm_allocatorloc.h
include/rm_policyloc.h
src/rm.c
src/rm_allocator.c
src/rm_policy.c

index ad7373c9160c20d066172846f6f79c738f94949e..fad2f91c8cc8b9e7ef9e91a327ba7642e6336852 100644 (file)
@@ -73,12 +73,16 @@ typedef struct {
 
 /* Resource allocator operations */
 typedef enum {
-    /* Allocate operation */
-    Rm_allocatorOp_ALLOCATE = 0,
+    /* Allocate init operation */
+    Rm_allocatorOp_ALLOCATE_INIT = 0,
+    /* Allocate use operation */
+    Rm_allocatorOp_ALLOCATE_USE,
     /* Free operation */
     Rm_allocatorOp_FREE,
-    /* Preallocate based on Policy DTB information operation */
-    Rm_allocatorOp_PRE_ALLOCATE
+    /* Preallocate to use based on Policy DTB information operation */
+    Rm_allocatorOp_PRE_ALLOCATE_INIT,
+    /* Preallocate to init based on Policy DTB information operation */
+    Rm_allocatorOp_PRE_ALLOCATE_USE
 } Rm_AllocatorOp;
 
 /* Allocator operation configuration structure */
@@ -89,10 +93,6 @@ typedef struct {
     Rm_PolicyValidInstNode *serviceSrcInstNode;
     /* Allocator operation type */
     Rm_AllocatorOp          operation;
-    /* Specifies the type of allocation
-     * a) Allocate to initialize
-     * b) Allocate to use */
-    uint32_t                allocType;
     /* Resources for which the allocator operation will affect */
     Rm_ResourceInfo        *resourceInfo;
 } Rm_AllocatorOpInfo;
index b28919c917c5bfec8ec3870ba1ecc648f5129f00..f430343b5ef58498a42b391158b8a6f2ff169897 100644 (file)
@@ -152,7 +152,7 @@ Rm_PolicyValidInstNode *rmPolicyGetValidInstNode(Rm_Handle rmHandle, char *instN
 Rm_PolicyValidInstNode *rmPolicyGetLinuxInstNode(Rm_Handle rmHandle);
 int rmPolicyCheckPrivilege(Rm_PolicyCheckCfg *privilegeCfg, int32_t *result);
 uint32_t rmPolicyGetResourceBase(void *policyDtb, Rm_PolicyValidInstNode *validInstNode, 
-                                 int32_t resourceOffset, uint32_t allocType, 
+                                 int32_t resourceOffset, Rm_PolicyCheckType policyCheckType, 
                                  int32_t *result);
 uint32_t rmPolicyGetResourceAlignment(void *policyDtb, int32_t resourceOffset);
 int32_t rmPolicyGetResourceOffset(void *policyDtb, char *resourceName);
index 1cfd0a41313066b758685b5d0b3e7655eae4b439..3afc89ed2908db1c4a0706c88d809501e9433843 100644 (file)
--- a/src/rm.c
+++ b/src/rm.c
@@ -434,15 +434,6 @@ static void allocationHandler (Rm_Inst *rmInst, Rm_Transaction *transaction)
         opInfo.resourceInfo = &transaction->resourceInfo;
         opInfo.serviceSrcInstNode = rmPolicyGetValidInstNode((Rm_Handle)rmInst, transaction->serviceSrcInstName);
         if (opInfo.serviceSrcInstNode) {
-            switch (transaction->type) {
-                case Rm_service_RESOURCE_ALLOCATE_INIT:
-                    RM_policy_SET_PERM(opInfo.allocType, RM_POLICY_PERM_INIT_SHIFT, 1);
-                    break;
-                case Rm_service_RESOURCE_ALLOCATE_USE:
-                    RM_policy_SET_PERM(opInfo.allocType, RM_POLICY_PERM_USE_SHIFT, 1);    
-                    break;
-            }        
-
             /* Populated NameServer name has precedence over base */
             if (strlen(transaction->resourceInfo.nameServerName) > 0) {
                 if ((transaction->resourceInfo.base == 0) &&
@@ -462,25 +453,42 @@ static void allocationHandler (Rm_Inst *rmInst, Rm_Transaction *transaction)
                 }
                 else {
                     retVal = RM_ERROR_NS_NAME_AND_RES_VAL_CONFLICT;
+                    goto errorExit;
                 }
             }
 
-            if (retVal == RM_SERVICE_PROCESSING) {      
-                if (transaction->resourceInfo.base == RM_RESOURCE_BASE_UNSPECIFIED) {
-                    opInfo.operation = Rm_allocatorOp_PRE_ALLOCATE;
-                    retVal = rmAllocatorOperation((Rm_Handle)rmInst, &opInfo);
+            if (transaction->resourceInfo.base == RM_RESOURCE_BASE_UNSPECIFIED) {
+                if (transaction->type == Rm_service_RESOURCE_ALLOCATE_INIT) {
+                    opInfo.operation = Rm_allocatorOp_PRE_ALLOCATE_INIT;
                 }
-            
-                if (retVal == RM_SERVICE_PROCESSING) {
-                    opInfo.operation = Rm_allocatorOp_ALLOCATE;
-                    retVal = rmAllocatorOperation((Rm_Handle)rmInst, &opInfo);
-                }      
+                else if (transaction->type == Rm_service_RESOURCE_ALLOCATE_USE) {
+                    opInfo.operation = Rm_allocatorOp_PRE_ALLOCATE_USE;
+                }
+                else {
+                    retVal = RM_ERROR_INVALID_SERVICE_TYPE;
+                    goto errorExit;
+                }
+                retVal = rmAllocatorOperation((Rm_Handle)rmInst, &opInfo);
             }
+        
+            if (retVal == RM_SERVICE_PROCESSING) {
+                if (transaction->type == Rm_service_RESOURCE_ALLOCATE_INIT) {
+                    opInfo.operation = Rm_allocatorOp_ALLOCATE_INIT;
+                }
+                else if (transaction->type == Rm_service_RESOURCE_ALLOCATE_USE) {
+                    opInfo.operation = Rm_allocatorOp_ALLOCATE_USE;
+                }
+                else {
+                    retVal = RM_ERROR_INVALID_SERVICE_TYPE;
+                    goto errorExit;
+                }
+                retVal = rmAllocatorOperation((Rm_Handle)rmInst, &opInfo);
+            }      
         }
         else {
             retVal = RM_SERVICE_DENIED_INST_NAME_NOT_VALID;
         }
-        
+errorExit:        
         transaction->state = retVal;                 
     }   
 }
index 59d44c9ff302ef16058c327058ebd110753d5cb9..23ce8afec41bc8b6c96dd755b6f1b40abfce77fb 100644 (file)
@@ -303,18 +303,20 @@ static void allocatorResNodeOwnerDelete(Rm_Handle rmHandle, Rm_ResourceNode *nod
         owner = owner->nextOwner;
     }
 
-    if (prevOwner == NULL) {
-        node->ownerList = owner->nextOwner;
-    }
-    else {
-        prevOwner->nextOwner = owner->nextOwner;
-        RM_SS_OBJ_WB(prevOwner, Rm_Owner);
+    if (owner) {
+        if (prevOwner == NULL) {
+            node->ownerList = owner->nextOwner;
+        }
+        else {
+            prevOwner->nextOwner = owner->nextOwner;
+            RM_SS_OBJ_WB(prevOwner, Rm_Owner);
+        }
+        
+        node->allocationCount--;
+        owner->instNameNode->allocRefCount--;
+        RM_SS_OBJ_WB(owner->instNameNode, Rm_PolicyValidInstNode);
+        Rm_osalFree((void *)owner, sizeof(*owner));
     }
-    
-    node->allocationCount--;
-    owner->instNameNode->allocRefCount--;
-    RM_SS_OBJ_WB(owner->instNameNode, Rm_PolicyValidInstNode);
-    Rm_osalFree((void *)owner, sizeof(*owner));
 }
 
 /* FUNCTION PURPOSE: Copies the owners of a resource node
@@ -421,8 +423,19 @@ static int32_t allocatorPreAllocate(Rm_Handle rmHandle, Rm_Allocator *allocator,
     int                nodePassesPolicy;
     int32_t            retVal;
 
+    if (opInfo->operation == Rm_allocatorOp_PRE_ALLOCATE_INIT) {
+        policyCheckType = Rm_policyCheck_INIT;
+    }
+    else if (opInfo->operation == Rm_allocatorOp_PRE_ALLOCATE_USE) {
+        policyCheckType = Rm_policyCheck_USE;
+    }
+    else {
+        retVal = RM_ERROR_INVALID_SERVICE_TYPE;
+        return (retVal);
+    }
+    
     opInfo->resourceInfo->base = rmPolicyGetResourceBase(opInfo->policy, opInfo->serviceSrcInstNode, 
-                                                         resourcePolicy, opInfo->allocType, 
+                                                         resourcePolicy, policyCheckType, 
                                                          &retVal);
     if (retVal != RM_OK) {
         return (retVal);
@@ -443,12 +456,6 @@ static int32_t allocatorPreAllocate(Rm_Handle rmHandle, Rm_Allocator *allocator,
 
     /* Configure policy checking structure */
     memset((void *)&policyCheckCfg, 0, sizeof(policyCheckCfg));
-    if (RM_policy_GET_PERM(opInfo->allocType, RM_POLICY_PERM_INIT_SHIFT)) {
-        policyCheckType = Rm_policyCheck_INIT;
-    }
-    else if (RM_policy_GET_PERM(opInfo->allocType, RM_POLICY_PERM_USE_SHIFT)) {
-        policyCheckType = Rm_policyCheck_USE;
-    }
     policyCheckCfg.policyDtb = opInfo->policy;
     policyCheckCfg.resourceOffset = resourcePolicy;
     
@@ -554,19 +561,24 @@ static int32_t allocatorAllocate(Rm_Handle rmHandle, Rm_Allocator *allocator, in
     uint32_t            matchingEnd;  
     int32_t             retVal;
 
+    if (opInfo->operation == Rm_allocatorOp_ALLOCATE_INIT) {
+        policyCheckType = Rm_policyCheck_INIT;
+    }
+    else if (opInfo->operation == Rm_allocatorOp_ALLOCATE_USE) {
+        policyCheckType = Rm_policyCheck_USE;
+    }
+    else {
+        retVal = RM_ERROR_INVALID_SERVICE_TYPE;
+        return (retVal);
+    }   
+
     memset((void *)&findNode, 0, sizeof(findNode));
     findNode.base = opInfo->resourceInfo->base;
     findNode.length = opInfo->resourceInfo->length;
     matchingNode = RB_FIND(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, &findNode);
 
     /* Prepare privilege checks */
-    memset((void *)&policyCheckCfg, 0, sizeof(policyCheckCfg));
-    if (RM_policy_GET_PERM(opInfo->allocType, RM_POLICY_PERM_INIT_SHIFT)) {
-        policyCheckType = Rm_policyCheck_INIT;
-    }
-    else if (RM_policy_GET_PERM(opInfo->allocType, RM_POLICY_PERM_USE_SHIFT)) {
-        policyCheckType = Rm_policyCheck_USE;
-    }
+    memset((void *)&policyCheckCfg, 0, sizeof(policyCheckCfg)); 
 
     if (matchingNode) {
         findEnd = findNode.base + findNode.length - 1;
@@ -671,7 +683,9 @@ static int32_t allocatorAllocate(Rm_Handle rmHandle, Rm_Allocator *allocator, in
 
                             allocatorResNodeOwnerClear(rmHandle, leftNode);
                             rmResourceNodeFree(leftNode);
-                            RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, rightNode);                        
+                            if (rightNode) {
+                                RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, rightNode);  
+                            }
                         }
                         else if (combineRight) {
                             /* Combine right and matching nodes.  Reinsert left. */
@@ -679,12 +693,18 @@ static int32_t allocatorAllocate(Rm_Handle rmHandle, Rm_Allocator *allocator, in
 
                             allocatorResNodeOwnerClear(rmHandle, rightNode);
                             rmResourceNodeFree(rightNode);
-                            RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, leftNode);
+                            if (leftNode) {
+                                RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, leftNode);
+                            }
                         }
                         else {
                             /* No combine. */
-                            RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, leftNode);
-                            RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, rightNode);
+                            if (leftNode) {
+                                RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, leftNode);
+                            }
+                            if (rightNode) {
+                                RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, rightNode);
+                            }
                         }
 
                         /* Always reinsert matchingNode */                
@@ -873,7 +893,9 @@ static int32_t allocatorFree(Rm_Handle rmHandle, Rm_Allocator *allocator, Rm_All
 
                             allocatorResNodeOwnerClear(rmHandle, leftNode);
                             rmResourceNodeFree(leftNode);
-                            RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, rightNode);                        
+                            if (rightNode) {
+                                RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, rightNode); 
+                            }
                         }
                         else if (combineRight) {
                             /* Combine right and matching nodes.  Reinsert left. */
@@ -881,12 +903,18 @@ static int32_t allocatorFree(Rm_Handle rmHandle, Rm_Allocator *allocator, Rm_All
 
                             allocatorResNodeOwnerClear(rmHandle, rightNode);
                             rmResourceNodeFree(rightNode);
-                            RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, leftNode);
+                            if (leftNode) {
+                                RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, leftNode);
+                            }
                         }
                         else {
                             /* No combine. */
-                            RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, leftNode);
-                            RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, rightNode);
+                            if (leftNode) {
+                                RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, leftNode);
+                            }
+                            if (rightNode) {
+                                RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, rightNode);
+                            }
                         }
 
                         /* Always reinsert matchingNode */
@@ -1082,7 +1110,7 @@ static int32_t allocatorFindLinuxResource(Rm_Handle rmHandle, const char *resour
     int32_t             propOffset;
     int32_t             nodeOffset = RM_DTB_UTIL_STARTING_NODE_OFFSET;
     int32_t             prevDepth = RM_DTB_UTIL_STARTING_DEPTH;
-    int32_t             depth;
+    int32_t             depth = RM_DTB_UTIL_STARTING_DEPTH;
     int32_t             propertyLen;
     const char         *propertyName;
     const void         *propertyData; 
@@ -1095,7 +1123,7 @@ static int32_t allocatorFindLinuxResource(Rm_Handle rmHandle, const char *resour
     strncpy(resourceInfo.name, resourceName, RM_NAME_MAX_CHARS);
     opInfo.policy = rmInst->u.server.globalPolicy;
     opInfo.serviceSrcInstNode = rmPolicyGetLinuxInstNode(rmHandle);
-    opInfo.operation = Rm_allocatorOp_ALLOCATE;
+    opInfo.operation = Rm_allocatorOp_ALLOCATE_INIT;
     opInfo.resourceInfo = &resourceInfo;    
 
     while(linuxAlias) {
@@ -1285,10 +1313,12 @@ int32_t rmAllocatorOperation(Rm_Handle rmHandle, Rm_AllocatorOpInfo *opInfo)
             rmResourceTreeInv(allocator->allocatorRootEntry);
         }
         
-        if (opInfo->operation == Rm_allocatorOp_PRE_ALLOCATE) {
+        if ((opInfo->operation == Rm_allocatorOp_PRE_ALLOCATE_INIT) ||
+            (opInfo->operation == Rm_allocatorOp_PRE_ALLOCATE_USE)) {
             retVal = allocatorPreAllocate(rmHandle, allocator, resourceOffsetInPolicy, opInfo);
         }               
-        else if (opInfo->operation == Rm_allocatorOp_ALLOCATE) {
+        else if ((opInfo->operation == Rm_allocatorOp_ALLOCATE_INIT) ||
+                 (opInfo->operation == Rm_allocatorOp_ALLOCATE_USE)) {
             retVal = allocatorAllocate(rmHandle, allocator, resourceOffsetInPolicy, opInfo);
         }
         else if (opInfo->operation == Rm_allocatorOp_FREE) {
index 3eba1b495e47a5cabca79aaa2e3e58ec5eb47e44..63f1dc0e1cd136aa9639a7aafd1aa8fe894a6a8f 100644 (file)
@@ -664,7 +664,7 @@ int rmPolicyCheckPrivilege(Rm_PolicyCheckCfg *privilegeCfg, int32_t *result)
  *              Policy DTB.
  */
 uint32_t rmPolicyGetResourceBase(void *policyDtb, Rm_PolicyValidInstNode *validInstNode, 
-                                 int32_t resourceOffset, uint32_t allocType, 
+                                 int32_t resourceOffset, Rm_PolicyCheckType policyCheckType, 
                                  int32_t *result)
 
 {
@@ -699,12 +699,12 @@ uint32_t rmPolicyGetResourceBase(void *policyDtb, Rm_PolicyValidInstNode *validI
             if ((strncmp(permission->instName, validInstNode->name, RM_NAME_MAX_CHARS) == 0) ||
                 (strncmp(permission->instName, Rm_policyAllInstances, RM_NAME_MAX_CHARS) == 0)) {
                 /* Check instance's permissions */
-                if (RM_policy_GET_PERM(allocType, RM_POLICY_PERM_INIT_SHIFT) &&
+                if ((policyCheckType == Rm_policyCheck_INIT) &&
                     RM_policy_GET_PERM(permission->permissionBits, RM_POLICY_PERM_INIT_SHIFT)) {
                     resourceBase = assignment->resourceBase;
                     break;
                 }
-                else if (RM_policy_GET_PERM(allocType, RM_POLICY_PERM_USE_SHIFT) &&
+                else if ((policyCheckType == Rm_policyCheck_USE) &&
                          RM_policy_GET_PERM(permission->permissionBits, RM_POLICY_PERM_USE_SHIFT)) {
                     resourceBase = assignment->resourceBase;
                     break;