2.6.23-rc2-mm2: strtol_check_range patches

From: Alexey Dobriyan
Date: Mon Aug 13 2007 - 10:30:31 EST


Andrew please drop
introduce-strtol_check_range-fix.patch
introduce-strtol_check_range.patch
from -mm.

strtol_check_range() semantics is broken, because caller can't distinguish
-E from valid negative number if he wants to negative integers. Comment
mentions this, but we don't want to such horrible and not well thought
out function to lib/ .

If anything it should be strtonum() with additional trailing '\n' check.

+ * Do not use this to convert numbers that are allowed to be negative.
+ */
+long strtol_check_range(const char *cp, long min, long max, unsigned int base)
+{
+ long ret;
+ char *p = (char *) cp;
+
+ WARN_ON(min < 0);
+ WARN_ON(max < min);
+
+ ret = simple_strtol(p, &p, base);
+
+ if (*p && (*p != '\n'))
+ return -EINVAL;
+ if ((ret < min) || (ret > max))
+ return -EINVAL;
+
+ return ret;
+}

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/