Commit bf2d29c6 authored by Eric Van Hensbergen's avatar Eric Van Hensbergen

9p: fix memory leak in v9fs_parse_options()

If match_strdup() fail this function exits without freeing the options string.
Signed-off-by: default avatarVenkateswararao Jujjuri <jvrao@us.ibm.com>
Sigend-off-by: default avatarEric Van Hensbergen <ericvh@gmail.com>
parent fb786100
...@@ -103,8 +103,10 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts) ...@@ -103,8 +103,10 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)
return 0; return 0;
tmp_options = kstrdup(opts, GFP_KERNEL); tmp_options = kstrdup(opts, GFP_KERNEL);
if (!tmp_options) if (!tmp_options) {
ret = -ENOMEM;
goto fail_option_alloc; goto fail_option_alloc;
}
options = tmp_options; options = tmp_options;
while ((p = strsep(&options, ",")) != NULL) { while ((p = strsep(&options, ",")) != NULL) {
...@@ -160,8 +162,12 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts) ...@@ -160,8 +162,12 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)
break; break;
case Opt_cache: case Opt_cache:
s = match_strdup(&args[0]); s = match_strdup(&args[0]);
if (!s) if (!s) {
goto fail_option_alloc; ret = -ENOMEM;
P9_DPRINTK(P9_DEBUG_ERROR,
"problem allocating copy of cache arg\n");
goto free_and_return;
}
if (strcmp(s, "loose") == 0) if (strcmp(s, "loose") == 0)
v9ses->cache = CACHE_LOOSE; v9ses->cache = CACHE_LOOSE;
...@@ -174,8 +180,12 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts) ...@@ -174,8 +180,12 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)
case Opt_access: case Opt_access:
s = match_strdup(&args[0]); s = match_strdup(&args[0]);
if (!s) if (!s) {
goto fail_option_alloc; ret = -ENOMEM;
P9_DPRINTK(P9_DEBUG_ERROR,
"problem allocating copy of access arg\n");
goto free_and_return;
}
v9ses->flags &= ~V9FS_ACCESS_MASK; v9ses->flags &= ~V9FS_ACCESS_MASK;
if (strcmp(s, "user") == 0) if (strcmp(s, "user") == 0)
...@@ -196,13 +206,10 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts) ...@@ -196,13 +206,10 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)
} }
} }
free_and_return:
kfree(tmp_options); kfree(tmp_options);
return ret;
fail_option_alloc: fail_option_alloc:
P9_DPRINTK(P9_DEBUG_ERROR, return ret;
"failed to allocate copy of option argument\n");
return -ENOMEM;
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment