Patchwork [1/2] mtd-utils: improve simple_strtoX usage commentary

login
register
mail settings
Submitter Artem Bityutskiy
Date April 8, 2011, 3:07 p.m.
Message ID <1302275249-11962-1-git-send-email-dedekind1@gmail.com>
Download mbox | patch
Permalink /patch/90378/
State New
Headers show

Comments

Artem Bityutskiy - April 8, 2011, 3:07 p.m.
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
 include/common.h |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
Mike Frysinger - April 8, 2011, 4:20 p.m.
On Fri, Apr 8, 2011 at 11:07, Artem Bityutskiy wrote:
> + * num = simple_strtoul(str, &error);
> + * if (error || !is_valid_number(num))
> + *     error_happened();

when i read this, it makes me think there is a "is_valid_number()"
function i should be calling.

maybe something like:
if (error || ... number is out of range for your need ...)
-mike
Artem Bityutskiy - April 9, 2011, 2:39 p.m.
On Fri, 2011-04-08 at 12:20 -0400, Mike Frysinger wrote:
> On Fri, Apr 8, 2011 at 11:07, Artem Bityutskiy wrote:
> > + * num = simple_strtoul(str, &error);
> > + * if (error || !is_valid_number(num))
> > + *     error_happened();
> 
> when i read this, it makes me think there is a "is_valid_number()"
> function i should be calling.
> 
> maybe something like:
> if (error || ... number is out of range for your need ...)
> -mike

I'll do this and push this out, thanks for review!

Patch

diff --git a/include/common.h b/include/common.h
index 2e5c2a0..0e3526a 100644
--- a/include/common.h
+++ b/include/common.h
@@ -93,6 +93,17 @@  static inline int is_power_of_2(unsigned long long n)
  * simple_strtoX - convert a hex/dec/oct string into a number
  * @snum: buffer to convert
  * @error: set to 1 when buffer isn't fully consumed
+ *
+ * These functions are similar to the standard strtoX() functions, but they are
+ * a little bit easier to use if you want to convert full string of digits into
+ * the binary form. The typical usage:
+ *
+ * int error = 0;
+ * unsigned long num;
+ *
+ * num = simple_strtoul(str, &error);
+ * if (error || !is_valid_number(num))
+ * 	error_happened();
  */
 #define simple_strtoX(func, type) \
 static inline type simple_##func(const char *snum, int *error) \