OSDN Git Service

Remove atoi implementation and use sscanf instead
authorJes Sorensen <Jes.Sorensen@redhat.com>
Tue, 3 Dec 2013 17:27:04 +0000 (18:27 +0100)
committerLarry Finger <Larry.Finger@lwfinger.net>
Tue, 3 Dec 2013 18:08:27 +0000 (12:08 -0600)
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
include/osdep_service.h
os_dep/osdep_service.c
os_dep/rtw_android.c

index 69b2774..07555c2 100644 (file)
@@ -445,8 +445,6 @@ extern void rtw_sleep_schedulable(int ms);
 extern void    rtw_msleep_os(int ms);
 extern void    rtw_usleep_os(int us);
 
-extern u32     rtw_atoi(u8* s);
-
 #ifdef DBG_DELAY_OS
 #define rtw_mdelay_os(ms) _rtw_mdelay_os((ms), __FUNCTION__, __LINE__)
 #define rtw_udelay_os(ms) _rtw_udelay_os((ms), __FUNCTION__, __LINE__)
index 7395fa5..e7e5c15 100644 (file)
@@ -46,28 +46,6 @@ inline int RTW_STATUS_CODE(int error_code){
        }
 }
 
-u32 rtw_atoi(u8* s)
-{
-
-       int num=0,flag=0;
-       int i;
-       for(i=0;i<=strlen(s);i++)
-       {
-         if(s[i] >= '0' && s[i] <= '9')
-                num = num * 10 + s[i] -'0';
-         else if(s[0] == '-' && i==0)
-                flag =1;
-         else
-                 break;
-        }
-
-       if(flag == 1)
-          num = num * -1;
-
-        return(num);
-
-}
-
 inline u8* _rtw_vmalloc(u32 sz)
 {
        u8      *pbuf;
index 62cbce1..a1288a1 100644 (file)
@@ -305,9 +305,10 @@ static int rtw_android_set_block(struct net_device *net, char *command, int tota
        return 0;
 }
 
-static int get_int_from_command(char *pcmd )
+static int get_int_from_command(char *pcmd)
 {
        int i = 0;
+       int val;
 
        for( i = 0; i < strlen( pcmd ); i++ )
        {
@@ -318,7 +319,9 @@ static int get_int_from_command(char *pcmd )
                        break;
                }
        }
-       return ( rtw_atoi( pcmd + i ) );
+       if (sscanf(pcmd + i, "%d", &val) != 1)
+               val = -EINVAL;
+       return val;
 }
 
 int rtw_android_priv_cmd(struct net_device *net, struct ifreq *ifr, int cmd)
@@ -536,9 +539,14 @@ int rtw_android_priv_cmd(struct net_device *net, struct ifreq *ifr, int cmd)
 
                struct wifi_display_info                *pwfd_info;
                _adapter*       padapter = ( _adapter * ) rtw_netdev_priv(net);
+               int val = get_int_from_command(priv_cmd.buf);
 
-               pwfd_info = &padapter->wfd_info;
-               pwfd_info->rtsp_ctrlport = ( u16 ) get_int_from_command( priv_cmd.buf );
+               if ((val > 0xffff) || (val < 0)) {
+                       ret = -EINVAL;
+               } else {
+                       pwfd_info = &padapter->wfd_info;
+                       pwfd_info->rtsp_ctrlport = ( u16 ) val;
+               }
                break;
        }
        case ANDROID_WIFI_CMD_WFD_SET_MAX_TPUT:
@@ -554,11 +562,16 @@ int rtw_android_priv_cmd(struct net_device *net, struct ifreq *ifr, int cmd)
 
                struct wifi_display_info                *pwfd_info;
                _adapter*       padapter = ( _adapter * ) rtw_netdev_priv(net);
+               int val = get_int_from_command(priv_cmd.buf);
 
-               pwfd_info = &padapter->wfd_info;
-               pwfd_info->wfd_device_type = ( u8 ) get_int_from_command( priv_cmd.buf );
+               if ((val < 0) || (val > 255)) {
+                       ret = -EINVAL;
+               } else {
+                       pwfd_info = &padapter->wfd_info;
+                       pwfd_info->wfd_device_type = (u8)val;
 
-               pwfd_info->wfd_device_type &= WFD_DEVINFO_DUAL;
+                       pwfd_info->wfd_device_type &= WFD_DEVINFO_DUAL;
+               }
                break;
        }
 #endif