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

[S390] cio: Use strict_strtoul() for attributes.

Make parsing of attribute writes handle incorrect input better.

Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>

authored by

Cornelia Huck and committed by
Martin Schwidefsky
2f972202 0ff5ce7f

+35 -18
+5 -2
drivers/s390/cio/ccwgroup.c
··· 318 318 { 319 319 struct ccwgroup_device *gdev; 320 320 struct ccwgroup_driver *gdrv; 321 - unsigned int value; 321 + unsigned long value; 322 322 int ret; 323 323 324 324 gdev = to_ccwgroupdev(dev); ··· 329 329 if (!try_module_get(gdrv->owner)) 330 330 return -EINVAL; 331 331 332 - value = simple_strtoul(buf, NULL, 0); 332 + ret = strict_strtoul(buf, 0, &value); 333 + if (ret) 334 + goto out; 333 335 ret = count; 334 336 if (value == 1) 335 337 ccwgroup_set_online(gdev); ··· 339 337 ccwgroup_set_offline(gdev); 340 338 else 341 339 ret = -EINVAL; 340 + out: 342 341 module_put(gdrv->owner); 343 342 return ret; 344 343 }
+8 -3
drivers/s390/cio/cmf.c
··· 1219 1219 { 1220 1220 struct ccw_device *cdev; 1221 1221 int ret; 1222 + unsigned long val; 1223 + 1224 + ret = strict_strtoul(buf, 16, &val); 1225 + if (ret) 1226 + return ret; 1222 1227 1223 1228 cdev = to_ccwdev(dev); 1224 1229 1225 - switch (buf[0]) { 1226 - case '0': 1230 + switch (val) { 1231 + case 0: 1227 1232 ret = disable_cmf(cdev); 1228 1233 if (ret) 1229 1234 dev_info(&cdev->dev, "disable_cmf failed (%d)\n", ret); 1230 1235 break; 1231 - case '1': 1236 + case 1: 1232 1237 ret = enable_cmf(cdev); 1233 1238 if (ret && ret != -EBUSY) 1234 1239 dev_info(&cdev->dev, "enable_cmf failed (%d)\n", ret);
+7 -3
drivers/s390/cio/css.c
··· 705 705 { 706 706 struct channel_subsystem *css = to_css(dev); 707 707 int ret; 708 + unsigned long val; 708 709 710 + ret = strict_strtoul(buf, 16, &val); 711 + if (ret) 712 + return ret; 709 713 mutex_lock(&css->mutex); 710 - switch (buf[0]) { 711 - case '0': 714 + switch (val) { 715 + case 0: 712 716 ret = css->cm_enabled ? chsc_secm(css, 0) : 0; 713 717 break; 714 - case '1': 718 + case 1: 715 719 ret = css->cm_enabled ? 0 : chsc_secm(css, 1); 716 720 break; 717 721 default:
+11 -6
drivers/s390/cio/device.c
··· 512 512 const char *buf, size_t count) 513 513 { 514 514 struct ccw_device *cdev = to_ccwdev(dev); 515 - int i, force; 516 - char *tmp; 515 + int force, ret; 516 + unsigned long i; 517 517 518 518 if (atomic_cmpxchg(&cdev->private->onoff, 0, 1) != 0) 519 519 return -EAGAIN; ··· 525 525 if (!strncmp(buf, "force\n", count)) { 526 526 force = 1; 527 527 i = 1; 528 + ret = 0; 528 529 } else { 529 530 force = 0; 530 - i = simple_strtoul(buf, &tmp, 16); 531 + ret = strict_strtoul(buf, 16, &i); 531 532 } 532 - 533 + if (ret) 534 + goto out; 533 535 switch (i) { 534 536 case 0: 535 537 online_store_handle_offline(cdev); 538 + ret = count; 536 539 break; 537 540 case 1: 538 541 online_store_handle_online(cdev, force); 542 + ret = count; 539 543 break; 540 544 default: 541 - count = -EINVAL; 545 + ret = -EINVAL; 542 546 } 547 + out: 543 548 if (cdev->drv) 544 549 module_put(cdev->drv->owner); 545 550 atomic_set(&cdev->private->onoff, 0); 546 - return count; 551 + return ret; 547 552 } 548 553 549 554 static ssize_t
+4 -4
drivers/s390/cio/qdio.c
··· 3663 3663 static ssize_t 3664 3664 qdio_performance_stats_store(struct bus_type *bus, const char *buf, size_t count) 3665 3665 { 3666 - char *tmp; 3667 - int i; 3666 + unsigned long i; 3667 + int ret; 3668 3668 3669 - i = simple_strtoul(buf, &tmp, 16); 3670 - if ((i == 0) || (i == 1)) { 3669 + ret = strict_strtoul(buf, 16, &i); 3670 + if (!ret && ((i == 0) || (i == 1))) { 3671 3671 if (i == qdio_performance_stats) 3672 3672 return count; 3673 3673 qdio_performance_stats = i;