From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.4 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D94BC4332D for ; Fri, 20 Mar 2020 10:00:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4F39120739 for ; Fri, 20 Mar 2020 10:00:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="fKCE73zk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4F39120739 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id EE0366B0003; Fri, 20 Mar 2020 06:00:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E69E66B0006; Fri, 20 Mar 2020 06:00:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D325E6B0007; Fri, 20 Mar 2020 06:00:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0071.hostedemail.com [216.40.44.71]) by kanga.kvack.org (Postfix) with ESMTP id B8B806B0003 for ; Fri, 20 Mar 2020 06:00:10 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 6C0D9181AC9C6 for ; Fri, 20 Mar 2020 10:00:10 +0000 (UTC) X-FDA: 76615294980.02.boats70_3bacf2e070215 X-HE-Tag: boats70_3bacf2e070215 X-Filterd-Recvd-Size: 4681 Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [63.128.21.74]) by imf38.hostedemail.com (Postfix) with ESMTP for ; Fri, 20 Mar 2020 10:00:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584698409; 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: in-reply-to:in-reply-to:references:references; bh=wav6xNqI9ihDDoXx/GoMx+TsMvEpi21uQTIJBLfXuG4=; b=fKCE73zkvVYrvFz4MsX5CkUGXCs0/sWC5OlXizr7oajoGpfpUMTg72nBqI7ehdsnPk/Dg5 dDuOoQ62DPhmfvEhD/q3EWzGWQKp9x3rF854DA6sLwAia488B2gwcGpi4+Iqtss9EEU+Rt w7pN3dYGuKFGQGLiGLcguScgEYJ9MM0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-256-1Zz8HvToOJmcmiDI4OJmtA-1; Fri, 20 Mar 2020 06:00:07 -0400 X-MC-Unique: 1Zz8HvToOJmcmiDI4OJmtA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 960B418CA245; Fri, 20 Mar 2020 10:00:05 +0000 (UTC) Received: from localhost (ovpn-13-97.pek2.redhat.com [10.72.13.97]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 315A37389C; Fri, 20 Mar 2020 10:00:00 +0000 (UTC) Date: Fri, 20 Mar 2020 17:59:58 +0800 From: Baoquan He To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, linux-hyperv@vger.kernel.org, Wei Yang , Michal Hocko , Greg Kroah-Hartman , Andrew Morton , Michal Hocko , Oscar Salvador , "Rafael J. Wysocki" Subject: Re: [PATCH v3 3/8] drivers/base/memory: store mapping between MMOP_* and string in an array Message-ID: <20200320095958.GF2987@MiWiFi-R3L-srv> References: <20200319131221.14044-1-david@redhat.com> <20200319131221.14044-4-david@redhat.com> <20200320073653.GE2987@MiWiFi-R3L-srv> <166f7f03-eda9-00a8-bd18-128898526313@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <166f7f03-eda9-00a8-bd18-128898526313@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 03/20/20 at 10:50am, David Hildenbrand wrote: > On 20.03.20 08:36, Baoquan He wrote: > > On 03/19/20 at 02:12pm, David Hildenbrand wrote: > >> Let's use a simple array which we can reuse soon. While at it, move the > >> string->mmop conversion out of the device hotplug lock. > >> > >> Reviewed-by: Wei Yang > >> Acked-by: Michal Hocko > >> Cc: Greg Kroah-Hartman > >> Cc: Andrew Morton > >> Cc: Michal Hocko > >> Cc: Oscar Salvador > >> Cc: "Rafael J. Wysocki" > >> Cc: Baoquan He > >> Cc: Wei Yang > >> Signed-off-by: David Hildenbrand > >> --- > >> drivers/base/memory.c | 38 +++++++++++++++++++++++--------------- > >> 1 file changed, 23 insertions(+), 15 deletions(-) > >> > >> diff --git a/drivers/base/memory.c b/drivers/base/memory.c > >> index e7e77cafef80..8a7f29c0bf97 100644 > >> --- a/drivers/base/memory.c > >> +++ b/drivers/base/memory.c > >> @@ -28,6 +28,24 @@ > >> > >> #define MEMORY_CLASS_NAME "memory" > >> > >> +static const char *const online_type_to_str[] = { > >> + [MMOP_OFFLINE] = "offline", > >> + [MMOP_ONLINE] = "online", > >> + [MMOP_ONLINE_KERNEL] = "online_kernel", > >> + [MMOP_ONLINE_MOVABLE] = "online_movable", > >> +}; > >> + > >> +static int memhp_online_type_from_str(const char *str) > >> +{ > >> + int i; > > > > I would change it as: > > > > for (int i = 0; i < ARRAY_SIZE(online_type_to_str); i++) { > > > > That's not allowed by the C90 standard (and -std=gnu89). > > $ gcc main.c -std=gnu89 > main.c: In function 'main': > main.c:3:2: error: 'for' loop initial declarations are only allowed in > C99 or C11 mode > 3 | for (int i = 0; i < 8; i++) { > | ^~~ Good to know, thanks. > > One of the reasons why > git grep "for (int " > > will result in very little hits (IOW, only 5 in driver code only). > > -- > Thanks, > > David / dhildenb