diff options
Diffstat (limited to 'lib/parser.c')
-rw-r--r-- | lib/parser.c | 16 |
1 files changed, 3 insertions, 13 deletions
diff --git a/lib/parser.c b/lib/parser.c index 3278958b472a..dd70e5e6c9e2 100644 --- a/lib/parser.c +++ b/lib/parser.c | |||
@@ -131,13 +131,10 @@ static int match_number(substring_t *s, int *result, int base) | |||
131 | char *buf; | 131 | char *buf; |
132 | int ret; | 132 | int ret; |
133 | long val; | 133 | long val; |
134 | size_t len = s->to - s->from; | ||
135 | 134 | ||
136 | buf = kmalloc(len + 1, GFP_KERNEL); | 135 | buf = match_strdup(s); |
137 | if (!buf) | 136 | if (!buf) |
138 | return -ENOMEM; | 137 | return -ENOMEM; |
139 | memcpy(buf, s->from, len); | ||
140 | buf[len] = '\0'; | ||
141 | 138 | ||
142 | ret = 0; | 139 | ret = 0; |
143 | val = simple_strtol(buf, &endp, base); | 140 | val = simple_strtol(buf, &endp, base); |
@@ -166,13 +163,10 @@ static int match_u64int(substring_t *s, u64 *result, int base) | |||
166 | char *buf; | 163 | char *buf; |
167 | int ret; | 164 | int ret; |
168 | u64 val; | 165 | u64 val; |
169 | size_t len = s->to - s->from; | ||
170 | 166 | ||
171 | buf = kmalloc(len + 1, GFP_KERNEL); | 167 | buf = match_strdup(s); |
172 | if (!buf) | 168 | if (!buf) |
173 | return -ENOMEM; | 169 | return -ENOMEM; |
174 | memcpy(buf, s->from, len); | ||
175 | buf[len] = '\0'; | ||
176 | 170 | ||
177 | ret = kstrtoull(buf, base, &val); | 171 | ret = kstrtoull(buf, base, &val); |
178 | if (!ret) | 172 | if (!ret) |
@@ -327,10 +321,6 @@ EXPORT_SYMBOL(match_strlcpy); | |||
327 | */ | 321 | */ |
328 | char *match_strdup(const substring_t *s) | 322 | char *match_strdup(const substring_t *s) |
329 | { | 323 | { |
330 | size_t sz = s->to - s->from + 1; | 324 | return kmemdup_nul(s->from, s->to - s->from, GFP_KERNEL); |
331 | char *p = kmalloc(sz, GFP_KERNEL); | ||
332 | if (p) | ||
333 | match_strlcpy(p, s, sz); | ||
334 | return p; | ||
335 | } | 325 | } |
336 | EXPORT_SYMBOL(match_strdup); | 326 | EXPORT_SYMBOL(match_strdup); |