From: Shiyang Ruan <ruansy.fnst@fujitsu.com>
To: linux-mm@kvack.org, david@redhat.com, osalvador@suse.de,
rafael@kernel.org
Subject: [PATCH v3] drivers/base/memory: simplify outputting of valid_zones_show()
Date: Wed, 8 Jan 2025 09:52:23 +0800 [thread overview]
Message-ID: <20250108015223.1522887-1-ruansy.fnst@fujitsu.com> (raw)
In-Reply-To: <20250107100941.1169222-1-ruansy.fnst@fujitsu.com>
No need to specific position at the first writing to the buf because the
@len is always 0 at this time. Use sysfs_emit() instead to simplify it.
Also avoid setting/checking default_zone with a conditional operator.
Signed-off-by: Shiyang Ruan <ruansy.fnst@fujitsu.com>
Acked-by: David Hildenbrand <david@redhat.com>
---
drivers/base/memory.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 67858eeb92ed..92e6bc6eb21e 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -455,7 +455,7 @@ static ssize_t valid_zones_show(struct device *dev,
struct memory_group *group = mem->group;
struct zone *default_zone;
int nid = mem->nid;
- int len = 0;
+ int len;
/*
* Check the existing zone. Make sure that we do that only on the
@@ -466,22 +466,18 @@ static ssize_t valid_zones_show(struct device *dev,
* If !mem->zone, the memory block spans multiple zones and
* cannot get offlined.
*/
- default_zone = mem->zone;
- if (!default_zone)
- return sysfs_emit(buf, "%s\n", "none");
- len += sysfs_emit_at(buf, len, "%s", default_zone->name);
- goto out;
+ return sysfs_emit(buf, "%s\n",
+ mem->zone ? mem->zone->name : "none");
}
default_zone = zone_for_pfn_range(MMOP_ONLINE, nid, group,
start_pfn, nr_pages);
- len += sysfs_emit_at(buf, len, "%s", default_zone->name);
+ len = sysfs_emit(buf, "%s", default_zone->name);
len += print_allowed_zone(buf, len, nid, group, start_pfn, nr_pages,
MMOP_ONLINE_KERNEL, default_zone);
len += print_allowed_zone(buf, len, nid, group, start_pfn, nr_pages,
MMOP_ONLINE_MOVABLE, default_zone);
-out:
len += sysfs_emit_at(buf, len, "\n");
return len;
}
--
2.43.0
next prev parent reply other threads:[~2025-01-08 1:52 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-07 10:09 [PATCH] " Shiyang Ruan
2025-01-07 10:15 ` David Hildenbrand
2025-01-07 10:28 ` Shiyang Ruan
2025-01-07 10:33 ` David Hildenbrand
2025-01-07 10:39 ` [PATCH v2] " Shiyang Ruan
2025-01-07 10:52 ` David Hildenbrand
2025-01-08 1:52 ` Shiyang Ruan [this message]
2025-01-22 10:14 ` [PATCH v3] " Shiyang Ruan
2025-01-22 11:04 ` David Hildenbrand
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=20250108015223.1522887-1-ruansy.fnst@fujitsu.com \
--to=ruansy.fnst@fujitsu.com \
--cc=david@redhat.com \
--cc=linux-mm@kvack.org \
--cc=osalvador@suse.de \
--cc=rafael@kernel.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