From: Markus Elfring <Markus.Elfring@web.de>
To: v9fs@lists.linux.dev, kernel-janitors@vger.kernel.org,
"Christian Schönebeck" <linux_oss@crudebyte.com>,
"Dominique Martinet" <asmadeus@codewreck.org>,
"Eric Van Hensbergen" <ericvh@kernel.org>,
"Latchesar Ionkov" <lucho@ionkov.net>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] fs/9p: Improve exception handling in v9fs_session_init()
Date: Thu, 28 Dec 2023 21:01:49 +0100 [thread overview]
Message-ID: <7203d3fc-f1e4-4fb1-8dd3-068b0ec6c752@web.de> (raw)
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 28 Dec 2023 20:47:18 +0100
The kfree() function was called in up to two cases by
the v9fs_session_init() function during error handling
even if the passed variable contained a null pointer.
This issue was detected by using the Coccinelle software.
* Thus return directly after a call of the function “kstrdup” failed
at the beginning.
* Adjust jump targets.
* Delete an initialisation (for the variable “rc”)
which became unnecessary with this refactoring.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
fs/9p/v9fs.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/fs/9p/v9fs.c b/fs/9p/v9fs.c
index 61dbe52bb3a3..874a36303b72 100644
--- a/fs/9p/v9fs.c
+++ b/fs/9p/v9fs.c
@@ -392,15 +392,18 @@ struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
const char *dev_name, char *data)
{
struct p9_fid *fid;
- int rc = -ENOMEM;
+ int rc;
v9ses->uname = kstrdup(V9FS_DEFUSER, GFP_KERNEL);
if (!v9ses->uname)
- goto err_names;
+ return ERR_PTR(-ENOMEM);
v9ses->aname = kstrdup(V9FS_DEFANAME, GFP_KERNEL);
- if (!v9ses->aname)
- goto err_names;
+ if (!v9ses->aname) {
+ rc = -ENOMEM;
+ goto free_uname;
+ }
+
init_rwsem(&v9ses->rename_sem);
v9ses->uid = INVALID_UID;
@@ -489,8 +492,9 @@ struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
#endif
p9_client_destroy(v9ses->clnt);
err_names:
- kfree(v9ses->uname);
kfree(v9ses->aname);
+free_uname:
+ kfree(v9ses->uname);
return ERR_PTR(rc);
}
--
2.43.0
next reply other threads:[~2023-12-28 20:02 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-28 20:01 Markus Elfring [this message]
2024-01-08 11:09 ` [PATCH] fs/9p: Improve exception handling in v9fs_session_init() Dominique Martinet
2024-01-08 12:15 ` Markus Elfring
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7203d3fc-f1e4-4fb1-8dd3-068b0ec6c752@web.de \
--to=markus.elfring@web.de \
--cc=asmadeus@codewreck.org \
--cc=ericvh@kernel.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux_oss@crudebyte.com \
--cc=lucho@ionkov.net \
--cc=v9fs@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).