linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Leesoo Ahn <lsahn@ooseel.net>
To: lsahn@ooseel.net
Cc: Leesoo Ahn <lsahn@wewakecorp.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [PATCH] mm/sparse: return right away if sparsemap_buf is null
Date: Fri, 26 Jul 2024 16:10:23 +0900	[thread overview]
Message-ID: <20240726071023.4078055-1-lsahn@wewakecorp.com> (raw)

sparse_buffer_fini(..) takes the following actions even though the value of
sparsemap_buf is NULL,
1. calculate size of sparsemap buffer (which is meaningless).
2. set sparsemap_buf variable to NULL (although it is already NULL).

These steps are unnecessary if the variable, sparsemap_buf is NULL.

Refactor the function to return right away if the variable is NULL.
Hence, it doesn't need to take further actions.

Signed-off-by: Leesoo Ahn <lsahn@ooseel.net>
---
 mm/sparse.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/mm/sparse.c b/mm/sparse.c
index e4b830091d13..091e4bc2f72c 100644
--- a/mm/sparse.c
+++ b/mm/sparse.c
@@ -469,9 +469,13 @@ static void __init sparse_buffer_init(unsigned long size, int nid)
 
 static void __init sparse_buffer_fini(void)
 {
-	unsigned long size = sparsemap_buf_end - sparsemap_buf;
+	unsigned long size;
 
-	if (sparsemap_buf && size > 0)
+	if (!sparsemap_buf)
+		return;
+
+	size = sparsemap_buf_end - sparsemap_buf;
+	if (size > 0)
 		sparse_buffer_free(size);
 	sparsemap_buf = NULL;
 }
-- 
2.34.1



             reply	other threads:[~2024-07-26  7:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-26  7:10 Leesoo Ahn [this message]
2024-07-28 12:43 ` Mike Rapoport
2024-07-29  6:57   ` Anshuman Khandual

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=20240726071023.4078055-1-lsahn@wewakecorp.com \
    --to=lsahn@ooseel.net \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lsahn@wewakecorp.com \
    /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