diff options
author | Kinglong Mee <kinglongmee@gmail.com> | 2015-09-11 21:37:18 -0400 |
---|---|---|
committer | Trond Myklebust <trond.myklebust@primarydata.com> | 2015-11-03 15:56:49 -0500 |
commit | 941c3ff3102ccce440034d59cf9e4e9cc10b720d (patch) | |
tree | 2c4fbe2ccfefef8f5daa60e88d98dd91301de1a7 | |
parent | 1ca843a2d28dec89e58e7227c27a9d55f21f59e1 (diff) |
Sunrpc: Supports hexadecimal number for sysctl files of sunrpc debug
The sunrpc debug sysctl files only accept decimal number right now.
But all the XXXDBUG_XXX macros are defined as hexadecimal.
It is not easy to set or check an separate flag.
This patch let those files support accepting hexadecimal number,
(decimal number is also supported). Also, display it as hexadecimal.
v2,
Remove duplicate parsing of '0x...', just using simple_strtol(tmpbuf, &s, 0)
Fix a bug of isspace() checking after parsing
Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
-rw-r--r-- | net/sunrpc/sysctl.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/net/sunrpc/sysctl.c b/net/sunrpc/sysctl.c index 887f0183b4c6..c88d9bc06f5c 100644 --- a/net/sunrpc/sysctl.c +++ b/net/sunrpc/sysctl.c | |||
@@ -76,7 +76,7 @@ static int | |||
76 | proc_dodebug(struct ctl_table *table, int write, | 76 | proc_dodebug(struct ctl_table *table, int write, |
77 | void __user *buffer, size_t *lenp, loff_t *ppos) | 77 | void __user *buffer, size_t *lenp, loff_t *ppos) |
78 | { | 78 | { |
79 | char tmpbuf[20], c, *s; | 79 | char tmpbuf[20], c, *s = NULL; |
80 | char __user *p; | 80 | char __user *p; |
81 | unsigned int value; | 81 | unsigned int value; |
82 | size_t left, len; | 82 | size_t left, len; |
@@ -103,23 +103,24 @@ proc_dodebug(struct ctl_table *table, int write, | |||
103 | return -EFAULT; | 103 | return -EFAULT; |
104 | tmpbuf[left] = '\0'; | 104 | tmpbuf[left] = '\0'; |
105 | 105 | ||
106 | for (s = tmpbuf, value = 0; '0' <= *s && *s <= '9'; s++, left--) | 106 | value = simple_strtol(tmpbuf, &s, 0); |
107 | value = 10 * value + (*s - '0'); | 107 | if (s) { |
108 | if (*s && !isspace(*s)) | 108 | left -= (s - tmpbuf); |
109 | return -EINVAL; | 109 | if (left && !isspace(*s)) |
110 | while (left && isspace(*s)) | 110 | return -EINVAL; |
111 | left--, s++; | 111 | while (left && isspace(*s)) |
112 | left--, s++; | ||
113 | } else | ||
114 | left = 0; | ||
112 | *(unsigned int *) table->data = value; | 115 | *(unsigned int *) table->data = value; |
113 | /* Display the RPC tasks on writing to rpc_debug */ | 116 | /* Display the RPC tasks on writing to rpc_debug */ |
114 | if (strcmp(table->procname, "rpc_debug") == 0) | 117 | if (strcmp(table->procname, "rpc_debug") == 0) |
115 | rpc_show_tasks(&init_net); | 118 | rpc_show_tasks(&init_net); |
116 | } else { | 119 | } else { |
117 | if (!access_ok(VERIFY_WRITE, buffer, left)) | 120 | len = sprintf(tmpbuf, "0x%04x", *(unsigned int *) table->data); |
118 | return -EFAULT; | ||
119 | len = sprintf(tmpbuf, "%d", *(unsigned int *) table->data); | ||
120 | if (len > left) | 121 | if (len > left) |
121 | len = left; | 122 | len = left; |
122 | if (__copy_to_user(buffer, tmpbuf, len)) | 123 | if (copy_to_user(buffer, tmpbuf, len)) |
123 | return -EFAULT; | 124 | return -EFAULT; |
124 | if ((left -= len) > 0) { | 125 | if ((left -= len) > 0) { |
125 | if (put_user('\n', (char __user *)buffer + len)) | 126 | if (put_user('\n', (char __user *)buffer + len)) |