All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kelvin Cao <kelvin.cao@microchip.com>
To: "Kurt Schwemmer" <kurt.schwemmer@microsemi.com>,
	"Logan Gunthorpe" <logang@deltatee.com>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Krzysztof Wilczyński" <kw@linux.com>,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Kelvin Cao <kelvin.cao@microchip.com>, <kelvincao@outlook.com>
Subject: [PATCH 2/2] Declare local array state_names as static
Date: Thu, 18 Nov 2021 16:38:03 -0800	[thread overview]
Message-ID: <20211119003803.2333-3-kelvin.cao@microchip.com> (raw)
In-Reply-To: <20211119003803.2333-1-kelvin.cao@microchip.com>

When a MRPC command is being executed, the function stuser_set_state()
will be called several times to set the command execution state.
During each run of stuser_set_state(), the local array state_names is
allocated and populated. The array contains a constant mapping of the
state enum values to the text strings, so repeated allocation and
initialization is just a wait of CPU cycles. Therefore, declare the
array as static.

See the link below for the discussion.

  https://lore.kernel.org/r/20211014141859.11444-1-kelvin.cao@microchip.com/

Suggested-by: Krzysztof Wilczyński <kw@linux.com>
Signed-off-by: Kelvin Cao <kelvin.cao@microchip.com>
---
 drivers/pci/switch/switchtec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pci/switch/switchtec.c b/drivers/pci/switch/switchtec.c
index 6e2d6c5ea4b5..c36c1238c604 100644
--- a/drivers/pci/switch/switchtec.c
+++ b/drivers/pci/switch/switchtec.c
@@ -122,7 +122,7 @@ static void stuser_set_state(struct switchtec_user *stuser,
 {
 	/* requires the mrpc_mutex to already be held when called */
 
-	const char * const state_names[] = {
+	static const char * const state_names[] = {
 		[MRPC_IDLE] = "IDLE",
 		[MRPC_QUEUED] = "QUEUED",
 		[MRPC_RUNNING] = "RUNNING",
-- 
2.25.1


  parent reply	other threads:[~2021-11-19  0:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-19  0:38 [PATCH 0/2] Add Switchtec Gen4 automotive device IDs and a tweak Kelvin Cao
2021-11-19  0:38 ` [PATCH 1/2] Add device IDs for the Gen4 automotive variants Kelvin Cao
2021-11-19  0:38 ` Kelvin Cao [this message]
2021-11-19 16:49 ` [PATCH 0/2] Add Switchtec Gen4 automotive device IDs and a tweak Logan Gunthorpe
2021-11-21  6:38   ` Kelvin.Cao
2021-11-19 18:15 ` Bjorn Helgaas
2021-11-21  6:40   ` Kelvin.Cao

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=20211119003803.2333-3-kelvin.cao@microchip.com \
    --to=kelvin.cao@microchip.com \
    --cc=bhelgaas@google.com \
    --cc=kelvincao@outlook.com \
    --cc=kurt.schwemmer@microsemi.com \
    --cc=kw@linux.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=logang@deltatee.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.