Message ID | 20250107103926.1189728-1-ruansy.fnst@fujitsu.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | [v2] drivers/base/memory: simplify outputting of valid_zones_show() | expand |
On 07.01.25 11:39, Shiyang Ruan wrote: > 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> > --- > drivers/base/memory.c | 10 +++------- > 1 file changed, 3 insertions(+), 7 deletions(-) > > diff --git a/drivers/base/memory.c b/drivers/base/memory.c > index 67858eeb92ed..975fdbbff264 100644 > --- a/drivers/base/memory.c > +++ b/drivers/base/memory.c > @@ -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); Sorry for realizing it now: you can turn that into len = sysfs_emit(buf, "%s", default_zone->name); And stop initializing len to 0. Acked-by: David Hildenbrand <david@redhat.com>
diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 67858eeb92ed..975fdbbff264 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -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; }
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> --- drivers/base/memory.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)