* [PATCH 1/2] kstrto*: add documentation
@ 2012-07-12 20:53 Eldad Zack
2012-07-12 20:53 ` [PATCH 2/2] simple_strto*: annotate function as obsolete Eldad Zack
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Eldad Zack @ 2012-07-12 20:53 UTC (permalink / raw)
To: Andrew Morton, Joe Perches, open list; +Cc: Eldad Zack, J. Bruce Fields
As J. Bruce Fields <bfields@fieldses.org> pointed out, kstrto* is
currently lacking kerneldoc comments.
This patch adds kerneldoc comments to common variants of kstrto*:
kstrto(u)l, kstrto(u)ll and kstrto(u)int.
Cc: J. Bruce Fields <bfields@fieldses.org>
Signed-off-by: Eldad Zack <eldad@fogrefinery.com>
---
include/linux/kernel.h | 36 ++++++++++++++++++++++++++++++++++++
lib/kstrtox.c | 18 ++++++++++++++++++
2 files changed, 54 insertions(+)
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index e07f5e0..582df0f 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -220,6 +220,16 @@ int __must_check _kstrtol(const char *s, unsigned int base, long *res);
int __must_check kstrtoull(const char *s, unsigned int base, unsigned long long *res);
int __must_check kstrtoll(const char *s, unsigned int base, long long *res);
+
+/**
+ * kstrtoul - convert a string to an unsigned long
+ * @s: The start of the string
+ * @base: The number base to use
+ * @res: Where to write the result of the conversion if successful
+ *
+ * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
+ * Used as a replacement for the obsolete simple_strtoul.
+ */
static inline int __must_check kstrtoul(const char *s, unsigned int base, unsigned long *res)
{
/*
@@ -233,6 +243,15 @@ static inline int __must_check kstrtoul(const char *s, unsigned int base, unsign
return _kstrtoul(s, base, res);
}
+/**
+ * kstrtol - convert a string to a long
+ * @s: The start of the string
+ * @base: The number base to use
+ * @res: Where to write the result of the conversion if successful
+ *
+ * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
+ * Used as a replacement for the obsolete simple_strtol.
+ */
static inline int __must_check kstrtol(const char *s, unsigned int base, long *res)
{
/*
@@ -246,7 +265,24 @@ static inline int __must_check kstrtol(const char *s, unsigned int base, long *r
return _kstrtol(s, base, res);
}
+/**
+ * kstrtouint - convert a string to an unsigned int
+ * @s: The start of the string
+ * @base: The number base to use
+ * @res: Where to write the result of the conversion if successful
+ *
+ * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
+ */
int __must_check kstrtouint(const char *s, unsigned int base, unsigned int *res);
+
+/**
+ * kstrtoint - convert a string to an int
+ * @s: The start of the string
+ * @base: The number base to use
+ * @res: Where to write the result of the conversion if successful
+ *
+ * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
+ */
int __must_check kstrtoint(const char *s, unsigned int base, int *res);
static inline int __must_check kstrtou64(const char *s, unsigned int base, u64 *res)
diff --git a/lib/kstrtox.c b/lib/kstrtox.c
index c3615ea..7f5bca2 100644
--- a/lib/kstrtox.c
+++ b/lib/kstrtox.c
@@ -104,6 +104,15 @@ static int _kstrtoull(const char *s, unsigned int base, unsigned long long *res)
return 0;
}
+/**
+ * kstrtoull - convert a string to an unsigned long long
+ * @s: The start of the string
+ * @base: The number base to use
+ * @res: Where to write the result of the conversion if successful
+ *
+ * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
+ * Used as a replacement for the obsolete simple_strtoull.
+ */
int kstrtoull(const char *s, unsigned int base, unsigned long long *res)
{
if (s[0] == '+')
@@ -112,6 +121,15 @@ int kstrtoull(const char *s, unsigned int base, unsigned long long *res)
}
EXPORT_SYMBOL(kstrtoull);
+/**
+ * kstrtoll - convert a string to a long long
+ * @s: The start of the string
+ * @base: The number base to use
+ * @res: Where to write the result of the conversion if successful
+ *
+ * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
+ * Used as a replacement for the obsolete simple_strtoll.
+ */
int kstrtoll(const char *s, unsigned int base, long long *res)
{
unsigned long long tmp;
--
1.7.10.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/2] simple_strto*: annotate function as obsolete
2012-07-12 20:53 [PATCH 1/2] kstrto*: add documentation Eldad Zack
@ 2012-07-12 20:53 ` Eldad Zack
2012-07-12 21:17 ` [PATCH 1/2] kstrto*: add documentation Stephen Boyd
2012-07-12 21:23 ` J. Bruce Fields
2 siblings, 0 replies; 9+ messages in thread
From: Eldad Zack @ 2012-07-12 20:53 UTC (permalink / raw)
To: Andrew Morton, Joe Perches, open list; +Cc: Eldad Zack, J. Bruce Fields
This patch update the documentation to simple_strto* to reflect
that it has been obsoleted and advise the usage of kstrto*.
Cc: J. Bruce Fields <bfields@fieldses.org>
Signed-off-by: Eldad Zack <eldad@fogrefinery.com>
---
lib/vsprintf.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index c3f36d41..1980cf3 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -38,6 +38,8 @@
* @cp: The start of the string
* @endp: A pointer to the end of the parsed string will be placed here
* @base: The number base to use
+ *
+ * This function is obsolete. Please use kstrtoull instead.
*/
unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base)
{
@@ -61,6 +63,8 @@ EXPORT_SYMBOL(simple_strtoull);
* @cp: The start of the string
* @endp: A pointer to the end of the parsed string will be placed here
* @base: The number base to use
+ *
+ * This function is obsolete. Please use kstrtoul instead.
*/
unsigned long simple_strtoul(const char *cp, char **endp, unsigned int base)
{
@@ -73,6 +77,8 @@ EXPORT_SYMBOL(simple_strtoul);
* @cp: The start of the string
* @endp: A pointer to the end of the parsed string will be placed here
* @base: The number base to use
+ *
+ * This function is obsolete. Please use kstrtol instead.
*/
long simple_strtol(const char *cp, char **endp, unsigned int base)
{
@@ -88,6 +94,8 @@ EXPORT_SYMBOL(simple_strtol);
* @cp: The start of the string
* @endp: A pointer to the end of the parsed string will be placed here
* @base: The number base to use
+ *
+ * This function is obsolete. Please use kstrtoll instead.
*/
long long simple_strtoll(const char *cp, char **endp, unsigned int base)
{
--
1.7.10.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] kstrto*: add documentation
2012-07-12 20:53 [PATCH 1/2] kstrto*: add documentation Eldad Zack
2012-07-12 20:53 ` [PATCH 2/2] simple_strto*: annotate function as obsolete Eldad Zack
@ 2012-07-12 21:17 ` Stephen Boyd
2012-07-12 21:19 ` Stephen Boyd
2012-07-12 21:23 ` J. Bruce Fields
2 siblings, 1 reply; 9+ messages in thread
From: Stephen Boyd @ 2012-07-12 21:17 UTC (permalink / raw)
To: Eldad Zack; +Cc: Andrew Morton, Joe Perches, open list, J. Bruce Fields
On 07/12/12 13:53, Eldad Zack wrote:
>
> diff --git a/include/linux/kernel.h b/include/linux/kernel.h
> index e07f5e0..582df0f 100644
> --- a/include/linux/kernel.h
> +++ b/include/linux/kernel.h
> @@ -220,6 +220,16 @@ int __must_check _kstrtol(const char *s, unsigned int base, long *res);
>
> int __must_check kstrtoull(const char *s, unsigned int base, unsigned long long *res);
> int __must_check kstrtoll(const char *s, unsigned int base, long long *res);
> +
> +/**
> + * kstrtoul - convert a string to an unsigned long
Aren't function names supposed to have () after them in kernel doc?
--
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] kstrto*: add documentation
2012-07-12 21:17 ` [PATCH 1/2] kstrto*: add documentation Stephen Boyd
@ 2012-07-12 21:19 ` Stephen Boyd
0 siblings, 0 replies; 9+ messages in thread
From: Stephen Boyd @ 2012-07-12 21:19 UTC (permalink / raw)
To: Eldad Zack; +Cc: Andrew Morton, Joe Perches, open list, J. Bruce Fields
On 07/12/12 14:17, Stephen Boyd wrote:
> On 07/12/12 13:53, Eldad Zack wrote:
>> diff --git a/include/linux/kernel.h b/include/linux/kernel.h
>> index e07f5e0..582df0f 100644
>> --- a/include/linux/kernel.h
>> +++ b/include/linux/kernel.h
>> @@ -220,6 +220,16 @@ int __must_check _kstrtol(const char *s, unsigned int base, long *res);
>>
>> int __must_check kstrtoull(const char *s, unsigned int base, unsigned long long *res);
>> int __must_check kstrtoll(const char *s, unsigned int base, long long *res);
>> +
>> +/**
>> + * kstrtoul - convert a string to an unsigned long
> Aren't function names supposed to have () after them in kernel doc?
>
Argh, ignore me. Apparently it's optional.
--
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] kstrto*: add documentation
2012-07-12 20:53 [PATCH 1/2] kstrto*: add documentation Eldad Zack
2012-07-12 20:53 ` [PATCH 2/2] simple_strto*: annotate function as obsolete Eldad Zack
2012-07-12 21:17 ` [PATCH 1/2] kstrto*: add documentation Stephen Boyd
@ 2012-07-12 21:23 ` J. Bruce Fields
2012-07-12 22:09 ` Eldad Zack
2 siblings, 1 reply; 9+ messages in thread
From: J. Bruce Fields @ 2012-07-12 21:23 UTC (permalink / raw)
To: Eldad Zack; +Cc: Andrew Morton, Joe Perches, open list
On Thu, Jul 12, 2012 at 10:53:13PM +0200, Eldad Zack wrote:
> As J. Bruce Fields <bfields@fieldses.org> pointed out, kstrto* is
> currently lacking kerneldoc comments.
> This patch adds kerneldoc comments to common variants of kstrto*:
> kstrto(u)l, kstrto(u)ll and kstrto(u)int.
>
> Cc: J. Bruce Fields <bfields@fieldses.org>
> Signed-off-by: Eldad Zack <eldad@fogrefinery.com>
> ---
> include/linux/kernel.h | 36 ++++++++++++++++++++++++++++++++++++
> lib/kstrtox.c | 18 ++++++++++++++++++
> 2 files changed, 54 insertions(+)
>
> diff --git a/include/linux/kernel.h b/include/linux/kernel.h
> index e07f5e0..582df0f 100644
> --- a/include/linux/kernel.h
> +++ b/include/linux/kernel.h
> @@ -220,6 +220,16 @@ int __must_check _kstrtol(const char *s, unsigned int base, long *res);
>
> int __must_check kstrtoull(const char *s, unsigned int base, unsigned long long *res);
> int __must_check kstrtoll(const char *s, unsigned int base, long long *res);
> +
> +/**
> + * kstrtoul - convert a string to an unsigned long
Also, is it worth mentioning that the number is required to be followed
by a string or newline?
--b.
> + * @s: The start of the string
> + * @base: The number base to use
> + * @res: Where to write the result of the conversion if successful
> + *
> + * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
> + * Used as a replacement for the obsolete simple_strtoul.
> + */
> static inline int __must_check kstrtoul(const char *s, unsigned int base, unsigned long *res)
> {
> /*
> @@ -233,6 +243,15 @@ static inline int __must_check kstrtoul(const char *s, unsigned int base, unsign
> return _kstrtoul(s, base, res);
> }
>
> +/**
> + * kstrtol - convert a string to a long
> + * @s: The start of the string
> + * @base: The number base to use
> + * @res: Where to write the result of the conversion if successful
> + *
> + * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
> + * Used as a replacement for the obsolete simple_strtol.
> + */
> static inline int __must_check kstrtol(const char *s, unsigned int base, long *res)
> {
> /*
> @@ -246,7 +265,24 @@ static inline int __must_check kstrtol(const char *s, unsigned int base, long *r
> return _kstrtol(s, base, res);
> }
>
> +/**
> + * kstrtouint - convert a string to an unsigned int
> + * @s: The start of the string
> + * @base: The number base to use
> + * @res: Where to write the result of the conversion if successful
> + *
> + * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
> + */
> int __must_check kstrtouint(const char *s, unsigned int base, unsigned int *res);
> +
> +/**
> + * kstrtoint - convert a string to an int
> + * @s: The start of the string
> + * @base: The number base to use
> + * @res: Where to write the result of the conversion if successful
> + *
> + * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
> + */
> int __must_check kstrtoint(const char *s, unsigned int base, int *res);
>
> static inline int __must_check kstrtou64(const char *s, unsigned int base, u64 *res)
> diff --git a/lib/kstrtox.c b/lib/kstrtox.c
> index c3615ea..7f5bca2 100644
> --- a/lib/kstrtox.c
> +++ b/lib/kstrtox.c
> @@ -104,6 +104,15 @@ static int _kstrtoull(const char *s, unsigned int base, unsigned long long *res)
> return 0;
> }
>
> +/**
> + * kstrtoull - convert a string to an unsigned long long
> + * @s: The start of the string
> + * @base: The number base to use
> + * @res: Where to write the result of the conversion if successful
> + *
> + * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
> + * Used as a replacement for the obsolete simple_strtoull.
> + */
> int kstrtoull(const char *s, unsigned int base, unsigned long long *res)
> {
> if (s[0] == '+')
> @@ -112,6 +121,15 @@ int kstrtoull(const char *s, unsigned int base, unsigned long long *res)
> }
> EXPORT_SYMBOL(kstrtoull);
>
> +/**
> + * kstrtoll - convert a string to a long long
> + * @s: The start of the string
> + * @base: The number base to use
> + * @res: Where to write the result of the conversion if successful
> + *
> + * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
> + * Used as a replacement for the obsolete simple_strtoll.
> + */
> int kstrtoll(const char *s, unsigned int base, long long *res)
> {
> unsigned long long tmp;
> --
> 1.7.10.4
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] kstrto*: add documentation
2012-07-12 21:23 ` J. Bruce Fields
@ 2012-07-12 22:09 ` Eldad Zack
2012-07-12 22:16 ` J. Bruce Fields
0 siblings, 1 reply; 9+ messages in thread
From: Eldad Zack @ 2012-07-12 22:09 UTC (permalink / raw)
To: J. Bruce Fields; +Cc: Andrew Morton, Joe Perches, open list
On Thu, 12 Jul 2012, J. Bruce Fields wrote:
> On Thu, Jul 12, 2012 at 10:53:13PM +0200, Eldad Zack wrote:
> > +/**
> > + * kstrtoul - convert a string to an unsigned long
>
> Also, is it worth mentioning that the number is required to be followed
> by a string or newline?
I am not sure if I understand _parse_integer correctly (which is called
to do the actual parsing and has a very nice comment to it) - but it
expects a null-terminated string, but will also stop as soon as it
bumps into any other non-number character without error (please correct
me I'm wrong).
In that case maybe "This function stops parsing as soon as it gets to a
character which doesn't belong to the given base, including newline
or null.".
And now that I read it more closely, how about:
"If base is given as 0, then the base of the string is automatically
detected with the conventional semantics: If the string begins with 0x
the number will be parsed as a hexadecimel (case insensitive). If
it otherwise begins with 0, it will be parsed as an octal number.
Otherwise it will be parsed as a decimal."
Eldad
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] kstrto*: add documentation
2012-07-12 22:09 ` Eldad Zack
@ 2012-07-12 22:16 ` J. Bruce Fields
2012-07-12 22:27 ` Eldad Zack
0 siblings, 1 reply; 9+ messages in thread
From: J. Bruce Fields @ 2012-07-12 22:16 UTC (permalink / raw)
To: Eldad Zack; +Cc: Andrew Morton, Joe Perches, open list
On Fri, Jul 13, 2012 at 12:09:37AM +0200, Eldad Zack wrote:
>
> On Thu, 12 Jul 2012, J. Bruce Fields wrote:
> > On Thu, Jul 12, 2012 at 10:53:13PM +0200, Eldad Zack wrote:
> > > +/**
> > > + * kstrtoul - convert a string to an unsigned long
> >
> > Also, is it worth mentioning that the number is required to be followed
> > by a string or newline?
>
> I am not sure if I understand _parse_integer correctly (which is called
> to do the actual parsing and has a very nice comment to it) - but it
> expects a null-terminated string, but will also stop as soon as it
> bumps into any other non-number character without error (please correct
> me I'm wrong).
I believe it, but, in _kstrtoull:
rv = _parse_integer(s, base, &_res);
if (rv & KSTRTOX_OVERFLOW)
return -ERANGE;
rv &= ~KSTRTOX_OVERFLOW;
if (rv == 0)
return -EINVAL;
s += rv;
if (*s == '\n')
s++;
if (*s)
return -EINVAL;
So actually it appears the string must be all numeric except possibly a final
newline.
--b.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] kstrto*: add documentation
2012-07-12 22:16 ` J. Bruce Fields
@ 2012-07-12 22:27 ` Eldad Zack
0 siblings, 0 replies; 9+ messages in thread
From: Eldad Zack @ 2012-07-12 22:27 UTC (permalink / raw)
To: J. Bruce Fields; +Cc: Andrew Morton, Joe Perches, open list
On Thu, 12 Jul 2012, J. Bruce Fields wrote:
> On Fri, Jul 13, 2012 at 12:09:37AM +0200, Eldad Zack wrote:
> >
> > On Thu, 12 Jul 2012, J. Bruce Fields wrote:
> > I am not sure if I understand _parse_integer correctly (which is called
> > to do the actual parsing and has a very nice comment to it) - but it
> > expects a null-terminated string, but will also stop as soon as it
> > bumps into any other non-number character without error (please correct
> > me I'm wrong).
>
> I believe it, but, in _kstrtoull:
>
> rv = _parse_integer(s, base, &_res);
> if (rv & KSTRTOX_OVERFLOW)
> return -ERANGE;
> rv &= ~KSTRTOX_OVERFLOW;
> if (rv == 0)
> return -EINVAL;
> s += rv;
> if (*s == '\n')
> s++;
> if (*s)
> return -EINVAL;
>
> So actually it appears the string must be all numeric except possibly a final
> newline.
Ah. You're right of course. Thanks! I also noticed I missed the SGML
templates, so I'll resend this at some point later.
Eldad
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/2] kstrto*: add documentation
@ 2012-09-30 11:44 Eldad Zack
0 siblings, 0 replies; 9+ messages in thread
From: Eldad Zack @ 2012-09-30 11:44 UTC (permalink / raw)
To: J. Bruce Fields
Cc: Andrew Morton, Joe Perches, linux-kernel, Rob Landley, linux-doc,
Eldad Zack
As J. Bruce Fields <bfields@fieldses.org> pointed out, kstrto* is
currently lacking kerneldoc comments.
This patch adds kerneldoc comments to common variants of kstrto*:
kstrto(u)l, kstrto(u)ll and kstrto(u)int.
Cc: J. Bruce Fields <bfields@fieldses.org>
Signed-off-by: Eldad Zack <eldad@fogrefinery.com>
---
v2: includes typo fix from Joe Perches <joe@perches.com>,
added details as suggested by J. Bruce Fields <bfields@fieldses.org>,
added the kstrto* functions to string conversions section in SGML.
Documentation/DocBook/kernel-api.tmpl | 3 ++
include/linux/kernel.h | 33 +++++++++++++++++
lib/kstrtox.c | 64 +++++++++++++++++++++++++++++++++
3 files changed, 100 insertions(+), 0 deletions(-)
diff --git a/Documentation/DocBook/kernel-api.tmpl b/Documentation/DocBook/kernel-api.tmpl
index 00687ee..f75ab4c 100644
--- a/Documentation/DocBook/kernel-api.tmpl
+++ b/Documentation/DocBook/kernel-api.tmpl
@@ -58,6 +58,9 @@
<sect1><title>String Conversions</title>
!Elib/vsprintf.c
+!Finclude/linux/kernel.h kstrtol
+!Finclude/linux/kernel.h kstrtoul
+!Elib/kstrtox.c
</sect1>
<sect1><title>String Manipulation</title>
<!-- All functions are exported at now
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 2451f1f..ef7f01b 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -228,6 +228,23 @@ int __must_check _kstrtol(const char *s, unsigned int base, long *res);
int __must_check kstrtoull(const char *s, unsigned int base, unsigned long long *res);
int __must_check kstrtoll(const char *s, unsigned int base, long long *res);
+
+/**
+ * kstrtoul - convert a string to an unsigned long
+ * @s: The start of the string. The string must be null-terminated, and may also
+ * include a single newline before its terminating null. The first character
+ * may also be a plus sign, but not a minus sign.
+ * @base: The number base to use. The maximum supported base is 16. If base is
+ * given as 0, then the base of the string is automatically detected with the
+ * conventional semantics - If it begins with 0x the number will be parsed as a
+ * hexadecimal (case insensitive), if it otherwise begins with 0, it will be
+ * parsed as an octal number. Otherwise it will be parsed as a decimal.
+ * @res: Where to write the result of the conversion on success.
+ *
+ * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
+ * Used as a replacement for the obsolete simple_strtoull. Return code must
+ * be checked.
+*/
static inline int __must_check kstrtoul(const char *s, unsigned int base, unsigned long *res)
{
/*
@@ -241,6 +258,22 @@ static inline int __must_check kstrtoul(const char *s, unsigned int base, unsign
return _kstrtoul(s, base, res);
}
+/**
+ * kstrtol - convert a string to a long
+ * @s: The start of the string. The string must be null-terminated, and may also
+ * include a single newline before its terminating null. The first character
+ * may also be a plus sign or a minus sign.
+ * @base: The number base to use. The maximum supported base is 16. If base is
+ * given as 0, then the base of the string is automatically detected with the
+ * conventional semantics - If it begins with 0x the number will be parsed as a
+ * hexadecimal (case insensitive), if it otherwise begins with 0, it will be
+ * parsed as an octal number. Otherwise it will be parsed as a decimal.
+ * @res: Where to write the result of the conversion on success.
+ *
+ * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
+ * Used as a replacement for the obsolete simple_strtoull. Return code must
+ * be checked.
+ */
static inline int __must_check kstrtol(const char *s, unsigned int base, long *res)
{
/*
diff --git a/lib/kstrtox.c b/lib/kstrtox.c
index c3615ea..f2372ca 100644
--- a/lib/kstrtox.c
+++ b/lib/kstrtox.c
@@ -104,6 +104,22 @@ static int _kstrtoull(const char *s, unsigned int base, unsigned long long *res)
return 0;
}
+/**
+ * kstrtoull - convert a string to an unsigned long long
+ * @s: The start of the string. The string must be null-terminated, and may also
+ * include a single newline before its terminating null. The first character
+ * may also be a plus sign, but not a minus sign.
+ * @base: The number base to use. The maximum supported base is 16. If base is
+ * given as 0, then the base of the string is automatically detected with the
+ * conventional semantics - If it begins with 0x the number will be parsed as a
+ * hexadecimal (case insensitive), if it otherwise begins with 0, it will be
+ * parsed as an octal number. Otherwise it will be parsed as a decimal.
+ * @res: Where to write the result of the conversion on success.
+ *
+ * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
+ * Used as a replacement for the obsolete simple_strtoull. Return code must
+ * be checked.
+ */
int kstrtoull(const char *s, unsigned int base, unsigned long long *res)
{
if (s[0] == '+')
@@ -112,6 +128,22 @@ int kstrtoull(const char *s, unsigned int base, unsigned long long *res)
}
EXPORT_SYMBOL(kstrtoull);
+/**
+ * kstrtoll - convert a string to a long long
+ * @s: The start of the string. The string must be null-terminated, and may also
+ * include a single newline before its terminating null. The first character
+ * may also be a plus sign or a minus sign.
+ * @base: The number base to use. The maximum supported base is 16. If base is
+ * given as 0, then the base of the string is automatically detected with the
+ * conventional semantics - If it begins with 0x the number will be parsed as a
+ * hexadecimal (case insensitive), if it otherwise begins with 0, it will be
+ * parsed as an octal number. Otherwise it will be parsed as a decimal.
+ * @res: Where to write the result of the conversion on success.
+ *
+ * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
+ * Used as a replacement for the obsolete simple_strtoull. Return code must
+ * be checked.
+ */
int kstrtoll(const char *s, unsigned int base, long long *res)
{
unsigned long long tmp;
@@ -168,6 +200,22 @@ int _kstrtol(const char *s, unsigned int base, long *res)
}
EXPORT_SYMBOL(_kstrtol);
+/**
+ * kstrtouint - convert a string to an unsigned int
+ * @s: The start of the string. The string must be null-terminated, and may also
+ * include a single newline before its terminating null. The first character
+ * may also be a plus sign, but not a minus sign.
+ * @base: The number base to use. The maximum supported base is 16. If base is
+ * given as 0, then the base of the string is automatically detected with the
+ * conventional semantics - If it begins with 0x the number will be parsed as a
+ * hexadecimal (case insensitive), if it otherwise begins with 0, it will be
+ * parsed as an octal number. Otherwise it will be parsed as a decimal.
+ * @res: Where to write the result of the conversion on success.
+ *
+ * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
+ * Used as a replacement for the obsolete simple_strtoull. Return code must
+ * be checked.
+ */
int kstrtouint(const char *s, unsigned int base, unsigned int *res)
{
unsigned long long tmp;
@@ -183,6 +231,22 @@ int kstrtouint(const char *s, unsigned int base, unsigned int *res)
}
EXPORT_SYMBOL(kstrtouint);
+/**
+ * kstrtoint - convert a string to an int
+ * @s: The start of the string. The string must be null-terminated, and may also
+ * include a single newline before its terminating null. The first character
+ * may also be a plus sign or a minus sign.
+ * @base: The number base to use. The maximum supported base is 16. If base is
+ * given as 0, then the base of the string is automatically detected with the
+ * conventional semantics - If it begins with 0x the number will be parsed as a
+ * hexadecimal (case insensitive), if it otherwise begins with 0, it will be
+ * parsed as an octal number. Otherwise it will be parsed as a decimal.
+ * @res: Where to write the result of the conversion on success.
+ *
+ * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
+ * Used as a replacement for the obsolete simple_strtoull. Return code must
+ * be checked.
+ */
int kstrtoint(const char *s, unsigned int base, int *res)
{
long long tmp;
--
1.7.8.6
^ permalink raw reply related [flat|nested] 9+ messages in thread
end of thread, other threads:[~2012-09-30 11:45 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-12 20:53 [PATCH 1/2] kstrto*: add documentation Eldad Zack
2012-07-12 20:53 ` [PATCH 2/2] simple_strto*: annotate function as obsolete Eldad Zack
2012-07-12 21:17 ` [PATCH 1/2] kstrto*: add documentation Stephen Boyd
2012-07-12 21:19 ` Stephen Boyd
2012-07-12 21:23 ` J. Bruce Fields
2012-07-12 22:09 ` Eldad Zack
2012-07-12 22:16 ` J. Bruce Fields
2012-07-12 22:27 ` Eldad Zack
2012-09-30 11:44 Eldad Zack
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.