hc
2024-05-10 23fa18eaa71266feff7ba8d83022d9e1cc83c65a
kernel/lib/parser.c
....@@ -1,13 +1,12 @@
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>
97 #include <linux/types.h>
108 #include <linux/export.h>
9
+#include <linux/kstrtox.h>
1110 #include <linux/parser.h>
1211 #include <linux/slab.h>
1312 #include <linux/string.h>
....@@ -131,13 +130,10 @@
131130 char *buf;
132131 int ret;
133132 long val;
134
- size_t len = s->to - s->from;
135133
136
- buf = kmalloc(len + 1, GFP_KERNEL);
134
+ buf = match_strdup(s);
137135 if (!buf)
138136 return -ENOMEM;
139
- memcpy(buf, s->from, len);
140
- buf[len] = '\0';
141137
142138 ret = 0;
143139 val = simple_strtol(buf, &endp, base);
....@@ -166,13 +162,10 @@
166162 char *buf;
167163 int ret;
168164 u64 val;
169
- size_t len = s->to - s->from;
170165
171
- buf = kmalloc(len + 1, GFP_KERNEL);
166
+ buf = match_strdup(s);
172167 if (!buf)
173168 return -ENOMEM;
174
- memcpy(buf, s->from, len);
175
- buf[len] = '\0';
176169
177170 ret = kstrtoull(buf, base, &val);
178171 if (!ret)
....@@ -327,10 +320,6 @@
327320 */
328321 char *match_strdup(const substring_t *s)
329322 {
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);
335324 }
336325 EXPORT_SYMBOL(match_strdup);