linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: linux-mm@kvack.org, kernel-janitors@vger.kernel.org,
	Muchun Song <muchun.song@linux.dev>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH 2/2] hugetlbfs: Improve exception handling in hugetlbfs_fill_super()
Date: Fri, 29 Dec 2023 12:40:12 +0100	[thread overview]
Message-ID: <b109b7dc-3972-4b2e-ae4c-89bf8eecf8f2@web.de> (raw)
In-Reply-To: <9ce3f553-24bc-4ecd-ac5e-7ba27caeff57@web.de>

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 29 Dec 2023 11:46:32 +0100

The kfree() function was called in one case by
the hugetlbfs_fill_super() function during error handling
even if the passed variable contained a null pointer.
This issue was detected by using the Coccinelle software.

Thus adjust jump targets.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 fs/hugetlbfs/inode.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index 24401a5046dd..5687ec574dc4 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -1483,7 +1483,7 @@ hugetlbfs_fill_super(struct super_block *sb, struct fs_context *fc)
 						     ctx->max_hpages,
 						     ctx->min_hpages);
 		if (!sbinfo->spool)
-			goto out_free;
+			goto free_sbinfo;
 	}
 	sb->s_maxbytes = MAX_LFS_FILESIZE;
 	sb->s_blocksize = huge_page_size(ctx->hstate);
@@ -1499,10 +1499,12 @@ hugetlbfs_fill_super(struct super_block *sb, struct fs_context *fc)
 	sb->s_stack_depth = FILESYSTEM_MAX_STACK_DEPTH;
 	sb->s_root = d_make_root(hugetlbfs_get_root(sb, ctx));
 	if (!sb->s_root)
-		goto out_free;
+		goto free_spool;
 	return 0;
-out_free:
+
+free_spool:
 	kfree(sbinfo->spool);
+free_sbinfo:
 	kfree(sbinfo);
 	return -ENOMEM;
 }
--
2.43.0



  parent reply	other threads:[~2023-12-29 11:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-29 11:36 [PATCH 0/2] hugetlbfs: Adjustments for two function implementations Markus Elfring
2023-12-29 11:37 ` [PATCH 1/2] hugetlbfs: Improve a size determination in two functions Markus Elfring
2024-01-02  2:57   ` Muchun Song
2023-12-29 11:40 ` Markus Elfring [this message]
2023-12-29 14:52   ` [PATCH 2/2] hugetlbfs: Improve exception handling in hugetlbfs_fill_super() Matthew Wilcox
2023-12-30  6:45     ` 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=b109b7dc-3972-4b2e-ae4c-89bf8eecf8f2@web.de \
    --to=markus.elfring@web.de \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=muchun.song@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