Skip to content

Commit a474d84

Browse files
guoweikangakpm00
authored andcommitted
mm/shmem: refactor to reuse vfs_parse_monolithic_sep for option parsing
shmem_parse_options() is refactored to use vfs_parse_monolithic_sep() with a custom separator function, shmem_next_opt(). This eliminates redundant logic for parsing comma-separated options and ensures consistency with other kernel code that uses the same interface. The vfs_parse_monolithic_sep() helper was introduced in commit e001d14 ("fs: factor out vfs_parse_monolithic_sep() helper"). Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Guo Weikang <[email protected]> Cc: Amir Goldstein <[email protected]> Cc: Hugh Dickins <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 19b65ff commit a474d84

File tree

1 file changed

+27
-38
lines changed

1 file changed

+27
-38
lines changed

mm/shmem.c

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4647,48 +4647,37 @@ static int shmem_parse_one(struct fs_context *fc, struct fs_parameter *param)
46474647
return invalfc(fc, "Bad value for '%s'", param->key);
46484648
}
46494649

4650-
static int shmem_parse_options(struct fs_context *fc, void *data)
4650+
static char *shmem_next_opt(char **s)
46514651
{
4652-
char *options = data;
4652+
char *sbegin = *s;
4653+
char *p;
46534654

4654-
if (options) {
4655-
int err = security_sb_eat_lsm_opts(options, &fc->security);
4656-
if (err)
4657-
return err;
4658-
}
4655+
if (sbegin == NULL)
4656+
return NULL;
46594657

4660-
while (options != NULL) {
4661-
char *this_char = options;
4662-
for (;;) {
4663-
/*
4664-
* NUL-terminate this option: unfortunately,
4665-
* mount options form a comma-separated list,
4666-
* but mpol's nodelist may also contain commas.
4667-
*/
4668-
options = strchr(options, ',');
4669-
if (options == NULL)
4670-
break;
4671-
options++;
4672-
if (!isdigit(*options)) {
4673-
options[-1] = '\0';
4674-
break;
4675-
}
4676-
}
4677-
if (*this_char) {
4678-
char *value = strchr(this_char, '=');
4679-
size_t len = 0;
4680-
int err;
4681-
4682-
if (value) {
4683-
*value++ = '\0';
4684-
len = strlen(value);
4685-
}
4686-
err = vfs_parse_fs_string(fc, this_char, value, len);
4687-
if (err < 0)
4688-
return err;
4658+
/*
4659+
* NUL-terminate this option: unfortunately,
4660+
* mount options form a comma-separated list,
4661+
* but mpol's nodelist may also contain commas.
4662+
*/
4663+
for (;;) {
4664+
p = strchr(*s, ',');
4665+
if (p == NULL)
4666+
break;
4667+
*s = p + 1;
4668+
if (!isdigit(*(p+1))) {
4669+
*p = '\0';
4670+
return sbegin;
46894671
}
46904672
}
4691-
return 0;
4673+
4674+
*s = NULL;
4675+
return sbegin;
4676+
}
4677+
4678+
static int shmem_parse_monolithic(struct fs_context *fc, void *data)
4679+
{
4680+
return vfs_parse_monolithic_sep(fc, data, shmem_next_opt);
46924681
}
46934682

46944683
/*
@@ -5038,7 +5027,7 @@ static const struct fs_context_operations shmem_fs_context_ops = {
50385027
.free = shmem_free_fc,
50395028
.get_tree = shmem_get_tree,
50405029
#ifdef CONFIG_TMPFS
5041-
.parse_monolithic = shmem_parse_options,
5030+
.parse_monolithic = shmem_parse_monolithic,
50425031
.parse_param = shmem_parse_one,
50435032
.reconfigure = shmem_reconfigure,
50445033
#endif

0 commit comments

Comments
 (0)