hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/lib/parser.c
....@@ -1,8 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * 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.
64 */
75
86 #include <linux/ctype.h>
....@@ -131,13 +129,10 @@
131129 char *buf;
132130 int ret;
133131 long val;
134
- size_t len = s->to - s->from;
135132
136
- buf = kmalloc(len + 1, GFP_KERNEL);
133
+ buf = match_strdup(s);
137134 if (!buf)
138135 return -ENOMEM;
139
- memcpy(buf, s->from, len);
140
- buf[len] = '\0';
141136
142137 ret = 0;
143138 val = simple_strtol(buf, &endp, base);
....@@ -166,13 +161,10 @@
166161 char *buf;
167162 int ret;
168163 u64 val;
169
- size_t len = s->to - s->from;
170164
171
- buf = kmalloc(len + 1, GFP_KERNEL);
165
+ buf = match_strdup(s);
172166 if (!buf)
173167 return -ENOMEM;
174
- memcpy(buf, s->from, len);
175
- buf[len] = '\0';
176168
177169 ret = kstrtoull(buf, base, &val);
178170 if (!ret)
....@@ -327,10 +319,6 @@
327319 */
328320 char *match_strdup(const substring_t *s)
329321 {
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;
322
+ return kmemdup_nul(s->from, s->to - s->from, GFP_KERNEL);
335323 }
336324 EXPORT_SYMBOL(match_strdup);