From: Markus Elfring <Markus.Elfring@web.de>
To: kernel-janitors@vger.kernel.org,
Phillip Lougher <phillip@squashfs.org.uk>
Cc: cocci@inria.fr, LKML <linux-kernel@vger.kernel.org>,
Minchan Kim <minchan@kernel.org>
Subject: [cocci] [PATCH] squashfs: Improve exception handling in squashfs_decompressor_create()
Date: Thu, 30 Mar 2023 18:18:30 +0200 [thread overview]
Message-ID: <f1712777-97ff-d89c-0bdd-d72faed9a7f1@web.de> (raw)
In-Reply-To: <6cbcf640-55e5-2f11-4a09-716fe681c0d2@web.de>
Date: Thu, 30 Mar 2023 18:03:47 +0200
The label “out” was used to jump to a kfree() call despite of
the detail in the implementation of the function
“squashfs_decompressor_create” that it was determined already
that a corresponding variable contained a null pointer because of
a failed memory allocation.
Thus perform the following adjustments:
1. Return directly after a call of the function “kzalloc” failed
at the beginning.
2. Use more appropriate labels instead.
3. Omit extra initialisations (for the variables “decomp_strm” and “err”)
which became unnecessary with this refactoring.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
fs/squashfs/decompressor_multi.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/fs/squashfs/decompressor_multi.c b/fs/squashfs/decompressor_multi.c
index 416c53eedbd1..0a054ba4c541 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,22 +81,25 @@ 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);
if (IS_ERR(decomp_strm->stream)) {
err = PTR_ERR(decomp_strm->stream);
- goto out;
+ goto free_decomp_stream;
}
list_add(&decomp_strm->list, &stream->strm_list);
stream->avail_decomp = 1;
return stream;
-out:
+free_decomp_stream:
kfree(decomp_strm);
+free_stream:
kfree(stream);
return ERR_PTR(err);
}
--
2.40.0
next prev parent reply other threads:[~2023-03-30 16:18 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-28 15:55 [cocci] Reconsidering kfree() calls for null pointers (with SmPL) Markus Elfring
2023-03-28 16:05 ` Vlastimil Babka
2023-03-29 6:18 ` Markus Elfring
2023-03-29 7:25 ` Vlastimil Babka
2023-03-28 17:13 ` [cocci] [PATCH 0/2] ARM: Adjustments for init_atags_procfs() Markus Elfring
2023-03-28 17:15 ` [cocci] [PATCH 1/2] ARM: Delete an error message for a failed memory allocation in init_atags_procfs() Markus Elfring
2023-03-28 17:17 ` [cocci] [PATCH 2/2] ARM: Return directly after a failed kmalloc() " Markus Elfring
2024-01-10 11:48 ` [cocci] [PATCH 0/2] ARM: Adjustments for init_atags_procfs() Markus Elfring
2024-01-10 11:52 ` [cocci] [0/2] " Markus Elfring
[not found] ` <ZZ6MZl14bcIaCaQn@shell.armlinux.org.uk>
2024-01-10 12:44 ` Markus Elfring
[not found] ` <ZZ6R6KSQo9ph3ARZ@shell.armlinux.org.uk>
2024-01-10 12:52 ` Markus Elfring
[not found] ` <ZZ6gq5sOFf33GhM7@shell.armlinux.org.uk>
2024-01-10 14:00 ` Markus Elfring
[not found] ` <vltzbtbcuzrfgjoeg5oovdyoe34fnhte25uhb3gln56pzvmqzb@5u7u7cwgzzen>
2024-01-10 13:46 ` Markus Elfring
2023-03-28 18:45 ` [cocci] [PATCH 0/2] perf/x86/intel/pt: Adjustments for pt_pmu_hw_init() Markus Elfring
2023-03-28 18:50 ` [cocci] [PATCH 1/2] perf/x86/intel/pt: Use -ENOMEM directly for a return statement in pt_pmu_hw_init() Markus Elfring
2023-03-28 18:52 ` [cocci] [PATCH 2/2] perf/x86/intel/pt: Return directly after a failed kzalloc() " Markus Elfring
2024-01-10 11:45 ` [cocci] [PATCH 0/2] perf/x86/intel/pt: Adjustments for pt_pmu_hw_init() Markus Elfring
2023-03-29 10:12 ` [cocci] [PATCH] apparmor: Return directly after a failed kzalloc() in two functions Markus Elfring
2023-03-29 13:36 ` [cocci] [PATCH 0/3] lru_cache: Adjustments for lc_create() Markus Elfring
2023-03-29 13:40 ` [cocci] [PATCH 1/3] lru_cache: Return directly after a failed kzalloc() in lc_create() Markus Elfring
2023-03-29 13:42 ` [cocci] [PATCH 2/3] lru_cache: Improve two size determinations " Markus Elfring
2023-03-29 13:44 ` [cocci] [PATCH 3/3] lru_cache: Improve exception handling " Markus Elfring
2024-01-10 11:40 ` [cocci] [PATCH 0/3] lru_cache: Adjustments for lc_create() Markus Elfring
2023-03-29 15:46 ` [cocci] [PATCH] io_uring: Fix exception handling in io_ring_ctx_alloc() Markus Elfring
2024-01-10 11:23 ` [cocci] " Markus Elfring
2024-01-10 16:55 ` [cocci] [PATCH] " Gabriel Krisman Bertazi
2023-03-30 8:50 ` [cocci] [PATCH 0/4] overlayfs: Adjustments for ovl_fill_super() Markus Elfring
2023-03-30 8:55 ` [cocci] [PATCH 1/4] overlayfs: Return directly for two checks in ovl_fill_super() Markus Elfring
2023-03-30 8:57 ` [cocci] [PATCH 2/4] overlayfs: Improve two size determinations " Markus Elfring
2023-03-30 9:00 ` [cocci] [PATCH 3/4] overlayfs: Improve exception handling " Markus Elfring
2023-03-30 9:02 ` [cocci] [PATCH 4/4] overlayfs: Move some assignments for the variable “err” " Markus Elfring
2024-01-10 12:24 ` [cocci] [PATCH 0/4] overlayfs: Adjustments for ovl_fill_super() Markus Elfring
[not found] ` <CAOQ4uxiRaTQyT1nxeRD7B89=VuA+KKEqi01LL1kqfJ17-qKKpw@mail.gmail.com>
2024-01-10 13:01 ` [cocci] [0/4] " Markus Elfring
[not found] ` <CAOQ4uxjsuYy8BzgaHXaNa-S0+HZ_P-Fb1UEgOkbrdxQPz0Y6rQ@mail.gmail.com>
2024-01-10 13:33 ` Markus Elfring
2023-03-30 16:18 ` Markus Elfring [this message]
2024-01-05 20:32 ` [cocci] [PATCH] squashfs: Improve exception handling in squashfs_decompressor_create() 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=f1712777-97ff-d89c-0bdd-d72faed9a7f1@web.de \
--to=markus.elfring@web.de \
--cc=cocci@inria.fr \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=minchan@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;
as well as URLs for NNTP newsgroup(s).