浏览代码

tcm_loop: fixup tpgt string to integer conversion

Currently, for example, mkdir "tpgt_xyz" doesn't return error.
mkdir /sys/kernel/config/target/loopback/naa.60014055f195952b/tpgt_xyz

Replace obsoleted simple_strtoul with kstrtoul and check the conversion.

Signed-off-by: Ming Lin <mlin@kernel.org>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Ming Lin 10 年之前
父节点
当前提交
2e1cd90d71
共有 1 个文件被更改,包括 6 次插入8 次删除
  1. 6 8
      drivers/target/loopback/tcm_loop.c

+ 6 - 8
drivers/target/loopback/tcm_loop.c

@@ -1216,21 +1216,19 @@ static struct se_portal_group *tcm_loop_make_naa_tpg(
 	struct tcm_loop_hba *tl_hba = container_of(wwn,
 	struct tcm_loop_hba *tl_hba = container_of(wwn,
 			struct tcm_loop_hba, tl_hba_wwn);
 			struct tcm_loop_hba, tl_hba_wwn);
 	struct tcm_loop_tpg *tl_tpg;
 	struct tcm_loop_tpg *tl_tpg;
-	char *tpgt_str, *end_ptr;
 	int ret;
 	int ret;
-	unsigned short int tpgt;
+	unsigned long tpgt;
 
 
-	tpgt_str = strstr(name, "tpgt_");
-	if (!tpgt_str) {
+	if (strstr(name, "tpgt_") != name) {
 		pr_err("Unable to locate \"tpgt_#\" directory"
 		pr_err("Unable to locate \"tpgt_#\" directory"
 				" group\n");
 				" group\n");
 		return ERR_PTR(-EINVAL);
 		return ERR_PTR(-EINVAL);
 	}
 	}
-	tpgt_str += 5; /* Skip ahead of "tpgt_" */
-	tpgt = (unsigned short int) simple_strtoul(tpgt_str, &end_ptr, 0);
+	if (kstrtoul(name+5, 10, &tpgt))
+		return ERR_PTR(-EINVAL);
 
 
 	if (tpgt >= TL_TPGS_PER_HBA) {
 	if (tpgt >= TL_TPGS_PER_HBA) {
-		pr_err("Passed tpgt: %hu exceeds TL_TPGS_PER_HBA:"
+		pr_err("Passed tpgt: %lu exceeds TL_TPGS_PER_HBA:"
 				" %u\n", tpgt, TL_TPGS_PER_HBA);
 				" %u\n", tpgt, TL_TPGS_PER_HBA);
 		return ERR_PTR(-EINVAL);
 		return ERR_PTR(-EINVAL);
 	}
 	}
@@ -1247,7 +1245,7 @@ static struct se_portal_group *tcm_loop_make_naa_tpg(
 		return ERR_PTR(-ENOMEM);
 		return ERR_PTR(-ENOMEM);
 
 
 	pr_debug("TCM_Loop_ConfigFS: Allocated Emulated %s"
 	pr_debug("TCM_Loop_ConfigFS: Allocated Emulated %s"
-		" Target Port %s,t,0x%04x\n", tcm_loop_dump_proto_id(tl_hba),
+		" Target Port %s,t,0x%04lx\n", tcm_loop_dump_proto_id(tl_hba),
 		config_item_name(&wwn->wwn_group.cg_item), tpgt);
 		config_item_name(&wwn->wwn_group.cg_item), tpgt);
 
 
 	return &tl_tpg->tl_se_tpg;
 	return &tl_tpg->tl_se_tpg;