* [PATCH V2] kernel/res_counter.c: replace simple_strtoull by kstrtoull
@ 2014-05-08 17:00 Fabian Frederick
2014-05-08 20:54 ` Andrew Morton
0 siblings, 1 reply; 2+ messages in thread
From: Fabian Frederick @ 2014-05-08 17:00 UTC (permalink / raw)
To: linux-kernel; +Cc: akpm, Michal Hocko
Thanks to Andrew Morton for commenting first version.
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Michal Hocko <mhocko@suse.cz>
Signed-off-by: Fabian Frederick <fabf@skynet.be>
---
V2: Suggestions by Andrew Morton
-use internal rc variable
-simplify if condition
kernel/res_counter.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/res_counter.c b/kernel/res_counter.c
index 51dbac6..f65a95c 100644
--- a/kernel/res_counter.c
+++ b/kernel/res_counter.c
@@ -186,8 +186,8 @@ int res_counter_memparse_write_strategy(const char *buf,
/* return RES_COUNTER_MAX(unlimited) if "-1" is specified */
if (*buf == '-') {
- res = simple_strtoull(buf + 1, &end, 10);
- if (res != 1 || *end != '\0')
+ int rc = kstrtoull(buf + 1, 10, &res);
+ if ((res != 1) || rc)
return -EINVAL;
*resp = RES_COUNTER_MAX;
return 0;
--
1.9.1
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH V2] kernel/res_counter.c: replace simple_strtoull by kstrtoull
2014-05-08 17:00 [PATCH V2] kernel/res_counter.c: replace simple_strtoull by kstrtoull Fabian Frederick
@ 2014-05-08 20:54 ` Andrew Morton
0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2014-05-08 20:54 UTC (permalink / raw)
To: Fabian Frederick; +Cc: linux-kernel, Michal Hocko
On Thu, 8 May 2014 19:00:43 +0200 Fabian Frederick <fabf@skynet.be> wrote:
> ...
>
> --- a/kernel/res_counter.c
> +++ b/kernel/res_counter.c
> @@ -186,8 +186,8 @@ int res_counter_memparse_write_strategy(const char *buf,
>
> /* return RES_COUNTER_MAX(unlimited) if "-1" is specified */
> if (*buf == '-') {
> - res = simple_strtoull(buf + 1, &end, 10);
> - if (res != 1 || *end != '\0')
> + int rc = kstrtoull(buf + 1, 10, &res);
> + if ((res != 1) || rc)
> return -EINVAL;
> *resp = RES_COUNTER_MAX;
Two more things!
- there should be a newline after definitions, before code.
- we shouldn't overwrite the kstrtoull() return value. In this case it
might have returned -ERANGE but this code will replace that with EINVAL.
--- a/kernel/res_counter.c~kernel-res_counterc-replace-simple_strtoull-by-kstrtoull-fix
+++ a/kernel/res_counter.c
@@ -189,7 +189,10 @@ int res_counter_memparse_write_strategy(
/* return RES_COUNTER_MAX(unlimited) if "-1" is specified */
if (*buf == '-') {
int rc = kstrtoull(buf + 1, 10, &res);
- if ((res != 1) || rc)
+
+ if (rc)
+ return rc;
+ if (res != 1)
return -EINVAL;
*resp = RES_COUNTER_MAX;
return 0;
_
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-05-08 20:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-08 17:00 [PATCH V2] kernel/res_counter.c: replace simple_strtoull by kstrtoull Fabian Frederick
2014-05-08 20:54 ` Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®