From patchwork Wed Jan 8 01:52:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiyang Ruan X-Patchwork-Id: 13929946 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30C9EE77197 for ; Wed, 8 Jan 2025 01:52:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B1B876B0082; Tue, 7 Jan 2025 20:52:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ACB9F6B0083; Tue, 7 Jan 2025 20:52:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 96BDB6B0088; Tue, 7 Jan 2025 20:52:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 777A46B0082 for ; Tue, 7 Jan 2025 20:52:33 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 273FEC054D for ; Wed, 8 Jan 2025 01:52:33 +0000 (UTC) X-FDA: 82982610186.11.E8EB6CB Received: from esa10.hc1455-7.c3s2.iphmx.com (esa10.hc1455-7.c3s2.iphmx.com [139.138.36.225]) by imf25.hostedemail.com (Postfix) with ESMTP id 2C397A0015 for ; Wed, 8 Jan 2025 01:52:28 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=fujitsu.com header.s=fj2 header.b=IlZcAJW7; dmarc=pass (policy=reject) header.from=fujitsu.com; spf=pass (imf25.hostedemail.com: domain of ruansy.fnst@fujitsu.com designates 139.138.36.225 as permitted sender) smtp.mailfrom=ruansy.fnst@fujitsu.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736301149; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=coBshVMxPhBgBua8T3jmAZMtgeXWiqXF+y0Cjn8cAh0=; b=8ACwN4EG2QslK6CMWnDzCbWic+OTqx0f9VYE8Qb+rZxyJyp7aby/aIflrtrl4N2xC4SoTi eoebqqf2+gH9ta5fCXJ6YCd0IER2WmRD82gc9b7Fpn1kBQmnZAGJRYSNMePjZiWPAxQbIw fHgRh8LXv8FvR6Zvk8ZOWAp/zMY42oY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736301149; a=rsa-sha256; cv=none; b=2cyRrcB7AF+j/0EkknNCwFOD7xVPxqHyw6HDz5Mzj6F+dcfgjs+G8+IcOiKipdaXFRZ91O CkjWUY60Fs2+5r3NbxwGlzLEfTZRLjfYKM6ApZQz+iXOTmr/8Hl/2k43tzHZuwWBlgCXmw 3ix3J+6qIvl8+RoXjuGicB6p1dmRDWQ= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=fujitsu.com header.s=fj2 header.b=IlZcAJW7; dmarc=pass (policy=reject) header.from=fujitsu.com; spf=pass (imf25.hostedemail.com: domain of ruansy.fnst@fujitsu.com designates 139.138.36.225 as permitted sender) smtp.mailfrom=ruansy.fnst@fujitsu.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=fujitsu.com; i=@fujitsu.com; q=dns/txt; s=fj2; t=1736301149; x=1767837149; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=GsoACvZceZs1Mgujeidx0avXXe0k9Wd7MTULAQM+wRk=; b=IlZcAJW7DK0hCBl36cvdi4n2c5TAUDKtiBFT8D0CYhAeWma0dEUcko7C gnKVyFMN5kswCi7sLpvwaKTWosuY3unYpbahFw6p1x7YCdB87DEoU07VH TIHQ+bXnunfpZ1jdCZEjjlQhp/inofLBILpSv0puczsDcoHNck9HYMV8E oK09Hfaij3FS/3y1fBbVAm4Eh9Ga5r2AIfl+2P7FPLG5dRU1Cua1BZ7Ye A5jHNwKtY7iMPqK0IeoHXpUptpSbAZ6nrRgPY0Q9tmPMDRpBsMU67KpOY fQ+ZonA3i7pcl2rgSLoX+d5a9iKlfedTNKNHoZRmFr32BtRBnEz8RmsMN Q==; X-CSE-ConnectionGUID: mMi+gM4jQH6q7t24TNTHCw== X-CSE-MsgGUID: F2FlQvC6SJq5p0gXkOLudw== X-IronPort-AV: E=McAfee;i="6700,10204,11308"; a="173211033" X-IronPort-AV: E=Sophos;i="6.12,296,1728918000"; d="scan'208";a="173211033" Received: from unknown (HELO yto-r3.gw.nic.fujitsu.com) ([218.44.52.219]) by esa10.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jan 2025 10:52:27 +0900 Received: from yto-m4.gw.nic.fujitsu.com (yto-nat-yto-m4.gw.nic.fujitsu.com [192.168.83.67]) by yto-r3.gw.nic.fujitsu.com (Postfix) with ESMTP id 2425DE8525 for ; Wed, 8 Jan 2025 10:52:25 +0900 (JST) Received: from kws-ab3.gw.nic.fujitsu.com (kws-ab3.gw.nic.fujitsu.com [192.51.206.21]) by yto-m4.gw.nic.fujitsu.com (Postfix) with ESMTP id E95A6D3F12 for ; Wed, 8 Jan 2025 10:52:24 +0900 (JST) Received: from edo.cn.fujitsu.com (edo.cn.fujitsu.com [10.167.33.5]) by kws-ab3.gw.nic.fujitsu.com (Postfix) with ESMTP id 726F920086124 for ; Wed, 8 Jan 2025 10:52:24 +0900 (JST) Received: from localhost.localdomain (unknown [10.167.135.81]) by edo.cn.fujitsu.com (Postfix) with ESMTP id B18D11A006C; Wed, 8 Jan 2025 09:52:23 +0800 (CST) From: Shiyang Ruan 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 Message-ID: <20250108015223.1522887-1-ruansy.fnst@fujitsu.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250107100941.1169222-1-ruansy.fnst@fujitsu.com> References: <20250107100941.1169222-1-ruansy.fnst@fujitsu.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSS-9.1.0.1417-9.0.0.1002-28910.004 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1417-9.0.1002-28910.004 X-TMASE-Result: 10--3.611900-10.000000 X-TMASE-MatchedRID: DtgaWgV4wQ48fZON/jw+AOOnF2j8nBWbwTlc9CcHMZerwqxtE531VIPc XuILVCbaasOJoXx/wo/A1tegkciQsGsV28ESZOe8TPsVRSNcbWNAApRfVHzqNJsoi2XrUn/J8m+ hzBStansfRoCwBzgRYidET58jp62SQHnKHPxTHZu/IpW0E4URX0fKgQ2aEW0NUneAa7AjEG317U qMzGwiQipnWtvBibw61DS9q4JeVyiXJUflUx7KLtP4yv9wxw1hk1fN9KkaNH6SEszh2CoKriWdk STbNn9cYqxhzsApQRgZCdVZDNAaYg== X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 X-Stat-Signature: 16f76uuib8t5teqpdjcdqxr4mt6bk19o X-Rspamd-Queue-Id: 2C397A0015 X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1736301148-627898 X-HE-Meta: U2FsdGVkX18StPerwu5+0WdZDnY9qxkAvl2BwBnbI6VEsmXtLUnUN3rnifRhNLLmoLrlR4PnvLgExpoMkcwDhYUSfYvGGTaNvSe7gsikTxd+jDS8A17Q7B4QpkWGbfzVO4sf0RPTnkTJyKsYjz0uNTAeSVjuJbVwDdLd5ENHFXfxhdXEYs7rslT/0zo5TR01Qkj4+KPuYodQ3m/nh2awXHMGIZ5t/zBYL4Sk4l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Tz6hw7LzQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000005, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 Acked-by: David Hildenbrand --- 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; }