lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 18 Nov 2021 16:38:03 -0800
From:   Kelvin Cao <kelvin.cao@...rochip.com>
To:     Kurt Schwemmer <kurt.schwemmer@...rosemi.com>,
        Logan Gunthorpe <logang@...tatee.com>,
        Bjorn Helgaas <bhelgaas@...gle.com>,
        Krzysztof Wilczyński <kw@...ux.com>,
        <linux-pci@...r.kernel.org>, <linux-kernel@...r.kernel.org>
CC:     Kelvin Cao <kelvin.cao@...rochip.com>, <kelvincao@...look.com>
Subject: [PATCH 2/2] Declare local array state_names as static

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@...ux.com>
Signed-off-by: Kelvin Cao <kelvin.cao@...rochip.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ