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

iscsi-target: kstrtou* configfs attribute parameter cleanups

This patch includes the conversion of iscsi-target configfs
attributes for NetworkPortal, NodeACL, TPG, IQN and Discovery
groups to use kstrtou*() instead of simple_strtou*().

It also cleans up new-line usage during iscsi_tpg_param_store_##name
to use isspace().

Signed-off-by: Joern Engel <joern@logfs.org>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>

authored by

Jörn Engel and committed by
Nicholas Bellinger
ad7babd2 37b32c6f

+32 -21
+32 -21
drivers/target/iscsi/iscsi_target_configfs.c
··· 20 20 ****************************************************************************/ 21 21 22 22 #include <linux/configfs.h> 23 + #include <linux/ctype.h> 23 24 #include <linux/export.h> 24 25 #include <linux/inet.h> 25 26 #include <target/target_core_base.h> ··· 79 78 struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np, 80 79 struct iscsi_tpg_np, se_tpg_np); 81 80 struct iscsi_tpg_np *tpg_np_sctp = NULL; 82 - char *endptr; 83 81 u32 op; 84 82 int ret; 85 83 86 - op = simple_strtoul(page, &endptr, 0); 84 + ret = kstrtou32(page, 0, &op); 85 + if (ret) 86 + return ret; 87 87 if ((op != 1) && (op != 0)) { 88 88 pr_err("Illegal value for tpg_enable: %u\n", op); 89 89 return -EINVAL; ··· 383 381 { \ 384 382 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \ 385 383 se_node_acl); \ 386 - char *endptr; \ 387 384 u32 val; \ 388 385 int ret; \ 389 386 \ 390 - val = simple_strtoul(page, &endptr, 0); \ 387 + ret = kstrtou32(page, 0, &val); \ 388 + if (ret) \ 389 + return ret; \ 391 390 ret = iscsit_na_##name(nacl, val); \ 392 391 if (ret < 0) \ 393 392 return ret; \ ··· 791 788 struct iscsi_portal_group *tpg = container_of(se_tpg, 792 789 struct iscsi_portal_group, tpg_se_tpg); 793 790 struct config_item *acl_ci, *tpg_ci, *wwn_ci; 794 - char *endptr; 795 791 u32 cmdsn_depth = 0; 796 792 int ret; 797 793 798 - cmdsn_depth = simple_strtoul(page, &endptr, 0); 794 + ret = kstrtou32(page, 0, &cmdsn_depth); 795 + if (ret) 796 + return ret; 799 797 if (cmdsn_depth > TA_DEFAULT_CMDSN_DEPTH_MAX) { 800 798 pr_err("Passed cmdsn_depth: %u exceeds" 801 799 " TA_DEFAULT_CMDSN_DEPTH_MAX: %u\n", cmdsn_depth, ··· 980 976 { \ 981 977 struct iscsi_portal_group *tpg = container_of(se_tpg, \ 982 978 struct iscsi_portal_group, tpg_se_tpg); \ 983 - char *endptr; \ 984 979 u32 val; \ 985 980 int ret; \ 986 981 \ 987 982 if (iscsit_get_tpg(tpg) < 0) \ 988 983 return -EINVAL; \ 989 984 \ 990 - val = simple_strtoul(page, &endptr, 0); \ 985 + ret = kstrtou32(page, 0, &val); \ 986 + if (ret) \ 987 + goto out; \ 991 988 ret = iscsit_ta_##name(tpg, val); \ 992 989 if (ret < 0) \ 993 990 goto out; \ ··· 1216 1211 struct iscsi_portal_group *tpg = container_of(se_tpg, \ 1217 1212 struct iscsi_portal_group, tpg_se_tpg); \ 1218 1213 char *buf; \ 1219 - int ret; \ 1214 + int ret, len; \ 1220 1215 \ 1221 1216 buf = kzalloc(PAGE_SIZE, GFP_KERNEL); \ 1222 1217 if (!buf) \ 1223 1218 return -ENOMEM; \ 1224 - snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page); \ 1225 - buf[strlen(buf)-1] = '\0'; /* Kill newline */ \ 1219 + len = snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page); \ 1220 + if (isspace(buf[len-1])) \ 1221 + buf[len-1] = '\0'; /* Kill newline */ \ 1226 1222 \ 1227 1223 if (iscsit_get_tpg(tpg) < 0) { \ 1228 1224 kfree(buf); \ ··· 1360 1354 { 1361 1355 struct iscsi_portal_group *tpg = container_of(se_tpg, 1362 1356 struct iscsi_portal_group, tpg_se_tpg); 1363 - char *endptr; 1364 1357 u32 op; 1365 - int ret = 0; 1358 + int ret; 1366 1359 1367 - op = simple_strtoul(page, &endptr, 0); 1360 + ret = kstrtou32(page, 0, &op); 1361 + if (ret) 1362 + return ret; 1368 1363 if ((op != 1) && (op != 0)) { 1369 1364 pr_err("Illegal value for tpg_enable: %u\n", op); 1370 1365 return -EINVAL; ··· 1413 1406 { 1414 1407 struct iscsi_portal_group *tpg; 1415 1408 struct iscsi_tiqn *tiqn; 1416 - char *tpgt_str, *end_ptr; 1417 - int ret = 0; 1418 - unsigned short int tpgt; 1409 + char *tpgt_str; 1410 + int ret; 1411 + u16 tpgt; 1419 1412 1420 1413 tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn); 1421 1414 /* 1422 1415 * Only tpgt_# directory groups can be created below 1423 1416 * target/iscsi/iqn.superturodiskarry/ 1424 - */ 1417 + */ 1425 1418 tpgt_str = strstr(name, "tpgt_"); 1426 1419 if (!tpgt_str) { 1427 1420 pr_err("Unable to locate \"tpgt_#\" directory" ··· 1429 1422 return NULL; 1430 1423 } 1431 1424 tpgt_str += 5; /* Skip ahead of "tpgt_" */ 1432 - tpgt = (unsigned short int) simple_strtoul(tpgt_str, &end_ptr, 0); 1425 + ret = kstrtou16(tpgt_str, 0, &tpgt); 1426 + if (ret) 1427 + return NULL; 1433 1428 1434 1429 tpg = iscsit_alloc_portal_group(tiqn, tpgt); 1435 1430 if (!tpg) ··· 1639 1630 { 1640 1631 struct iscsi_param *param; 1641 1632 struct iscsi_portal_group *discovery_tpg = iscsit_global->discovery_tpg; 1642 - char *endptr; 1643 1633 u32 op; 1634 + int err; 1644 1635 1645 - op = simple_strtoul(page, &endptr, 0); 1636 + err = kstrtou32(page, 0, &op); 1637 + if (err) 1638 + return -EINVAL; 1646 1639 if ((op != 1) && (op != 0)) { 1647 1640 pr_err("Illegal value for enforce_discovery_auth:" 1648 1641 " %u\n", op);