Coverity fixes
[keystone-rtos/rm-lld.git] / src / rm.c
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;                 
     }   
 }