Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: minwoo.im.dev@gmail.com (Minwoo Im)
Subject: [PATCH 1/3] nvme: separate out nvme_ctrl_state_name()
Date: Thu, 16 May 2019 22:55:59 +0900	[thread overview]
Message-ID: <20190516135558.GC24001@minwooim-desktop> (raw)
In-Reply-To: <20190516083740.95894-2-hare@suse.de>

Hi Hannes,

> +const char *nvme_ctrl_state_name(struct nvme_ctrl *ctrl)
> +{
> +	if ((unsigned)ctrl->state < ARRAY_SIZE(nvme_ctrl_state_names) &&
> +	    nvme_ctrl_state_names[ctrl->state])
> +		return nvme_ctrl_state_names[ctrl->state];
> +	return NULL;

Perhaps we can return "unknown" here that can make callers do not
need to consider that if it gives NULL and not return a string there also.

> @@ -2989,19 +3008,10 @@ static ssize_t nvme_sysfs_show_state(struct device *dev,
>  				     char *buf)
>  {
>  	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
> -	static const char *const state_name[] = {
> -		[NVME_CTRL_NEW]		= "new",
> -		[NVME_CTRL_LIVE]	= "live",
> -		[NVME_CTRL_ADMIN_ONLY]	= "only-admin",
> -		[NVME_CTRL_RESETTING]	= "resetting",
> -		[NVME_CTRL_CONNECTING]	= "connecting",
> -		[NVME_CTRL_DELETING]	= "deleting",
> -		[NVME_CTRL_DEAD]	= "dead",
> -	};
> -
> -	if ((unsigned)ctrl->state < ARRAY_SIZE(state_name) &&
> -	    state_name[ctrl->state])
> -		return sprintf(buf, "%s\n", state_name[ctrl->state]);
> +	const char *state_name = nvme_ctrl_state_name(ctrl);
> +
> +	if (state_name)
> +		return sprintf(buf, "%s\n", state_name);
>  
>  	return sprintf(buf, "unknown state\n");

If so, we can make these three lines to a single one without considering
the NULL case.

What do you think?

  reply	other threads:[~2019-05-16 13:55 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-16  8:37 [PATCH 0/3] nvme-fc: track state change failures Hannes Reinecke
2019-05-16  8:37 ` [PATCH 1/3] nvme: separate out nvme_ctrl_state_name() Hannes Reinecke
2019-05-16 13:55   ` Minwoo Im [this message]
2019-05-16 16:24   ` James Smart
2019-05-16  8:37 ` [PATCH 2/3] nvme-fc: track state change failures during reconnect Hannes Reinecke
2019-05-16 16:24   ` James Smart
2019-05-16  8:37 ` [PATCH 3/3] nvme-fc: fail reconnect if state change fails Hannes Reinecke
2019-05-16 16:25   ` James Smart
2019-05-18  0:18   ` Arun Easi
2019-05-18  0:21     ` Arun Easi
  -- strict thread matches above, loose matches on Subject: below --
2019-05-17  6:42 [PATCHv2 0/3] nvme-fc: track state change failures Hannes Reinecke
2019-05-17  6:42 ` [PATCH 1/3] nvme: separate out nvme_ctrl_state_name() Hannes Reinecke
2019-05-17  7:59   ` Minwoo Im

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=20190516135558.GC24001@minwooim-desktop \
    --to=minwoo.im.dev@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