f2fs: use strcmp() in parse_options()

Remove the pointless string length checks.  Just use strcmp().

Signed-off-by: Eric Biggers <ebiggers@google.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
Eric Biggers 2020-05-01 16:35:23 -07:00 committed by Jaegeuk Kim
parent d29fbcdb05
commit 3c57f75182
1 changed files with 16 additions and 28 deletions

View File

@ -427,11 +427,11 @@ static int parse_options(struct super_block *sb, char *options)
if (!name) if (!name)
return -ENOMEM; return -ENOMEM;
if (strlen(name) == 2 && !strncmp(name, "on", 2)) { if (!strcmp(name, "on")) {
F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_ON; F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_ON;
} else if (strlen(name) == 3 && !strncmp(name, "off", 3)) { } else if (!strcmp(name, "off")) {
F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_OFF; F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_OFF;
} else if (strlen(name) == 4 && !strncmp(name, "sync", 4)) { } else if (!strcmp(name, "sync")) {
F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_SYNC; F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_SYNC;
} else { } else {
kvfree(name); kvfree(name);
@ -591,16 +591,14 @@ static int parse_options(struct super_block *sb, char *options)
if (!name) if (!name)
return -ENOMEM; return -ENOMEM;
if (strlen(name) == 8 && if (!strcmp(name, "adaptive")) {
!strncmp(name, "adaptive", 8)) {
if (f2fs_sb_has_blkzoned(sbi)) { if (f2fs_sb_has_blkzoned(sbi)) {
f2fs_warn(sbi, "adaptive mode is not allowed with zoned block device feature"); f2fs_warn(sbi, "adaptive mode is not allowed with zoned block device feature");
kvfree(name); kvfree(name);
return -EINVAL; return -EINVAL;
} }
F2FS_OPTION(sbi).fs_mode = FS_MODE_ADAPTIVE; F2FS_OPTION(sbi).fs_mode = FS_MODE_ADAPTIVE;
} else if (strlen(name) == 3 && } else if (!strcmp(name, "lfs")) {
!strncmp(name, "lfs", 3)) {
F2FS_OPTION(sbi).fs_mode = FS_MODE_LFS; F2FS_OPTION(sbi).fs_mode = FS_MODE_LFS;
} else { } else {
kvfree(name); kvfree(name);
@ -725,14 +723,11 @@ static int parse_options(struct super_block *sb, char *options)
name = match_strdup(&args[0]); name = match_strdup(&args[0]);
if (!name) if (!name)
return -ENOMEM; return -ENOMEM;
if (strlen(name) == 10 && if (!strcmp(name, "user-based")) {
!strncmp(name, "user-based", 10)) {
F2FS_OPTION(sbi).whint_mode = WHINT_MODE_USER; F2FS_OPTION(sbi).whint_mode = WHINT_MODE_USER;
} else if (strlen(name) == 3 && } else if (!strcmp(name, "off")) {
!strncmp(name, "off", 3)) {
F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF; F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
} else if (strlen(name) == 8 && } else if (!strcmp(name, "fs-based")) {
!strncmp(name, "fs-based", 8)) {
F2FS_OPTION(sbi).whint_mode = WHINT_MODE_FS; F2FS_OPTION(sbi).whint_mode = WHINT_MODE_FS;
} else { } else {
kvfree(name); kvfree(name);
@ -745,11 +740,9 @@ static int parse_options(struct super_block *sb, char *options)
if (!name) if (!name)
return -ENOMEM; return -ENOMEM;
if (strlen(name) == 7 && if (!strcmp(name, "default")) {
!strncmp(name, "default", 7)) {
F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT; F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;
} else if (strlen(name) == 5 && } else if (!strcmp(name, "reuse")) {
!strncmp(name, "reuse", 5)) {
F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_REUSE; F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_REUSE;
} else { } else {
kvfree(name); kvfree(name);
@ -761,14 +754,11 @@ static int parse_options(struct super_block *sb, char *options)
name = match_strdup(&args[0]); name = match_strdup(&args[0]);
if (!name) if (!name)
return -ENOMEM; return -ENOMEM;
if (strlen(name) == 5 && if (!strcmp(name, "posix")) {
!strncmp(name, "posix", 5)) {
F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_POSIX; F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_POSIX;
} else if (strlen(name) == 6 && } else if (!strcmp(name, "strict")) {
!strncmp(name, "strict", 6)) {
F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_STRICT; F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_STRICT;
} else if (strlen(name) == 9 && } else if (!strcmp(name, "nobarrier")) {
!strncmp(name, "nobarrier", 9)) {
F2FS_OPTION(sbi).fsync_mode = F2FS_OPTION(sbi).fsync_mode =
FSYNC_MODE_NOBARRIER; FSYNC_MODE_NOBARRIER;
} else { } else {
@ -823,15 +813,13 @@ static int parse_options(struct super_block *sb, char *options)
name = match_strdup(&args[0]); name = match_strdup(&args[0]);
if (!name) if (!name)
return -ENOMEM; return -ENOMEM;
if (strlen(name) == 3 && !strcmp(name, "lzo")) { if (!strcmp(name, "lzo")) {
F2FS_OPTION(sbi).compress_algorithm = F2FS_OPTION(sbi).compress_algorithm =
COMPRESS_LZO; COMPRESS_LZO;
} else if (strlen(name) == 3 && } else if (!strcmp(name, "lz4")) {
!strcmp(name, "lz4")) {
F2FS_OPTION(sbi).compress_algorithm = F2FS_OPTION(sbi).compress_algorithm =
COMPRESS_LZ4; COMPRESS_LZ4;
} else if (strlen(name) == 4 && } else if (!strcmp(name, "zstd")) {
!strcmp(name, "zstd")) {
F2FS_OPTION(sbi).compress_algorithm = F2FS_OPTION(sbi).compress_algorithm =
COMPRESS_ZSTD; COMPRESS_ZSTD;
} else { } else {