Skip to contentSkip to conversation

configfs: documentation: remove unneeded check

PATCH Superseded Dan Carpenter 2 participants 4 messages Oct 27, 2010 – Oct 28, 2010

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

PATCH 1/1 configfs: documentation: remove unneeded check

If "p" is NULL then it will cause an oops when we pass it to simple_strtoul(). In this case "p" can not be NULL so I removed the check and cleaned up the rest of the if condition as well.

Documentation/filesystems/configfs/configfs_example_explicit.c +1 -1
index d428cc9..63ff248 100644
@@ -89,7 +89,7 @@ static ssize_t childless_storeme_write(struct childless *childless,
 	char *p = (char *) page;
 
 	tmp = simple_strtoul(p, &p, 10);
-	if (!p || (*p && (*p != '\n')))
+	if (*p != '\0' && *p != '\n')
 		return -EINVAL;
 
 	if (tmp > INT_MAX)
#1 lore raw
Quoted 11 lines · Dan Carpenter

If "p" is NULL then it will cause an oops when we pass it to simple_strtoul(). In this case "p" can not be NULL so I removed the check and cleaned up the rest of the if condition as well.

Documentation/filesystems/configfs/configfs_example_explicit.c +0 -0
index d428cc9..63ff248 100644

Documentation/filesystems/configfs/configfs_example_explicit.c static ssize_t childless_storeme_write(struct childless *childless, · line 93

Quoted 6 lines
Documentation/filesystems/configfs/configfs_example_explicit.c +1 -1
@@ -89,7 +89,7 @@ static ssize_t childless_storeme_write(struct childless *childless,
 	char *p = (char *) page;
 
 	tmp = simple_strtoul(p, &p, 10);
-	if (!p || (*p && (*p != '\n')))
+	if (*p != '\0' && *p != '\n')
 		return -EINVAL;
	If you're going to prefer "*p != '\0'" to "*p" as a test, I'd

like you to include parens: "if ((*p != '\0') && (*p != '\n'))" While the order of precedence is correct in your change, it makes folks have to stop and think about order of precedence in the first place.

Joel

Signature · 9 lines
Life's Little Instruction Book #444

	"Never underestimate the power of a kind word or deed."

Joel Becker
Senior Development Manager
Oracle
E-mail: [email protected]
Phone: (650) 506-8127
#2 lore raw

PATCH v2 1/1 configfs: documentation: remove unneeded check

If "p" is NULL then it will cause an oops when we pass it to simple_strtoul(). In this case "p" can not be NULL so I removed the check. I also changed the check a little to make it more explicit that we are testing whether p points to the NUL char.

---
V2: Added some parenthesis to make the precedence more clear.

Documentation/filesystems/configfs/configfs_example_explicit.c +1 -1
index d428cc9..63ff248 100644
@@ -89,7 +89,7 @@ static ssize_t childless_storeme_write(struct childless *childless,
 	char *p = (char *) page;
 
 	tmp = simple_strtoul(p, &p, 10);
-	if (!p || (*p && (*p != '\n')))
+	if ((*p != '\0') && (*p != '\n'))
 		return -EINVAL;
 
 	if (tmp > INT_MAX)
Acked-by on v2 1/1
#3 lore raw
Quoted 6 lines · Dan Carpenter

If "p" is NULL then it will cause an oops when we pass it to simple_strtoul(). In this case "p" can not be NULL so I removed the check. I also changed the check a little to make it more explicit that we are testing whether p points to the NUL char.

Quoted 17 lines

---
V2: Added some parenthesis to make the precedence more clear.

Documentation/filesystems/configfs/configfs_example_explicit.c +1 -1
index d428cc9..63ff248 100644
@@ -89,7 +89,7 @@ static ssize_t childless_storeme_write(struct childless *childless,
 	char *p = (char *) page;
 
 	tmp = simple_strtoul(p, &p, 10);
-	if (!p || (*p && (*p != '\n')))
+	if ((*p != '\0') && (*p != '\n'))
 		return -EINVAL;
 
 	if (tmp > INT_MAX)
Signature · 10 lines
"Sometimes I think the surest sign intelligent
 life exists elsewhere in the universe is that
 none of it has tried to contact us."
                                -Calvin & Hobbes

Joel Becker
Senior Development Manager
Oracle
E-mail: [email protected]
Phone: (650) 506-8127