.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * lib/parser.c - simple parser for mount, etc. options. |
---|
3 | | - * |
---|
4 | | - * This source code is licensed under the GNU General Public License, |
---|
5 | | - * Version 2. See the file COPYING for more details. |
---|
6 | 4 | */ |
---|
7 | 5 | |
---|
8 | 6 | #include <linux/ctype.h> |
---|
9 | 7 | #include <linux/types.h> |
---|
10 | 8 | #include <linux/export.h> |
---|
| 9 | +#include <linux/kstrtox.h> |
---|
11 | 10 | #include <linux/parser.h> |
---|
12 | 11 | #include <linux/slab.h> |
---|
13 | 12 | #include <linux/string.h> |
---|
.. | .. |
---|
131 | 130 | char *buf; |
---|
132 | 131 | int ret; |
---|
133 | 132 | long val; |
---|
134 | | - size_t len = s->to - s->from; |
---|
135 | 133 | |
---|
136 | | - buf = kmalloc(len + 1, GFP_KERNEL); |
---|
| 134 | + buf = match_strdup(s); |
---|
137 | 135 | if (!buf) |
---|
138 | 136 | return -ENOMEM; |
---|
139 | | - memcpy(buf, s->from, len); |
---|
140 | | - buf[len] = '\0'; |
---|
141 | 137 | |
---|
142 | 138 | ret = 0; |
---|
143 | 139 | val = simple_strtol(buf, &endp, base); |
---|
.. | .. |
---|
166 | 162 | char *buf; |
---|
167 | 163 | int ret; |
---|
168 | 164 | u64 val; |
---|
169 | | - size_t len = s->to - s->from; |
---|
170 | 165 | |
---|
171 | | - buf = kmalloc(len + 1, GFP_KERNEL); |
---|
| 166 | + buf = match_strdup(s); |
---|
172 | 167 | if (!buf) |
---|
173 | 168 | return -ENOMEM; |
---|
174 | | - memcpy(buf, s->from, len); |
---|
175 | | - buf[len] = '\0'; |
---|
176 | 169 | |
---|
177 | 170 | ret = kstrtoull(buf, base, &val); |
---|
178 | 171 | if (!ret) |
---|
.. | .. |
---|
327 | 320 | */ |
---|
328 | 321 | char *match_strdup(const substring_t *s) |
---|
329 | 322 | { |
---|
330 | | - size_t sz = s->to - s->from + 1; |
---|
331 | | - char *p = kmalloc(sz, GFP_KERNEL); |
---|
332 | | - if (p) |
---|
333 | | - match_strlcpy(p, s, sz); |
---|
334 | | - return p; |
---|
| 323 | + return kmemdup_nul(s->from, s->to - s->from, GFP_KERNEL); |
---|
335 | 324 | } |
---|
336 | 325 | EXPORT_SYMBOL(match_strdup); |
---|