Skip to contentSkip to conversation

xen-scsiback: clean up a type issue in scsiback_make_tpg()

PATCH In review Dan Carpenter 2 participants 3 messages Sep 8, 2014

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen-scsiback: clean up a type issue in scsiback_make_tpg()

This code was confusing because we had an unsigned long and then we compared it to UINT_MAX and then we stored it in a u16. How many bytes is this supposed to have: 2, 4 or 16???

I've made it a u16 throughout.

drivers/xen/xen-scsiback.c +4 -3
index 7b565632..ad11258 100644
@@ -1885,13 +1885,14 @@ scsiback_make_tpg(struct se_wwn *wwn,
 			struct scsiback_tport, tport_wwn);
 
 	struct scsiback_tpg *tpg;
-	unsigned long tpgt;
+	u16 tpgt;
 	int ret;
 
 	if (strstr(name, "tpgt_") != name)
 		return ERR_PTR(-EINVAL);
-	if (kstrtoul(name + 5, 10, &tpgt) || tpgt > UINT_MAX)
-		return ERR_PTR(-EINVAL);
+	ret = kstrtou16(name + 5, 10, &tpgt);
+	if (ret)
+		return ERR_PTR(ret);
 
 	tpg = kzalloc(sizeof(struct scsiback_tpg), GFP_KERNEL);
 	if (!tpg)
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Dan Carpenter

This code was confusing because we had an unsigned long and then we compared it to UINT_MAX and then we stored it in a u16. How many bytes is this supposed to have: 2, 4 or 16???

I've made it a u16 throughout.

Thanks,

Juergen

Quoted 29 lines
drivers/xen/xen-scsiback.c +4 -3
index 7b565632..ad11258 100644
@@ -1885,13 +1885,14 @@ scsiback_make_tpg(struct se_wwn *wwn,
  			struct scsiback_tport, tport_wwn);
 
  	struct scsiback_tpg *tpg;
-	unsigned long tpgt;
+	u16 tpgt;
  	int ret;
 
  	if (strstr(name, "tpgt_") != name)
  		return ERR_PTR(-EINVAL);
-	if (kstrtoul(name + 5, 10, &tpgt) || tpgt > UINT_MAX)
-		return ERR_PTR(-EINVAL);
+	ret = kstrtou16(name + 5, 10, &tpgt);
+	if (ret)
+		return ERR_PTR(ret);
 
  	tpg = kzalloc(sizeof(struct scsiback_tpg), GFP_KERNEL);
  	if (!tpg)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Dan Carpenter
Quoted 7 lines · Dan Carpenter

This code was confusing because we had an unsigned long and then we compared it to UINT_MAX and then we stored it in a u16. How many bytes is this supposed to have: 2, 4 or 16???

I've made it a u16 throughout.

Thanks,

Juergen

Quoted 29 lines
drivers/xen/xen-scsiback.c +4 -3
index 7b565632..ad11258 100644
@@ -1885,13 +1885,14 @@ scsiback_make_tpg(struct se_wwn *wwn,
  			struct scsiback_tport, tport_wwn);
 
  	struct scsiback_tpg *tpg;
-	unsigned long tpgt;
+	u16 tpgt;
  	int ret;
 
  	if (strstr(name, "tpgt_") != name)
  		return ERR_PTR(-EINVAL);
-	if (kstrtoul(name + 5, 10, &tpgt) || tpgt > UINT_MAX)
-		return ERR_PTR(-EINVAL);
+	ret = kstrtou16(name + 5, 10, &tpgt);
+	if (ret)
+		return ERR_PTR(ret);
 
  	tpg = kzalloc(sizeof(struct scsiback_tpg), GFP_KERNEL);
  	if (!tpg)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel