@@ -5446,23 +5446,18 @@ static int kbdlight_read(struct seq_file *m)
5446
5446
static int kbdlight_write (char * buf )
5447
5447
{
5448
5448
char * cmd ;
5449
- int level = -1 ;
5449
+ int res , level = - EINVAL ;
5450
5450
5451
5451
if (!tp_features .kbdlight )
5452
5452
return - ENODEV ;
5453
5453
5454
5454
while ((cmd = strsep (& buf , "," ))) {
5455
- if (strlencmp (cmd , "0" ) == 0 )
5456
- level = 0 ;
5457
- else if (strlencmp (cmd , "1" ) == 0 )
5458
- level = 1 ;
5459
- else if (strlencmp (cmd , "2" ) == 0 )
5460
- level = 2 ;
5461
- else
5462
- return - EINVAL ;
5455
+ res = kstrtoint (cmd , 10 , & level );
5456
+ if (res < 0 )
5457
+ return res ;
5463
5458
}
5464
5459
5465
- if (level == -1 )
5460
+ if (level >= 3 || level < 0 )
5466
5461
return - EINVAL ;
5467
5462
5468
5463
return kbdlight_set_level_and_update (level );
@@ -9776,19 +9771,18 @@ static int lcdshadow_read(struct seq_file *m)
9776
9771
static int lcdshadow_write (char * buf )
9777
9772
{
9778
9773
char * cmd ;
9779
- int state = -1 ;
9774
+ int res , state = - EINVAL ;
9780
9775
9781
9776
if (lcdshadow_state < 0 )
9782
9777
return - ENODEV ;
9783
9778
9784
9779
while ((cmd = strsep (& buf , "," ))) {
9785
- if (strlencmp (cmd , "0" ) == 0 )
9786
- state = 0 ;
9787
- else if (strlencmp (cmd , "1" ) == 0 )
9788
- state = 1 ;
9780
+ res = kstrtoint (cmd , 10 , & state );
9781
+ if (res < 0 )
9782
+ return res ;
9789
9783
}
9790
9784
9791
- if (state == -1 )
9785
+ if (state >= 2 || state < 0 )
9792
9786
return - EINVAL ;
9793
9787
9794
9788
return lcdshadow_set (state );
0 commit comments