From patchwork Fri Jan 20 05:57:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 46158 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp32807wrn; Thu, 19 Jan 2023 22:00:42 -0800 (PST) X-Google-Smtp-Source: AMrXdXvVDvRDVKmxEQV371E8hV+/kvMmEjcxQ+BxdAjjIyBDbKWxH4rXNy33RE44Jjyh8jRulnwK X-Received: by 2002:a17:907:9620:b0:871:2051:6377 with SMTP id gb32-20020a170907962000b0087120516377mr18773310ejc.60.1674194442790; Thu, 19 Jan 2023 22:00:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674194442; cv=none; d=google.com; s=arc-20160816; b=XIxX8aDFAll/BZmzzMKDfbE1wnYtFh1X1rBtGTp36CsQzVifQj9uJjJ0sMrtaolK6i QtlSz67/BUyh8enAb/0XqLH2RWYO/jMk7M4RRlczAfONqFaWhlVfKmT+5rhDGiMRqBao byHhAu0tjTqjvyi728DDcD7dFZW2nEVLaehk+jgrxfMgoHylefrrs3eH6ZzOMbdt6vNu 9P0qePqt2zJQVgYM5gE9HbIuzm441rPzFxVe8mvLZtOxFUKo4KBSaFiet9M4E7vLZ7ZB adQjcQAxJrLijMJejJodn8Iny8EWK/pn6b7oePKY+26tXJ8pIkJ70dzzwHBj6ZOXRbE0 /74w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=BbP4W57AMZS9MBlxZ+FGeKuIJTpb3nSR8+y62zx7ev0=; b=fy3aSBS/OE6URTV70P9zwF+lclj8BUvWjPVyvBPSWpAhBhMa8okpaGcXuaf6gaCPR+ IW/BIpNop/BYte6s+0FpjHoSoDMX8lUf0659gRwgBFiR3EBGocYaJRiSfrzdFuiwG9Qq 7Nss6Q72JAGWLV/73qeg6Y5R+Yw6pgPNSuce6Sm9Oruvb5UzxFp6lXplpeepR0/LZ/ZG WtyTZk4ZQBUl3qGtm4my55QIGl8HwA1PRqpjIpY5B9z7Ty2PgsIca+VTWwoz/Rdo3PpX k3j1ClO1CqCRABNmYwsJ5E97Le/9Q6BDTsf8IMDS+jPojmMMArA59h80r++ABNY/s0z1 sygQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=i2yclwUY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xc2-20020a170907074200b007c0b777d1c0si37961193ejb.737.2023.01.19.22.00.18; Thu, 19 Jan 2023 22:00:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=i2yclwUY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229819AbjATF62 (ORCPT + 99 others); Fri, 20 Jan 2023 00:58:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229530AbjATF6Z (ORCPT ); Fri, 20 Jan 2023 00:58:25 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D7C43A581 for ; Thu, 19 Jan 2023 21:57:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674194263; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BbP4W57AMZS9MBlxZ+FGeKuIJTpb3nSR8+y62zx7ev0=; b=i2yclwUYLUjVCZ0myUH8lJSAEyXTfVcMcqJjTLdVbjQ0vY/P8msimNE3V+AZvcDAaV0cMr Ies4zxB05z8FDA6ZWkKbvLfvMQUrY8muI35aWdBnvRj75yzhXVg11UCT+yYwAENDcQbi2I Y4rcg8Ji8553I2lqYqfQMlJzivEtzBg= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-68-hsPSwQu1MzqPAF6P0cWtIQ-1; Fri, 20 Jan 2023 00:57:38 -0500 X-MC-Unique: hsPSwQu1MzqPAF6P0cWtIQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2C6B53C02556; Fri, 20 Jan 2023 05:57:38 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-98.bne.redhat.com [10.64.54.98]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 61BF340C6EC4; Fri, 20 Jan 2023 05:57:35 +0000 (UTC) From: Gavin Shan To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, david@redhat.com, osalvador@suse.de, gregkh@linuxfoundation.org, rafael@kernel.org, shan.gavin@gmail.com Subject: [PATCH 1/2] drivers/base/memory: Fix comments for phys_index_show() Date: Fri, 20 Jan 2023 13:57:26 +0800 Message-Id: <20230120055727.355483-2-gshan@redhat.com> In-Reply-To: <20230120055727.355483-1-gshan@redhat.com> References: <20230120055727.355483-1-gshan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755520112235417620?= X-GMAIL-MSGID: =?utf-8?q?1755520112235417620?= According to 'admin-guide/mm/memory-hotplug.rst', the memory block ID, instead of the section index, is shown by '/sys/devices/system/memory/ memoryX/phys_index'. Fix the comments to match with 'admin-guide/mm/memory-hotplug.rst'. Besides, use the existing helper memory_block_id() to convert the section index to the memory block index. No functional change intended. Signed-off-by: Gavin Shan Reviewed-by: David Hildenbrand --- drivers/base/memory.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index fe98fb8d94e5..b456ac213610 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -115,18 +115,13 @@ unsigned long __weak memory_block_size_bytes(void) } EXPORT_SYMBOL_GPL(memory_block_size_bytes); -/* - * Show the first physical section index (number) of this memory block. - */ +/* Show the memory block ID, relative to the memory block size */ static ssize_t phys_index_show(struct device *dev, struct device_attribute *attr, char *buf) { struct memory_block *mem = to_memory_block(dev); - unsigned long phys_index; - - phys_index = mem->start_section_nr / sections_per_block; - return sysfs_emit(buf, "%08lx\n", phys_index); + return sysfs_emit(buf, "%08lx\n", memory_block_id(mem->start_section_nr)); } /* From patchwork Fri Jan 20 05:57:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 46157 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp32804wrn; Thu, 19 Jan 2023 22:00:42 -0800 (PST) X-Google-Smtp-Source: AMrXdXt4sN3GiaJ2B+Dd0qHcO+9OYoqJpwYXtSXA9NAS6OWiKN3sLWeKqjqXsKw4bLYrcUJ7MLTM X-Received: by 2002:a17:906:1c55:b0:7c0:1db5:ea10 with SMTP id l21-20020a1709061c5500b007c01db5ea10mr14084795ejg.53.1674194442424; Thu, 19 Jan 2023 22:00:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674194442; cv=none; d=google.com; s=arc-20160816; b=RESNb1l0PbsRpkdM00e9PVs5zUptbxk811UiAfO+jRE+pM+j6ED+WH0JylKTMyPLDH l4lR7D93VYSY62PWXLgqn3mW6i0r6bl585HYIy26QKF7D4coeyUnpipVpMr1Cp+JqDnA O7i5qw4BY8a5TZxYllVswXz9l7KAYBvIOkEqKKOgR3yjmmJcaQWSdG9PNoEdpqoUV90m zkdm6qlOJUL3tHJSd0ay+51cgovVRVC8cs9viFpstK391EZ8AtgeTxzcyuaQvx0dl7Bb ooYVTbpK6VZ/WOxO9dCFX54W6snCZNmKZr8tO/IC0fPbTqDOmgUe8Y8/tpSR6wWbYGpz mNrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=KjmOoqTkye3UNXuCyk++rWgNtMqygxPkyWDL4dhhiqM=; b=f5FXjmbzQViYB9+eNsxOCAqn1LKToPvRKiCnoR/QETCmD1ojQ476IywPG9aVG+OxTA PwOHg8+ygzxEMFwO65OxGIi8b9kRjE9QyJAE/W75ceMOuei/RTgkhd0LbgQNjP40evPo Sg5s1hlXmvV8MGV611fy/c+HOrLS2C9/DVhyGlYAhIMS1f8vzO4bQqgGtjd8/45Ijtfm bClOQ374wbzM8lpFwSyq29oI3buU+jVrooydy/toC0hfnfZH3vwygCcBgQLpnbZS0x2z P+sARtZOhevMA+SwlfzSq5l1B4alAG8oA1wAVSBLvlR9KWRWJWMdP/wVBc7oGxissruf dTzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=iMVqJj+0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xi9-20020a170906dac900b007b961545a0dsi42053351ejb.500.2023.01.19.22.00.18; Thu, 19 Jan 2023 22:00:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=iMVqJj+0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230320AbjATF60 (ORCPT + 99 others); Fri, 20 Jan 2023 00:58:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229819AbjATF6Z (ORCPT ); Fri, 20 Jan 2023 00:58:25 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F33DA619D for ; Thu, 19 Jan 2023 21:57:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674194267; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KjmOoqTkye3UNXuCyk++rWgNtMqygxPkyWDL4dhhiqM=; b=iMVqJj+02lXfv5RHo8ITaqNl3vJtZIDsS0HQW5E3j7vlri5kIHJ/c/tdgCy53iYLFW2YP4 ezwTgicL3YBY/ST0Ddm+enwzG8BJHMpJPx6OPtoNCMIn+Hiw8gKgXzQqbBWr+6Nc4enKat 7+5CkxP77jX7zSyD6xvP90K2+EAJcPA= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-98-kgi0r40PNt-4Eh0V51Y9Ag-1; Fri, 20 Jan 2023 00:57:41 -0500 X-MC-Unique: kgi0r40PNt-4Eh0V51Y9Ag-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 66E4F2A5954E; Fri, 20 Jan 2023 05:57:41 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-98.bne.redhat.com [10.64.54.98]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BE79640C6EC4; Fri, 20 Jan 2023 05:57:38 +0000 (UTC) From: Gavin Shan To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, david@redhat.com, osalvador@suse.de, gregkh@linuxfoundation.org, rafael@kernel.org, shan.gavin@gmail.com Subject: [PATCH 2/2] drivers/base/memory: Use array to show memory block state Date: Fri, 20 Jan 2023 13:57:27 +0800 Message-Id: <20230120055727.355483-3-gshan@redhat.com> In-Reply-To: <20230120055727.355483-1-gshan@redhat.com> References: <20230120055727.355483-1-gshan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755520111869254773?= X-GMAIL-MSGID: =?utf-8?q?1755520111869254773?= Use an array to show memory block state from '/sys/devices/system/ memory/memoryX/state', to simplify the code. No functional change intended. Signed-off-by: Gavin Shan --- drivers/base/memory.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index b456ac213610..9474f25c452c 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -141,28 +141,15 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr, char *buf) { struct memory_block *mem = to_memory_block(dev); - const char *output; + static const char *const mem_state_str[] = { + NULL, "online", "going-offline", NULL, "offline", + }; - /* - * We can probably put these states in a nice little array - * so that they're not open-coded - */ - switch (mem->state) { - case MEM_ONLINE: - output = "online"; - break; - case MEM_OFFLINE: - output = "offline"; - break; - case MEM_GOING_OFFLINE: - output = "going-offline"; - break; - default: - WARN_ON(1); + if (WARN_ON(mem->state >= ARRAY_SIZE(mem_state_str) || + !mem_state_str[mem->state])) return sysfs_emit(buf, "ERROR-UNKNOWN-%ld\n", mem->state); - } - return sysfs_emit(buf, "%s\n", output); + return sysfs_emit(buf, "%s\n", mem_state_str[mem->state]); } int memory_notify(unsigned long val, void *v)