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

9p: fix option parsing

Options pointer is being moved before calling kfree() which seems
to cause problems.  This uses a separate pointer to track and free
original allocation.
Signed-off-by: default avatarVenkateswararao Jujjuri <jvrao@us.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>w
parent 7a4439c4
...@@ -84,7 +84,7 @@ static const match_table_t tokens = { ...@@ -84,7 +84,7 @@ static const match_table_t tokens = {
static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts) static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)
{ {
char *options; char *options, *tmp_options;
substring_t args[MAX_OPT_ARGS]; substring_t args[MAX_OPT_ARGS];
char *p; char *p;
int option = 0; int option = 0;
...@@ -102,9 +102,10 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts) ...@@ -102,9 +102,10 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)
if (!opts) if (!opts)
return 0; return 0;
options = kstrdup(opts, GFP_KERNEL); tmp_options = kstrdup(opts, GFP_KERNEL);
if (!options) if (!tmp_options)
goto fail_option_alloc; goto fail_option_alloc;
options = tmp_options;
while ((p = strsep(&options, ",")) != NULL) { while ((p = strsep(&options, ",")) != NULL) {
int token; int token;
...@@ -194,7 +195,8 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts) ...@@ -194,7 +195,8 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)
continue; continue;
} }
} }
kfree(options);
kfree(tmp_options);
return ret; return ret;
fail_option_alloc: fail_option_alloc:
......
...@@ -69,7 +69,7 @@ p9_client_rpc(struct p9_client *c, int8_t type, const char *fmt, ...); ...@@ -69,7 +69,7 @@ p9_client_rpc(struct p9_client *c, int8_t type, const char *fmt, ...);
static int parse_opts(char *opts, struct p9_client *clnt) static int parse_opts(char *opts, struct p9_client *clnt)
{ {
char *options; char *options, *tmp_options;
char *p; char *p;
substring_t args[MAX_OPT_ARGS]; substring_t args[MAX_OPT_ARGS];
int option; int option;
...@@ -81,12 +81,13 @@ static int parse_opts(char *opts, struct p9_client *clnt) ...@@ -81,12 +81,13 @@ static int parse_opts(char *opts, struct p9_client *clnt)
if (!opts) if (!opts)
return 0; return 0;
options = kstrdup(opts, GFP_KERNEL); tmp_options = kstrdup(opts, GFP_KERNEL);
if (!options) { if (!tmp_options) {
P9_DPRINTK(P9_DEBUG_ERROR, P9_DPRINTK(P9_DEBUG_ERROR,
"failed to allocate copy of option string\n"); "failed to allocate copy of option string\n");
return -ENOMEM; return -ENOMEM;
} }
options = tmp_options;
while ((p = strsep(&options, ",")) != NULL) { while ((p = strsep(&options, ",")) != NULL) {
int token; int token;
...@@ -125,7 +126,7 @@ static int parse_opts(char *opts, struct p9_client *clnt) ...@@ -125,7 +126,7 @@ static int parse_opts(char *opts, struct p9_client *clnt)
} }
free_and_return: free_and_return:
kfree(options); kfree(tmp_options);
return ret; return ret;
} }
......
...@@ -714,7 +714,7 @@ static int parse_opts(char *params, struct p9_fd_opts *opts) ...@@ -714,7 +714,7 @@ static int parse_opts(char *params, struct p9_fd_opts *opts)
char *p; char *p;
substring_t args[MAX_OPT_ARGS]; substring_t args[MAX_OPT_ARGS];
int option; int option;
char *options; char *options, *tmp_options;
int ret; int ret;
opts->port = P9_PORT; opts->port = P9_PORT;
...@@ -724,12 +724,13 @@ static int parse_opts(char *params, struct p9_fd_opts *opts) ...@@ -724,12 +724,13 @@ static int parse_opts(char *params, struct p9_fd_opts *opts)
if (!params) if (!params)
return 0; return 0;
options = kstrdup(params, GFP_KERNEL); tmp_options = kstrdup(params, GFP_KERNEL);
if (!options) { if (!tmp_options) {
P9_DPRINTK(P9_DEBUG_ERROR, P9_DPRINTK(P9_DEBUG_ERROR,
"failed to allocate copy of option string\n"); "failed to allocate copy of option string\n");
return -ENOMEM; return -ENOMEM;
} }
options = tmp_options;
while ((p = strsep(&options, ",")) != NULL) { while ((p = strsep(&options, ",")) != NULL) {
int token; int token;
...@@ -760,7 +761,8 @@ static int parse_opts(char *params, struct p9_fd_opts *opts) ...@@ -760,7 +761,8 @@ static int parse_opts(char *params, struct p9_fd_opts *opts)
continue; continue;
} }
} }
kfree(options);
kfree(tmp_options);
return 0; return 0;
} }
......
...@@ -166,7 +166,7 @@ static int parse_opts(char *params, struct p9_rdma_opts *opts) ...@@ -166,7 +166,7 @@ static int parse_opts(char *params, struct p9_rdma_opts *opts)
char *p; char *p;
substring_t args[MAX_OPT_ARGS]; substring_t args[MAX_OPT_ARGS];
int option; int option;
char *options; char *options, *tmp_options;
int ret; int ret;
opts->port = P9_PORT; opts->port = P9_PORT;
...@@ -177,12 +177,13 @@ static int parse_opts(char *params, struct p9_rdma_opts *opts) ...@@ -177,12 +177,13 @@ static int parse_opts(char *params, struct p9_rdma_opts *opts)
if (!params) if (!params)
return 0; return 0;
options = kstrdup(params, GFP_KERNEL); tmp_options = kstrdup(params, GFP_KERNEL);
if (!options) { if (!tmp_options) {
P9_DPRINTK(P9_DEBUG_ERROR, P9_DPRINTK(P9_DEBUG_ERROR,
"failed to allocate copy of option string\n"); "failed to allocate copy of option string\n");
return -ENOMEM; return -ENOMEM;
} }
options = tmp_options;
while ((p = strsep(&options, ",")) != NULL) { while ((p = strsep(&options, ",")) != NULL) {
int token; int token;
...@@ -216,7 +217,7 @@ static int parse_opts(char *params, struct p9_rdma_opts *opts) ...@@ -216,7 +217,7 @@ static int parse_opts(char *params, struct p9_rdma_opts *opts)
} }
/* RQ must be at least as large as the SQ */ /* RQ must be at least as large as the SQ */
opts->rq_depth = max(opts->rq_depth, opts->sq_depth); opts->rq_depth = max(opts->rq_depth, opts->sq_depth);
kfree(options); kfree(tmp_options);
return 0; return 0;
} }
......
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