From patchwork Tue Jan 7 10:39:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiyang Ruan X-Patchwork-Id: 13928673 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 BFB51E77198 for ; Tue, 7 Jan 2025 10:39:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4E32F6B00C0; Tue, 7 Jan 2025 05:39:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 493776B00C1; Tue, 7 Jan 2025 05:39:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 35B446B00C2; Tue, 7 Jan 2025 05:39:35 -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 191DE6B00C0 for ; Tue, 7 Jan 2025 05:39:35 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 8DA5E4429A for ; Tue, 7 Jan 2025 10:39:34 +0000 (UTC) X-FDA: 82980309468.21.225BAFB Received: from esa9.hc1455-7.c3s2.iphmx.com (esa9.hc1455-7.c3s2.iphmx.com [139.138.36.223]) by imf13.hostedemail.com (Postfix) with ESMTP id 257D820002 for ; Tue, 7 Jan 2025 10:39:31 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=fujitsu.com header.s=fj2 header.b=rLTjVVOO; dmarc=pass (policy=reject) header.from=fujitsu.com; spf=pass (imf13.hostedemail.com: domain of ruansy.fnst@fujitsu.com designates 139.138.36.223 as permitted sender) smtp.mailfrom=ruansy.fnst@fujitsu.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736246372; a=rsa-sha256; cv=none; b=ys5GHWAHxIx+UUhWAQ8RHg62OWj17D23BdPwJe9EFU5jfMj0fkYIPVvIxf9T8/1RBD/6Vi unwZDIsfvemzri6cE27gKdckYmS2EYtojUb2yiHF5ycycHDOtnJZAe/DrLEgf8byhqNJ7x adjNIBxTW2DPLp2vWVXPQ6BCl/0/bqs= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=fujitsu.com header.s=fj2 header.b=rLTjVVOO; dmarc=pass (policy=reject) header.from=fujitsu.com; spf=pass (imf13.hostedemail.com: domain of ruansy.fnst@fujitsu.com designates 139.138.36.223 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=1736246372; 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=KcQRLdpEU0B6MH7oURVoKzNEOd9fs3A1VSJB3jT9jtQ=; b=DxKwrqUVBQVGEgP2Wn2MdKheHyJIYNoF8fD09UElFQf9uxuDLuDeLeFlUjnMK3dJapHb9A Ug4/XtA3txY3eDy/8OU5zqqKzzfM5PaTRFBA/Ex0CoFG0XMPXbdoCTyscGGdjsUqPNjagO TYZM2NOJB/H1bXDckJA45AX7itFgoxc= DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=fujitsu.com; i=@fujitsu.com; q=dns/txt; s=fj2; t=1736246372; x=1767782372; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=7bdgaV8/WL/L5Z2hWZaHfvRUNBK6R1qSAIXfRUu1RBI=; b=rLTjVVOO0JSQ4fuhucb9AFeAWHaRd55LokoyEQhoZNBEebFb51eYmRPb /hLSF2AKGI0j6Xexy6+8N0D+g+fLDgD/mbAZamPvdKGt8mmPZ7DYl3dLB AKOzRns0QMgPJdMMu7ml6MGAz77w9TRkyXQPWWJwnUzQ639Rr+rO6f6A+ xGQwHeQ72tIcOADAyboXHsedpeIc3fdU7CftPd1WcnDiRfHC2/Ev8uswj jP5mvHpdcO0lBUOT9k5qVuVQRRsQhgpTmner8MBedWc3XuPSC0m+hPpwY z8VW0L0FbYfi8NzqgNrk/i4ZXh+jzOYuj4eGGqva5T6O6KZ4p0zEsFGeq w==; X-CSE-ConnectionGUID: XI2zq2/1RXCONMXCGvj8vA== X-CSE-MsgGUID: yNtKkSi/R3qobSlJHg/Qgw== X-IronPort-AV: E=McAfee;i="6700,10204,11307"; a="174184918" X-IronPort-AV: E=Sophos;i="6.12,295,1728918000"; d="scan'208";a="174184918" Received: from unknown (HELO oym-r2.gw.nic.fujitsu.com) ([210.162.30.90]) by esa9.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Jan 2025 19:39:30 +0900 Received: from oym-m4.gw.nic.fujitsu.com (oym-nat-oym-m4.gw.nic.fujitsu.com [192.168.87.61]) by oym-r2.gw.nic.fujitsu.com (Postfix) with ESMTP id 1562BD4C42 for ; Tue, 7 Jan 2025 19:39:28 +0900 (JST) Received: from kws-ab4.gw.nic.fujitsu.com (kws-ab4.gw.nic.fujitsu.com [192.51.206.22]) by oym-m4.gw.nic.fujitsu.com (Postfix) with ESMTP id D7B48D4BDA for ; Tue, 7 Jan 2025 19:39:27 +0900 (JST) Received: from edo.cn.fujitsu.com (edo.cn.fujitsu.com [10.167.33.5]) by kws-ab4.gw.nic.fujitsu.com (Postfix) with ESMTP id 6224A224604 for ; Tue, 7 Jan 2025 19:39:27 +0900 (JST) Received: from localhost.localdomain (unknown [10.167.135.81]) by edo.cn.fujitsu.com (Postfix) with ESMTP id C74D41A0003; Tue, 7 Jan 2025 18:39:26 +0800 (CST) From: Shiyang Ruan To: linux-mm@kvack.org, david@redhat.com, osalvador@suse.de, rafael@kernel.org Subject: [PATCH v2] drivers/base/memory: simplify outputting of valid_zones_show() Date: Tue, 7 Jan 2025 18:39:26 +0800 Message-ID: <20250107103926.1189728-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-28908.003 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1417-9.0.1002-28908.003 X-TMASE-Result: 10--4.281900-10.000000 X-TMASE-MatchedRID: gevQBo9kxww8fZON/jw+AOOnF2j8nBWbwTlc9CcHMZerwqxtE531VIPc XuILVCbaasOJoXx/wo/A1tegkciQsDmpL9mXE1+sngIgpj8eDcBpkajQR5gb3lQwtQm7iV5jKra uXd3MZDXJZ/LISwyXPmJNR6KsW7HN+n3WuOWMj2XAygwaDfVh3TrmC8dgG//ruH4mN6E5uW0Zs1 smLxeDBA7aZVIFqfSXV0QaDim/SQ9FuPUh9LUiIdYo0ZSf6DjXug9Fry8EScFZ/ZLAbStn9PhRJ kR4B21q X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 257D820002 X-Stat-Signature: bri884ny4rcdpgd68ackngbnwgfzdb5o X-Rspam-User: X-HE-Tag: 1736246371-584792 X-HE-Meta: U2FsdGVkX18qh46oPu1RvzGDqgb/XjAt1/6M/FMwzeofOhM15ZqeW+jNtZVMX+vy8MOv/MOV9ccDIgUkjoakrkXtgBBkmK66o29lKMgfzmXRuMBgzw7gsUjLj9JfVFcqq4odtjdCldhEUwa75tlmwKzuwobuY9CrxzmqLGDwghnOcds+HzQs6sjAeHVc63C+spsfie1Wm4oe5jV9gwUkKExVAQqfLtYVAwFXsHdRTSq7JZZj57JRk7HW5waIVRLRzen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ender: 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 | 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); 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; }