linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Liu Ye <liuye@kylinos.cn>
To: akpm@linux-foundation.org
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Liu Ye <liuye@kylinos.cn>
Subject: [PATCH] mm/debug: Fix minor issues in mm
Date: Wed, 12 Mar 2025 09:12:36 +0800	[thread overview]
Message-ID: <20250312011236.262766-1-liuye@kylinos.cn> (raw)

This patch includes several minor fixes:

- Fix out-of-bounds access in page_type_name().
- Simplify compound page judgment conditions.
- Missing a newline character at the end of the format string.

Each change is independent.

Signed-off-by: Liu Ye <liuye@kylinos.cn>
---
 mm/debug.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/mm/debug.c b/mm/debug.c
index 8d2acf432385..9a3092e65765 100644
--- a/mm/debug.c
+++ b/mm/debug.c
@@ -62,7 +62,7 @@ static const char *page_type_name(unsigned int page_type)
 {
 	unsigned i = (page_type >> 24) - 0xf0;
 
-	if (i >= ARRAY_SIZE(page_type_names))
+	if (i < 0 || i >= ARRAY_SIZE(page_type_names))
 		return "unknown";
 	return page_type_names[i];
 }
@@ -132,15 +132,15 @@ static void __dump_page(const struct page *page)
 again:
 	memcpy(&precise, page, sizeof(*page));
 	head = precise.compound_head;
-	if ((head & 1) == 0) {
+	if (head & 1) {
+		foliop = (struct folio *)(head - 1);
+		idx = folio_page_idx(foliop, page);
+	} else {
 		foliop = (struct folio *)&precise;
 		idx = 0;
 		if (!folio_test_large(foliop))
 			goto dump;
 		foliop = (struct folio *)page;
-	} else {
-		foliop = (struct folio *)(head - 1);
-		idx = folio_page_idx(foliop, page);
 	}
 
 	if (idx < MAX_FOLIO_NR_PAGES) {
@@ -165,7 +165,7 @@ static void __dump_page(const struct page *page)
 void dump_page(const struct page *page, const char *reason)
 {
 	if (PagePoisoned(page))
-		pr_warn("page:%p is uninitialized and poisoned", page);
+		pr_warn("page:%p is uninitialized and poisoned\n", page);
 	else
 		__dump_page(page);
 	if (reason)
-- 
2.25.1



                 reply	other threads:[~2025-03-12  1:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20250312011236.262766-1-liuye@kylinos.cn \
    --to=liuye@kylinos.cn \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    /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