3
3
* rtmouse.c
4
4
* Raspberry Pi Mouse device driver
5
5
*
6
- * Version: 3.1.0
6
+ * Version: 3.1.1
7
7
*
8
8
* Copyright (C) 2015-2021 RT Corporation <shop@rt-net.jp>
9
9
*
55
55
56
56
MODULE_AUTHOR ("RT Corporation" );
57
57
MODULE_LICENSE ("GPL" );
58
- MODULE_VERSION ("3.0.0 " );
58
+ MODULE_VERSION ("3.1.1 " );
59
59
MODULE_DESCRIPTION ("Raspberry Pi Mouse device driver" );
60
60
61
61
/* --- Device Numbers --- */
@@ -848,59 +848,6 @@ static int i2c_dev_release(struct inode *inode, struct file *filep)
848
848
return 0 ;
849
849
}
850
850
851
- /* Parse Frequency */
852
- static int parseFreq (const char __user * buf , size_t count , int * ret )
853
- {
854
- char cval ;
855
- int error = 0 , i = 0 , tmp , bufcnt = 0 , freq ;
856
- size_t readcount = count ;
857
- int sgn = 1 ;
858
-
859
- char * newbuf = kmalloc (sizeof (char ) * count , GFP_KERNEL );
860
-
861
- while (readcount > 0 ) {
862
- if (copy_from_user (& cval , buf + i , sizeof (char ))) {
863
- kfree (newbuf );
864
- return - EFAULT ;
865
- }
866
-
867
- if (cval == '-' ) {
868
- if (bufcnt == 0 ) {
869
- sgn = -1 ;
870
- }
871
- } else if (cval < '0' || cval > '9' ) {
872
- newbuf [bufcnt ] = 'e' ;
873
- error = 1 ;
874
- } else {
875
- newbuf [bufcnt ] = cval ;
876
- }
877
-
878
- i ++ ;
879
- bufcnt ++ ;
880
- readcount -- ;
881
-
882
- if (cval == '\n' ) {
883
- break ;
884
- }
885
- }
886
-
887
- freq = 0 ;
888
- for (i = 0 , tmp = 1 ; i < bufcnt ; i ++ ) {
889
- char c = newbuf [bufcnt - i - 1 ];
890
-
891
- if (c >= '0' && c <= '9' ) {
892
- freq += (newbuf [bufcnt - i - 1 ] - '0' ) * tmp ;
893
- tmp *= 10 ;
894
- }
895
- }
896
-
897
- * ret = sgn * freq ;
898
-
899
- kfree (newbuf );
900
-
901
- return bufcnt ;
902
- }
903
-
904
851
/* Parse motor command */
905
852
static int parseMotorCmd (const char __user * buf , size_t count , int * ret )
906
853
{
@@ -931,58 +878,6 @@ static int parseMotorCmd(const char __user *buf, size_t count, int *ret)
931
878
return count ;
932
879
}
933
880
934
- /* Parse I2C pulse counter value */
935
- static int parse_count (const char __user * buf , size_t count , int * ret )
936
- {
937
- char cval ;
938
- int error = 0 , i = 0 , tmp , bufcnt = 0 , freq ;
939
- size_t readcount = count ;
940
- int sgn = 1 ;
941
-
942
- char * newbuf = kmalloc (sizeof (char ) * count , GFP_KERNEL );
943
-
944
- while (readcount > 0 ) {
945
- if (copy_from_user (& cval , buf + i , sizeof (char ))) {
946
- kfree (newbuf );
947
- return - EFAULT ;
948
- }
949
-
950
- if (cval == '-' ) {
951
- if (bufcnt == 0 ) {
952
- sgn = -1 ;
953
- }
954
- } else if (cval < '0' || cval > '9' ) {
955
- newbuf [bufcnt ] = 'e' ;
956
- error = 1 ;
957
- } else {
958
- newbuf [bufcnt ] = cval ;
959
- }
960
-
961
- i ++ ;
962
- bufcnt ++ ;
963
- readcount -- ;
964
-
965
- if (cval == '\n' ) {
966
- break ;
967
- }
968
- }
969
-
970
- freq = 0 ;
971
- for (i = 0 , tmp = 1 ; i < bufcnt ; i ++ ) {
972
- char c = newbuf [bufcnt - i - 1 ];
973
-
974
- if (c >= '0' && c <= '9' ) {
975
- freq += (newbuf [bufcnt - i - 1 ] - '0' ) * tmp ;
976
- tmp *= 10 ;
977
- }
978
- }
979
-
980
- * ret = sgn * freq ;
981
-
982
- kfree (newbuf );
983
-
984
- return bufcnt ;
985
- }
986
881
987
882
/*
988
883
* led_write - Trun ON/OFF LEDs
@@ -1019,10 +914,15 @@ static ssize_t led_write(struct file *filep, const char __user *buf,
1019
914
static ssize_t buzzer_write (struct file * filep , const char __user * buf ,
1020
915
size_t count , loff_t * f_pos )
1021
916
{
1022
- int bufcnt ;
917
+ int ret ;
1023
918
int freq , dat ;
1024
919
1025
- bufcnt = parseFreq (buf , count , & freq );
920
+ ret = kstrtoint_from_user (buf , count , 10 , & freq );
921
+ if (ret ) {
922
+ printk (KERN_ERR "%s: error parsing string to int in %s()\n" ,
923
+ DRIVER_NAME , __func__ );
924
+ return ret ;
925
+ }
1026
926
1027
927
if (freq != 0 ) {
1028
928
if (freq < 1 ) {
@@ -1043,7 +943,7 @@ static ssize_t buzzer_write(struct file *filep, const char __user *buf,
1043
943
RPI_GPF_OUTPUT ); // io is pwm out
1044
944
}
1045
945
1046
- return bufcnt ;
946
+ return count ;
1047
947
}
1048
948
1049
949
/*
@@ -1053,12 +953,17 @@ static ssize_t buzzer_write(struct file *filep, const char __user *buf,
1053
953
static ssize_t rawmotor_l_write (struct file * filep , const char __user * buf ,
1054
954
size_t count , loff_t * f_pos )
1055
955
{
1056
- int freq , bufcnt ;
1057
- bufcnt = parseFreq (buf , count , & freq );
956
+ int freq , ret ;
1058
957
958
+ ret = kstrtoint_from_user (buf , count , 10 , & freq );
959
+ if (ret ) {
960
+ printk (KERN_ERR "%s: error parsing string to int in %s()\n" ,
961
+ DRIVER_NAME , __func__ );
962
+ return ret ;
963
+ }
1059
964
set_motor_l_freq (freq );
1060
965
1061
- return bufcnt ;
966
+ return count ;
1062
967
}
1063
968
1064
969
/*
@@ -1068,12 +973,18 @@ static ssize_t rawmotor_l_write(struct file *filep, const char __user *buf,
1068
973
static ssize_t rawmotor_r_write (struct file * filep , const char __user * buf ,
1069
974
size_t count , loff_t * f_pos )
1070
975
{
1071
- int freq , bufcnt ;
1072
- bufcnt = parseFreq (buf , count , & freq );
976
+ int freq , ret ;
977
+
978
+ ret = kstrtoint_from_user (buf , count , 10 , & freq );
979
+ if (ret ) {
980
+ printk (KERN_ERR "%s: error parsing string to int in %s()\n" ,
981
+ DRIVER_NAME , __func__ );
982
+ return ret ;
983
+ }
1073
984
1074
985
set_motor_r_freq (freq );
1075
986
1076
- return bufcnt ;
987
+ return count ;
1077
988
}
1078
989
1079
990
/*
@@ -1292,13 +1203,15 @@ static ssize_t rtcnt_write(struct file *filep, const char __user *buf,
1292
1203
{
1293
1204
struct rtcnt_device_info * dev_info = filep -> private_data ;
1294
1205
1295
- int bufcnt = 0 ;
1296
1206
int rtcnt_count = 0 ;
1207
+ int ret ;
1297
1208
1298
- if (count < 0 )
1299
- return 0 ;
1300
-
1301
- bufcnt = parse_count (buf , count , & rtcnt_count );
1209
+ ret = kstrtoint_from_user (buf , count , 10 , & rtcnt_count );
1210
+ if (ret ) {
1211
+ printk (KERN_ERR "%s: error parsing string to int in %s()\n" ,
1212
+ DRIVER_NAME , __func__ );
1213
+ return ret ;
1214
+ }
1302
1215
1303
1216
i2c_counter_set (dev_info , rtcnt_count );
1304
1217
@@ -1308,7 +1221,7 @@ static ssize_t rtcnt_write(struct file *filep, const char __user *buf,
1308
1221
1309
1222
printk (KERN_INFO "%s: set pulse counter value %d\n" , DRIVER_NAME ,
1310
1223
rtcnt_count );
1311
- return bufcnt ;
1224
+ return count ;
1312
1225
}
1313
1226
1314
1227
/* --- Device File Operations --- */
0 commit comments