linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Gavin Shan <gshan@redhat.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	david@redhat.com, osalvador@suse.de, rafael@kernel.org,
	shan.gavin@gmail.com
Subject: Re: [PATCH 2/2] drivers/base/memory: Use array to show memory block state
Date: Fri, 20 Jan 2023 14:14:48 +0100	[thread overview]
Message-ID: <Y8qTyEgc8ih6M+DW@kroah.com> (raw)
In-Reply-To: <20230120055727.355483-3-gshan@redhat.com>

On Fri, Jan 20, 2023 at 01:57:27PM +0800, Gavin Shan wrote:
> 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 <gshan@redhat.com>
> ---
>  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]))

Ick, the whole WARN_ON() should just be removed please.  We don't want
to reboot any systems if this changed incorrectly.

Please fix this up to properly handle this and keep going on, don't mess
with WARN_ON() anymore in code that can recover properly.

thanks,

greg k-h


  reply	other threads:[~2023-01-20 13:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-20  5:57 [PATCH 0/2] drivers/base/memory: Two small cleanups Gavin Shan
2023-01-20  5:57 ` [PATCH 1/2] drivers/base/memory: Fix comments for phys_index_show() Gavin Shan
2023-01-23  8:40   ` David Hildenbrand
2023-01-20  5:57 ` [PATCH 2/2] drivers/base/memory: Use array to show memory block state Gavin Shan
2023-01-20 13:14   ` Greg KH [this message]
2023-01-20 22:59     ` Gavin Shan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y8qTyEgc8ih6M+DW@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=david@redhat.com \
    --cc=gshan@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=osalvador@suse.de \
    --cc=rafael@kernel.org \
    --cc=shan.gavin@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox