Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: convert drivers to use strict_strtoul()

strict_strtoul() allows newline character at the end of the the input
string and therefore is more user-friendly.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Joe Rouvier and committed by
Dmitry Torokhov
160f1fef 82a196f4

+53 -51
+5 -15
drivers/input/keyboard/atkbd.c
··· 1207 1207 { 1208 1208 struct input_dev *old_dev, *new_dev; 1209 1209 unsigned long value; 1210 - char *rest; 1211 1210 int err; 1212 1211 unsigned char old_extra, old_set; 1213 1212 1214 1213 if (!atkbd->write) 1215 1214 return -EIO; 1216 1215 1217 - value = simple_strtoul(buf, &rest, 10); 1218 - if (*rest || value > 1) 1216 + if (strict_strtoul(buf, 10, &value) || value > 1) 1219 1217 return -EINVAL; 1220 1218 1221 1219 if (atkbd->extra != value) { ··· 1262 1264 { 1263 1265 struct input_dev *old_dev, *new_dev; 1264 1266 unsigned long value; 1265 - char *rest; 1266 1267 int err; 1267 1268 unsigned char old_scroll; 1268 1269 1269 - value = simple_strtoul(buf, &rest, 10); 1270 - if (*rest || value > 1) 1270 + if (strict_strtoul(buf, 10, &value) || value > 1) 1271 1271 return -EINVAL; 1272 1272 1273 1273 if (atkbd->scroll != value) { ··· 1306 1310 { 1307 1311 struct input_dev *old_dev, *new_dev; 1308 1312 unsigned long value; 1309 - char *rest; 1310 1313 int err; 1311 1314 unsigned char old_set, old_extra; 1312 1315 1313 1316 if (!atkbd->write) 1314 1317 return -EIO; 1315 1318 1316 - value = simple_strtoul(buf, &rest, 10); 1317 - if (*rest || (value != 2 && value != 3)) 1319 + if (strict_strtoul(buf, 10, &value) || (value != 2 && value != 3)) 1318 1320 return -EINVAL; 1319 1321 1320 1322 if (atkbd->set != value) { ··· 1355 1361 { 1356 1362 struct input_dev *old_dev, *new_dev; 1357 1363 unsigned long value; 1358 - char *rest; 1359 1364 int err; 1360 1365 unsigned char old_softrepeat, old_softraw; 1361 1366 1362 1367 if (!atkbd->write) 1363 1368 return -EIO; 1364 1369 1365 - value = simple_strtoul(buf, &rest, 10); 1366 - if (*rest || value > 1) 1370 + if (strict_strtoul(buf, 10, &value) || value > 1) 1367 1371 return -EINVAL; 1368 1372 1369 1373 if (atkbd->softrepeat != value) { ··· 1405 1413 { 1406 1414 struct input_dev *old_dev, *new_dev; 1407 1415 unsigned long value; 1408 - char *rest; 1409 1416 int err; 1410 1417 unsigned char old_softraw; 1411 1418 1412 - value = simple_strtoul(buf, &rest, 10); 1413 - if (*rest || value > 1) 1419 + if (strict_strtoul(buf, 10, &value) || value > 1) 1414 1420 return -EINVAL; 1415 1421 1416 1422 if (atkbd->softraw != value) {
+1 -3
drivers/input/mouse/logips2pp.c
··· 157 157 static ssize_t ps2pp_attr_set_smartscroll(struct psmouse *psmouse, void *data, const char *buf, size_t count) 158 158 { 159 159 unsigned long value; 160 - char *rest; 161 160 162 - value = simple_strtoul(buf, &rest, 10); 163 - if (*rest || value > 1) 161 + if (strict_strtoul(buf, 10, &value) || value > 1) 164 162 return -EINVAL; 165 163 166 164 ps2pp_set_smartscroll(psmouse, value);
+3 -9
drivers/input/mouse/psmouse-base.c
··· 1433 1433 { 1434 1434 unsigned int *field = (unsigned int *)((char *)psmouse + (size_t)offset); 1435 1435 unsigned long value; 1436 - char *rest; 1437 1436 1438 - value = simple_strtoul(buf, &rest, 10); 1439 - if (*rest) 1437 + if (strict_strtoul(buf, 10, &value)) 1440 1438 return -EINVAL; 1441 1439 1442 1440 if ((unsigned int)value != value) ··· 1547 1549 static ssize_t psmouse_attr_set_rate(struct psmouse *psmouse, void *data, const char *buf, size_t count) 1548 1550 { 1549 1551 unsigned long value; 1550 - char *rest; 1551 1552 1552 - value = simple_strtoul(buf, &rest, 10); 1553 - if (*rest) 1553 + if (strict_strtoul(buf, 10, &value)) 1554 1554 return -EINVAL; 1555 1555 1556 1556 psmouse->set_rate(psmouse, value); ··· 1558 1562 static ssize_t psmouse_attr_set_resolution(struct psmouse *psmouse, void *data, const char *buf, size_t count) 1559 1563 { 1560 1564 unsigned long value; 1561 - char *rest; 1562 1565 1563 - value = simple_strtoul(buf, &rest, 10); 1564 - if (*rest) 1566 + if (strict_strtoul(buf, 10, &value)) 1565 1567 return -EINVAL; 1566 1568 1567 1569 psmouse->set_resolution(psmouse, value);
+2 -6
drivers/input/mouse/trackpoint.c
··· 89 89 struct trackpoint_attr_data *attr = data; 90 90 unsigned char *field = (unsigned char *)((char *)tp + attr->field_offset); 91 91 unsigned long value; 92 - char *rest; 93 92 94 - value = simple_strtoul(buf, &rest, 10); 95 - if (*rest || value > 255) 93 + if (strict_strtoul(buf, 10, &value) || value > 255) 96 94 return -EINVAL; 97 95 98 96 *field = value; ··· 115 117 struct trackpoint_attr_data *attr = data; 116 118 unsigned char *field = (unsigned char *)((char *)tp + attr->field_offset); 117 119 unsigned long value; 118 - char *rest; 119 120 120 - value = simple_strtoul(buf, &rest, 10); 121 - if (*rest || value > 1) 121 + if (strict_strtoul(buf, 10, &value) || value > 1) 122 122 return -EINVAL; 123 123 124 124 if (attr->inverted)
+38 -15
drivers/input/tablet/aiptek.c
··· 1202 1202 store_tabletXtilt(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 1203 1203 { 1204 1204 struct aiptek *aiptek = dev_get_drvdata(dev); 1205 - int x; 1205 + long x; 1206 1206 1207 - if (strcmp(buf, "disable") == 0) { 1207 + if (strict_strtol(buf, 10, &x)) { 1208 + size_t len = buf[count - 1] == '\n' ? count - 1 : count; 1209 + 1210 + if (strncmp(buf, "disable", len)) 1211 + return -EINVAL; 1212 + 1208 1213 aiptek->newSetting.xTilt = AIPTEK_TILT_DISABLE; 1209 1214 } else { 1210 - x = (int)simple_strtol(buf, NULL, 10); 1211 - if (x >= AIPTEK_TILT_MIN && x <= AIPTEK_TILT_MAX) { 1212 - aiptek->newSetting.xTilt = x; 1213 - } 1215 + if (x < AIPTEK_TILT_MIN || x > AIPTEK_TILT_MAX) 1216 + return -EINVAL; 1217 + 1218 + aiptek->newSetting.xTilt = x; 1214 1219 } 1220 + 1215 1221 return count; 1216 1222 } 1217 1223 ··· 1244 1238 store_tabletYtilt(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 1245 1239 { 1246 1240 struct aiptek *aiptek = dev_get_drvdata(dev); 1247 - int y; 1241 + long y; 1248 1242 1249 - if (strcmp(buf, "disable") == 0) { 1243 + if (strict_strtol(buf, 10, &y)) { 1244 + size_t len = buf[count - 1] == '\n' ? count - 1 : count; 1245 + 1246 + if (strncmp(buf, "disable", len)) 1247 + return -EINVAL; 1248 + 1250 1249 aiptek->newSetting.yTilt = AIPTEK_TILT_DISABLE; 1251 1250 } else { 1252 - y = (int)simple_strtol(buf, NULL, 10); 1253 - if (y >= AIPTEK_TILT_MIN && y <= AIPTEK_TILT_MAX) { 1254 - aiptek->newSetting.yTilt = y; 1255 - } 1251 + if (y < AIPTEK_TILT_MIN || y > AIPTEK_TILT_MAX) 1252 + return -EINVAL; 1253 + 1254 + aiptek->newSetting.yTilt = y; 1256 1255 } 1256 + 1257 1257 return count; 1258 1258 } 1259 1259 ··· 1281 1269 store_tabletJitterDelay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 1282 1270 { 1283 1271 struct aiptek *aiptek = dev_get_drvdata(dev); 1272 + long j; 1284 1273 1285 - aiptek->newSetting.jitterDelay = (int)simple_strtol(buf, NULL, 10); 1274 + if (strict_strtol(buf, 10, &j)) 1275 + return -EINVAL; 1276 + 1277 + aiptek->newSetting.jitterDelay = (int)j; 1286 1278 return count; 1287 1279 } 1288 1280 ··· 1310 1294 store_tabletProgrammableDelay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 1311 1295 { 1312 1296 struct aiptek *aiptek = dev_get_drvdata(dev); 1297 + long d; 1313 1298 1314 - aiptek->newSetting.programmableDelay = (int)simple_strtol(buf, NULL, 10); 1299 + if (strict_strtol(buf, 10, &d)) 1300 + return -EINVAL; 1301 + 1302 + aiptek->newSetting.programmableDelay = (int)d; 1315 1303 return count; 1316 1304 } 1317 1305 ··· 1561 1541 store_tabletWheel(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 1562 1542 { 1563 1543 struct aiptek *aiptek = dev_get_drvdata(dev); 1544 + long w; 1564 1545 1565 - aiptek->newSetting.wheel = (int)simple_strtol(buf, NULL, 10); 1546 + if (strict_strtol(buf, 10, &w)) return -EINVAL; 1547 + 1548 + aiptek->newSetting.wheel = (int)w; 1566 1549 return count; 1567 1550 } 1568 1551
+4 -3
drivers/input/touchscreen/ads7846.c
··· 461 461 const char *buf, size_t count) 462 462 { 463 463 struct ads7846 *ts = dev_get_drvdata(dev); 464 - char *endp; 465 - int i; 464 + long i; 466 465 467 - i = simple_strtoul(buf, &endp, 10); 466 + if (strict_strtoul(buf, 10, &i)) 467 + return -EINVAL; 468 + 468 469 spin_lock_irq(&ts->lock); 469 470 470 471 if (i)