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: Re: [PATCH] squashfs: Improve exception handling in squashfs_decompressor_create()
Date: Fri, 5 Jan 2024 21:32:04 +0100 [thread overview]
Message-ID: <71892e93-1545-4d04-9570-a15672f60e81@web.de> (raw)
In-Reply-To: <f1712777-97ff-d89c-0bdd-d72faed9a7f1@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);
> }
Is this patch still in review queues?
See also:
https://lore.kernel.org/cocci/f1712777-97ff-d89c-0bdd-d72faed9a7f1@web.de/
https://sympa.inria.fr/sympa/arc/cocci/2023-03/msg00120.html
Regards,
Markus
next prev parent reply other threads:[~2024-01-05 20:32 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <6cbcf640-55e5-2f11-4a09-716fe681c0d2@web.de>
2023-03-28 16:05 ` [cocci] Reconsidering kfree() calls for null pointers (with SmPL) Vlastimil Babka
[not found] ` <e4ba5b28-77b6-8013-ed76-e22e090496cb@web.de>
2023-03-29 7:25 ` Vlastimil Babka
[not found] ` <d33ebeca-0900-8c6c-ac44-f301daf24a5b@web.de>
2023-04-09 23:15 ` [PATCH] apparmor: Return directly after a failed kzalloc() in two functions John Johansen
[not found] ` <f1712777-97ff-d89c-0bdd-d72faed9a7f1@web.de>
2024-01-05 20:32 ` Markus Elfring [this message]
[not found] ` <33226beb-4fe2-3da5-5d69-a33e683dec57@web.de>
2024-01-10 11:40 ` [PATCH 0/3] lru_cache: Adjustments for lc_create() Markus Elfring
[not found] ` <d9c673f9-2c32-282f-f261-b4d5762409bb@web.de>
2024-01-10 11:45 ` [PATCH 0/2] perf/x86/intel/pt: Adjustments for pt_pmu_hw_init() Markus Elfring
[not found] ` <562a6f99-3f8e-9a77-e519-b668e24dced2@web.de>
2024-01-10 11:48 ` [PATCH 0/2] ARM: Adjustments for init_atags_procfs() Markus Elfring
2024-01-10 11:52 ` [0/2] " Markus Elfring
2024-01-10 12:24 ` Russell King (Oracle)
2024-01-10 12:44 ` Markus Elfring
2024-01-10 12:47 ` Russell King (Oracle)
2024-01-10 12:52 ` Markus Elfring
2024-01-10 13:50 ` Russell King (Oracle)
2024-01-10 14:00 ` Markus Elfring
2024-01-10 14:07 ` Russell King (Oracle)
2024-01-10 13:34 ` Christian Heusel
2024-01-10 13:46 ` Markus Elfring
[not found] ` <87b65f8e-abde-2aff-4da8-df6e0b464677@web.de>
2024-01-10 12:24 ` [PATCH 0/4] overlayfs: Adjustments for ovl_fill_super() Markus Elfring
2024-01-10 12:49 ` Amir Goldstein
2024-01-10 13:01 ` [0/4] " Markus Elfring
2024-01-10 13:19 ` Amir Goldstein
2024-01-10 13:33 ` Markus Elfring
2024-01-10 13:45 ` Amir Goldstein
[not found] ` <aa867594-e79d-6d08-a08e-8c9e952b4724@web.de>
2024-01-10 11:23 ` io_uring: Fix exception handling in io_ring_ctx_alloc() Markus Elfring
2024-01-10 16:55 ` [cocci] [PATCH] " Gabriel Krisman Bertazi
2024-01-10 20:45 ` [PATCH v2 0/2] io_uring: Adjustments for io_ring_ctx_alloc() Markus Elfring
2024-01-10 20:48 ` [PATCH v2 1/2] io_uring: Delete a redundant kfree() call in io_ring_ctx_alloc() Markus Elfring
2024-01-12 14:25 ` Gabriel Krisman Bertazi
2024-01-12 16:18 ` Jens Axboe
2024-01-12 17:15 ` Gabriel Krisman Bertazi
2024-01-12 17:50 ` [v2 " Markus Elfring
2024-01-10 20:50 ` [PATCH v2 2/2] io_uring: Improve exception handling " Markus Elfring
2024-01-11 13:23 ` Pavel Begunkov
2024-01-12 14:30 ` Gabriel Krisman Bertazi
2024-01-12 15:00 ` [v2 " 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=71892e93-1545-4d04-9570-a15672f60e81@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