From: Markus Elfring <Markus.Elfring@web.de>
To: linux-fsdevel@vger.kernel.org, kernel-janitors@vger.kernel.org,
Miklos Szeredi <miklos@szeredi.hu>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] fuse: Improve error handling in two functions
Date: Thu, 28 Dec 2023 22:02:13 +0100 [thread overview]
Message-ID: <70ebc121-4332-4c64-9a20-29837758aa19@web.de> (raw)
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 28 Dec 2023 21:57:00 +0100
The kfree() function was called in two cases during error handling
even if the passed variable contained a null pointer.
This issue was detected by using the Coccinelle software.
* Thus use additional labels.
* Move error code assignments into if branches.
* Delete initialisations (for the variable “err”)
which became unnecessary with this refactoring.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
fs/fuse/dev.c | 44 ++++++++++++++++++++++++++------------------
1 file changed, 26 insertions(+), 18 deletions(-)
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 1a8f82f478cb..8f2975b1aed3 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -1468,29 +1468,30 @@ static int fuse_notify_inval_entry(struct fuse_conn *fc, unsigned int size,
struct fuse_copy_state *cs)
{
struct fuse_notify_inval_entry_out outarg;
- int err = -ENOMEM;
+ int err;
char *buf;
struct qstr name;
buf = kzalloc(FUSE_NAME_MAX + 1, GFP_KERNEL);
- if (!buf)
- goto err;
+ if (!buf) {
+ err = -ENOMEM;
+ goto finish_copy;
+ }
- err = -EINVAL;
if (size < sizeof(outarg))
- goto err;
+ goto e_inval;
err = fuse_copy_one(cs, &outarg, sizeof(outarg));
if (err)
goto err;
- err = -ENAMETOOLONG;
- if (outarg.namelen > FUSE_NAME_MAX)
+ if (outarg.namelen > FUSE_NAME_MAX) {
+ err = -ENAMETOOLONG;
goto err;
+ }
- err = -EINVAL;
if (size != sizeof(outarg) + outarg.namelen + 1)
- goto err;
+ goto e_inval;
name.name = buf;
name.len = outarg.namelen;
@@ -1506,8 +1507,11 @@ static int fuse_notify_inval_entry(struct fuse_conn *fc, unsigned int size,
kfree(buf);
return err;
+e_inval:
+ err = -EINVAL;
err:
kfree(buf);
+finish_copy:
fuse_copy_finish(cs);
return err;
}
@@ -1516,29 +1520,30 @@ static int fuse_notify_delete(struct fuse_conn *fc, unsigned int size,
struct fuse_copy_state *cs)
{
struct fuse_notify_delete_out outarg;
- int err = -ENOMEM;
+ int err;
char *buf;
struct qstr name;
buf = kzalloc(FUSE_NAME_MAX + 1, GFP_KERNEL);
- if (!buf)
- goto err;
+ if (!buf) {
+ err = -ENOMEM;
+ goto finish_copy;
+ }
- err = -EINVAL;
if (size < sizeof(outarg))
- goto err;
+ goto e_inval;
err = fuse_copy_one(cs, &outarg, sizeof(outarg));
if (err)
goto err;
- err = -ENAMETOOLONG;
- if (outarg.namelen > FUSE_NAME_MAX)
+ if (outarg.namelen > FUSE_NAME_MAX) {
+ err = -ENAMETOOLONG;
goto err;
+ }
- err = -EINVAL;
if (size != sizeof(outarg) + outarg.namelen + 1)
- goto err;
+ goto e_inval;
name.name = buf;
name.len = outarg.namelen;
@@ -1554,8 +1559,11 @@ static int fuse_notify_delete(struct fuse_conn *fc, unsigned int size,
kfree(buf);
return err;
+e_inval:
+ err = -EINVAL;
err:
kfree(buf);
+finish_copy:
fuse_copy_finish(cs);
return err;
}
--
2.43.0
reply other threads:[~2023-12-28 21:02 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=70ebc121-4332-4c64-9a20-29837758aa19@web.de \
--to=markus.elfring@web.de \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=miklos@szeredi.hu \
/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).