| .. | .. |
|---|
| 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> |
|---|
| .. | .. |
|---|
| 131 | 129 | char *buf; |
|---|
| 132 | 130 | int ret; |
|---|
| 133 | 131 | long val; |
|---|
| 134 | | - size_t len = s->to - s->from; |
|---|
| 135 | 132 | |
|---|
| 136 | | - buf = kmalloc(len + 1, GFP_KERNEL); |
|---|
| 133 | + buf = match_strdup(s); |
|---|
| 137 | 134 | if (!buf) |
|---|
| 138 | 135 | return -ENOMEM; |
|---|
| 139 | | - memcpy(buf, s->from, len); |
|---|
| 140 | | - buf[len] = '\0'; |
|---|
| 141 | 136 | |
|---|
| 142 | 137 | ret = 0; |
|---|
| 143 | 138 | val = simple_strtol(buf, &endp, base); |
|---|
| .. | .. |
|---|
| 166 | 161 | char *buf; |
|---|
| 167 | 162 | int ret; |
|---|
| 168 | 163 | u64 val; |
|---|
| 169 | | - size_t len = s->to - s->from; |
|---|
| 170 | 164 | |
|---|
| 171 | | - buf = kmalloc(len + 1, GFP_KERNEL); |
|---|
| 165 | + buf = match_strdup(s); |
|---|
| 172 | 166 | if (!buf) |
|---|
| 173 | 167 | return -ENOMEM; |
|---|
| 174 | | - memcpy(buf, s->from, len); |
|---|
| 175 | | - buf[len] = '\0'; |
|---|
| 176 | 168 | |
|---|
| 177 | 169 | ret = kstrtoull(buf, base, &val); |
|---|
| 178 | 170 | if (!ret) |
|---|
| .. | .. |
|---|
| 327 | 319 | */ |
|---|
| 328 | 320 | char *match_strdup(const substring_t *s) |
|---|
| 329 | 321 | { |
|---|
| 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); |
|---|
| 335 | 323 | } |
|---|
| 336 | 324 | EXPORT_SYMBOL(match_strdup); |
|---|