From: Markus Elfring <Markus.Elfring@web.de>
To: Phillip Lougher <phillip@squashfs.org.uk>,
kernel-janitors@vger.kernel.org
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] squashfs: Improve error handling in squashfs_decompressor_create()
Date: Sat, 30 Dec 2023 10:55:14 +0100 [thread overview]
Message-ID: <49472d26-29e6-443f-b0f5-21967a67dd4a@web.de> (raw)
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 29 Dec 2023 21:30:26 +0100
The kfree() function was called in two cases by
the squashfs_decompressor_create() 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 “kzalloc” failed
at the beginning.
* Use another label.
* Move an error code assignment into an if branch.
* Delete an initialisation (for the variable “decomp_strm”)
which became unnecessary with this refactoring.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
fs/squashfs/decompressor_multi.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/fs/squashfs/decompressor_multi.c b/fs/squashfs/decompressor_multi.c
index 416c53eedbd1..81fd15d5163c 100644
--- a/fs/squashfs/decompressor_multi.c
+++ b/fs/squashfs/decompressor_multi.c
@@ -62,12 +62,12 @@ static void *squashfs_decompressor_create(struct squashfs_sb_info *msblk,
void *comp_opts)
{
struct squashfs_stream *stream;
- struct decomp_stream *decomp_strm = NULL;
- int err = -ENOMEM;
+ struct decomp_stream *decomp_strm;
+ int err;
stream = kzalloc(sizeof(*stream), GFP_KERNEL);
if (!stream)
- goto out;
+ return ERR_PTR(-ENOMEM);
stream->comp_opts = comp_opts;
mutex_init(&stream->mutex);
@@ -81,8 +81,10 @@ static void *squashfs_decompressor_create(struct squashfs_sb_info *msblk,
* file system works.
*/
decomp_strm = kmalloc(sizeof(*decomp_strm), GFP_KERNEL);
- if (!decomp_strm)
- goto out;
+ if (!decomp_strm) {
+ err = -ENOMEM;
+ goto free_stream;
+ }
decomp_strm->stream = msblk->decompressor->init(msblk,
stream->comp_opts);
@@ -97,6 +99,7 @@ static void *squashfs_decompressor_create(struct squashfs_sb_info *msblk,
out:
kfree(decomp_strm);
+free_stream:
kfree(stream);
return ERR_PTR(err);
}
--
2.43.0
next reply other threads:[~2023-12-30 9:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-30 9:55 Markus Elfring [this message]
2024-01-07 18:45 ` Phillip Lougher
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=49472d26-29e6-443f-b0f5-21967a67dd4a@web.de \
--to=markus.elfring@web.de \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=phillip@squashfs.org.uk \
/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
all inboxes | Powered by JetHome®