Skip to content

Commit

Permalink
9p: check memory allocation result for cachetag
Browse files Browse the repository at this point in the history
Check memory allocation result for cachetag in mount option parsing and
fix potential memory leak in the error case.

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Chengguang Xu <[email protected]>
Reviewed-by: Andrew Morton <[email protected]>
Cc: Eric Van Hensbergen <[email protected]>
Cc: Ron Minnich <[email protected]>
Cc: Latchesar Ionkov <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Chengguang Xu authored and torvalds committed Apr 6, 2018
1 parent ac89b2e commit a25c365
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions fs/9p/v9fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,10 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)
#ifdef CONFIG_9P_FSCACHE
kfree(v9ses->cachetag);
v9ses->cachetag = match_strdup(&args[0]);
if (!v9ses->cachetag) {
ret = -ENOMEM;
goto free_and_return;
}
#endif
break;
case Opt_cache:
Expand Down Expand Up @@ -471,6 +475,9 @@ struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
return fid;

err_clnt:
#ifdef CONFIG_9P_FSCACHE
kfree(v9ses->cachetag);
#endif
p9_client_destroy(v9ses->clnt);
err_names:
kfree(v9ses->uname);
Expand Down

0 comments on commit a25c365

Please sign in to comment.