Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp2715731ybh; Mon, 16 Mar 2020 08:22:25 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtIiwSFyfnCtumd/krIgFX08Usv+yGnGW4RwCKG6I4IDIlgJu6gdgQq8SZGXypcq2N4uk8p X-Received: by 2002:a05:6808:90f:: with SMTP id w15mr96915oih.0.1584372145882; Mon, 16 Mar 2020 08:22:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584372145; cv=none; d=google.com; s=arc-20160816; b=WWAwdS9CGTcZLsZVLNKB4L8ErcFR2RFlVZBspZsDYTzzw4fcx05dD8BXceVyAm/O1m qdRAIF0QrimTOyj/apiSw8mUVDVnPrlPtjltY2+0g7fawD1QMilzFet+p+gJbbk/ajDu g6UI9ddw1bsmPNlvs8pXvA+lZ9QUEpi8NoQ1x0+2y01zlARxfUT+shiOCJ7XBmLX87lf TPYMLIJRrHU0b2EiNkNK1KFgd5hh8ByBMpvYGG6x1Y6owQhDwI0qLhAWP9DwQALLeMkB 8foysU5OiIWd59NV/JGZEB+JuBvlpqGR7026W4nZ7qKYJOG/brodkhSx+Try0g5/GJYZ Q8ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=PHFwU/9Gwprc+RyvAszebJ6mggkLL/7mXQpDoqU9oeU=; b=MDjNaiAn734Sdi253chXzbxBq70ik5+YIJ7mGwvHSDu8rHOgu10hF0dZEMWkPP1JyX Cx6rJTYI43/bN1f+gcnymsxa3Hwj6tUmJW0mY/CEMHKBcLxJ/LCIA/QJiRLRH9zOnYyr XBrXknKT3AVFWKEeYq3JdzXNglK5N3kAUOTepZmqL1Pr8asWXSEiZpL4LyDYzQqAZusw k45ktTajZcsWDCCHeUOZQcN1WTTTUpRHc6DcC+Wce+y7a+ZNLPmzTv/5UF6Gcws/CnOA 9gvQbZMHmtwYAGOBHaFAz6ZKwxcQnVvLVeKDvDB1W7GmgUDC1deRkfqL5VmeS+NyrulP 7fPA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t83si105659oig.239.2020.03.16.08.22.13; Mon, 16 Mar 2020 08:22:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731696AbgCPPUy (ORCPT + 99 others); Mon, 16 Mar 2020 11:20:54 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:34857 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729856AbgCPPUx (ORCPT ); Mon, 16 Mar 2020 11:20:53 -0400 Received: by mail-wr1-f68.google.com with SMTP id h4so1111829wru.2; Mon, 16 Mar 2020 08:20:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=PHFwU/9Gwprc+RyvAszebJ6mggkLL/7mXQpDoqU9oeU=; b=jcedxD7NKQYDtUMcNkqQHGlt1H5Xpaw3RnwFUgSnatacPWrln81Dr9TIkc2965EqBm k1MYPg6psepbbXe/a1Iib0rl9LDLUgjd7+URVv1j0z6lHZruNfGkCobCLZoRC1oKug30 JkxX8KSLmSiQsrhZm5ks0P0rOk4W2PxSEdtFGUXSQad1qvwjA+iEHqnL8XvmMECzwgCy 5ttSoj635qpw+1LMdC14Y0Z3siW8lCCX9jOjkWXGvEzThd2CY1OBYYZFmJIrvxht+kJ+ 5tqX7lfnIwWKiz9GQ6ZwAXPDI86whLhO2AhY/hc8N1W4hKobiiYyw9YUvipOBg/7iK4u luCg== X-Gm-Message-State: ANhLgQ2BCvWIVF6KN1GFZDMd8RrUa9+KpZF4iB39h4lEfAUIlmUj3Hb6 qXYr94gLn0xrubpwkVZqhJs= X-Received: by 2002:adf:db49:: with SMTP id f9mr15327113wrj.145.1584372051365; Mon, 16 Mar 2020 08:20:51 -0700 (PDT) Received: from localhost ([37.188.132.163]) by smtp.gmail.com with ESMTPSA id b187sm18218wmb.42.2020.03.16.08.20.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Mar 2020 08:20:50 -0700 (PDT) Date: Mon, 16 Mar 2020 16:20:47 +0100 From: Michal Hocko To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, linux-hyperv@vger.kernel.org, Greg Kroah-Hartman , Andrew Morton , Oscar Salvador , "Rafael J. Wysocki" , Baoquan He , Wei Yang Subject: Re: [PATCH v1 3/5] drivers/base/memory: store mapping between MMOP_* and string in an array Message-ID: <20200316152047.GU11482@dhcp22.suse.cz> References: <20200311123026.16071-1-david@redhat.com> <20200311123026.16071-4-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200311123026.16071-4-david@redhat.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed 11-03-20 13:30:24, 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. > > 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 Acked-by: Michal Hocko > --- > 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; > + > + for (i = 0; i < ARRAY_SIZE(online_type_to_str); i++) { > + if (sysfs_streq(str, online_type_to_str[i])) > + return i; > + } > + return -EINVAL; > +} > + > #define to_memory_block(dev) container_of(dev, struct memory_block, dev) > > static int sections_per_block; > @@ -236,26 +254,17 @@ static int memory_subsys_offline(struct device *dev) > static ssize_t state_store(struct device *dev, struct device_attribute *attr, > const char *buf, size_t count) > { > + const int online_type = memhp_online_type_from_str(buf); > struct memory_block *mem = to_memory_block(dev); > - int ret, online_type; > + int ret; > + > + if (online_type < 0) > + return -EINVAL; > > ret = lock_device_hotplug_sysfs(); > if (ret) > return ret; > > - if (sysfs_streq(buf, "online_kernel")) > - online_type = MMOP_ONLINE_KERNEL; > - else if (sysfs_streq(buf, "online_movable")) > - online_type = MMOP_ONLINE_MOVABLE; > - else if (sysfs_streq(buf, "online")) > - online_type = MMOP_ONLINE; > - else if (sysfs_streq(buf, "offline")) > - online_type = MMOP_OFFLINE; > - else { > - ret = -EINVAL; > - goto err; > - } > - > switch (online_type) { > case MMOP_ONLINE_KERNEL: > case MMOP_ONLINE_MOVABLE: > @@ -271,7 +280,6 @@ static ssize_t state_store(struct device *dev, struct device_attribute *attr, > ret = -EINVAL; /* should never happen */ > } > > -err: > unlock_device_hotplug(); > > if (ret < 0) > -- > 2.24.1 -- Michal Hocko SUSE Labs