wlan: SETROAMSCANCHANNELS should take min of Number of Channels

the command format for SETROAMSCANCHANNELS is
SETROAMSCANCHANNELS N <Ch1> <Ch2> ... <Ch M>
In case of N not equal to M, Number of channels should be
Min of (N, M)
Example, SETROAMSCANCHANNELS 4 1 2 3 4 5   -> N = 4
         SETROAMSCANCHANNELS 4 1 2 3       -> N = 3

Change-Id: Ib3756200aa5f967613eac6f15b93c2739ba84366
CRs-Fixed: 466163
diff --git a/CORE/HDD/src/wlan_hdd_main.c b/CORE/HDD/src/wlan_hdd_main.c
index 463e8e7..a257779 100644
--- a/CORE/HDD/src/wlan_hdd_main.c
+++ b/CORE/HDD/src/wlan_hdd_main.c
@@ -975,6 +975,11 @@
 
   This function parses the channel list passed in the format
   SETROAMSCANCHANNELS<space><Number of channels><space>Channel 1<space>Channel 2<space>Channel N
+  if the Number of channels (N) does not match with the actual number of channels passed
+  then take the minimum of N and count of (Ch1, Ch2, ...Ch M)
+  For example, if SETROAMSCANCHANNELS 3 36 40 44 48, only 36, 40 and 44 shall be taken.
+  If SETROAMSCANCHANNELS 5 36 40 44 48, ignore 5 and take 36, 40, 44 and 48.
+  This function does not take care of removing duplicate channels from the list
 
   \param  - pValue Pointer to input channel list
   \param  - ChannelList Pointer to local output array to record channel list
@@ -1016,7 +1021,7 @@
     /*getting the first argument ie the number of channels*/
     sscanf(inPtr, "%s ", buf);
     v = kstrtos32(buf, 10, &tempInt);
-    if ( v < 0) return -EINVAL;
+    if ((v < 0) || (tempInt <= 0)) return -EINVAL;
 
     *pNumChannels = tempInt;
 
@@ -1030,7 +1035,15 @@
         /*no channel list after the number of channels argument*/
         if (NULL == inPtr)
         {
-            return -EINVAL;
+            if (0 != j)
+            {
+                *pNumChannels = j;
+                return VOS_STATUS_SUCCESS;
+            }
+            else
+            {
+                return -EINVAL;
+            }
         }
 
         /*removing empty space*/
@@ -1039,12 +1052,20 @@
         /*no channel list after the number of channels argument and spaces*/
         if ( '\0' == *inPtr )
         {
-            return -EINVAL;
+            if (0 != j)
+            {
+                *pNumChannels = j;
+                return VOS_STATUS_SUCCESS;
+            }
+            else
+            {
+                return -EINVAL;
+            }
         }
 
         sscanf(inPtr, "%s ", buf);
         v = kstrtos32(buf, 10, &tempInt);
-        if ( v < 0) return -EINVAL;
+        if ((v < 0) || (tempInt <= 0)) return -EINVAL;
         pChannelList[j] = tempInt;
 
         VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
@@ -1052,8 +1073,6 @@
                    pChannelList[j] );
     }
 
-    /* if the actual number of channels passed are more than
-       pNumChannels then ignore the rest; take only pNumChannels */
     return VOS_STATUS_SUCCESS;
 }