diff mbox series

[2/2] Declare local array state_names as static

Message ID 20211119003803.2333-3-kelvin.cao@microchip.com (mailing list archive)
State Accepted
Delegated to: Bjorn Helgaas
Headers show
Series Add Switchtec Gen4 automotive device IDs and a tweak | expand

Commit Message

Kelvin Cao Nov. 19, 2021, 12:38 a.m. UTC
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 mbox series

Patch

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",