All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vishal Aslot <os.vaslot@gmail.com>
To: bhelgaas@google.com, lukas@wunner.de
Cc: os.vaslot@gmail.com, linux-pci@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH] PCI:ibmphp: Eliminate unnecessary stack copies of struct slot
Date: Sat, 11 Sep 2021 22:42:29 -0500	[thread overview]
Message-ID: <20210912034229.1615885-1-os.vaslot@gmail.com> (raw)

Implementations of the following hotplug_slot_ops callbacks in ibmphp_core.c
create a copy of the struct slot with memcpy() on the stack. It is determined
that this overhead is unnecessary, because the only purpose of the stack copy
is to get the status back from ibmphp_hpc_readslot(). The status only needs
to be a "u8" variable. Therefore, this patch deletes the struct slot stack
variables and the related memcpy() calls from the following routines:

1. get_power_status()
2. get_attention_status()
3. get_latch_status()
4. get_adapter_status()

This patch also renames get_adapter_present() to get_adapter_status() in order
to match the hotplug_slot_ops name as well as the names of other status
routines.

Signed-off-by: Vishal Aslot <os.vaslot@gmail.com>
---

Why am I fixing this?
I found this issue in drivers/pci/hotplug/TODO, lines [21-24] and
decided to fix it.

 drivers/pci/hotplug/ibmphp_core.c | 40 +++++++++++++------------------
 1 file changed, 16 insertions(+), 24 deletions(-)

diff --git a/drivers/pci/hotplug/ibmphp_core.c b/drivers/pci/hotplug/ibmphp_core.c
index 17124254d897..9c4209185f07 100644
--- a/drivers/pci/hotplug/ibmphp_core.c
+++ b/drivers/pci/hotplug/ibmphp_core.c
@@ -263,7 +263,8 @@ static int get_attention_status(struct hotplug_slot *hotplug_slot, u8 *value)
 {
 	int rc = -ENODEV;
 	struct slot *pslot;
-	struct slot myslot;
+	u8 attention;
+	u8 ext_attention;
 
 	debug("get_attention_status - Entry hotplug_slot[%lx] pvalue[%lx]\n",
 					(ulong) hotplug_slot, (ulong) value);
@@ -271,14 +272,12 @@ static int get_attention_status(struct hotplug_slot *hotplug_slot, u8 *value)
 	ibmphp_lock_operations();
 	if (hotplug_slot) {
 		pslot = to_slot(hotplug_slot);
-		memcpy(&myslot, pslot, sizeof(struct slot));
-		rc = ibmphp_hpc_readslot(pslot, READ_SLOTSTATUS,
-					 &myslot.status);
+		rc = ibmphp_hpc_readslot(pslot, READ_SLOTSTATUS, &attention);
 		if (!rc)
 			rc = ibmphp_hpc_readslot(pslot, READ_EXTSLOTSTATUS,
-						 &myslot.ext_status);
+						 &ext_attention);
 		if (!rc)
-			*value = SLOT_ATTN(myslot.status, myslot.ext_status);
+			*value = SLOT_ATTN(attention, ext_attention);
 	}
 
 	ibmphp_unlock_operations();
@@ -290,18 +289,16 @@ static int get_latch_status(struct hotplug_slot *hotplug_slot, u8 *value)
 {
 	int rc = -ENODEV;
 	struct slot *pslot;
-	struct slot myslot;
+	u8 latch;
 
 	debug("get_latch_status - Entry hotplug_slot[%lx] pvalue[%lx]\n",
 					(ulong) hotplug_slot, (ulong) value);
 	ibmphp_lock_operations();
 	if (hotplug_slot) {
 		pslot = to_slot(hotplug_slot);
-		memcpy(&myslot, pslot, sizeof(struct slot));
-		rc = ibmphp_hpc_readslot(pslot, READ_SLOTSTATUS,
-					 &myslot.status);
+		rc = ibmphp_hpc_readslot(pslot, READ_SLOTSTATUS, &latch);
 		if (!rc)
-			*value = SLOT_LATCH(myslot.status);
+			*value = SLOT_LATCH(latch);
 	}
 
 	ibmphp_unlock_operations();
@@ -315,18 +312,16 @@ static int get_power_status(struct hotplug_slot *hotplug_slot, u8 *value)
 {
 	int rc = -ENODEV;
 	struct slot *pslot;
-	struct slot myslot;
+	u8 power;
 
 	debug("get_power_status - Entry hotplug_slot[%lx] pvalue[%lx]\n",
 					(ulong) hotplug_slot, (ulong) value);
 	ibmphp_lock_operations();
 	if (hotplug_slot) {
 		pslot = to_slot(hotplug_slot);
-		memcpy(&myslot, pslot, sizeof(struct slot));
-		rc = ibmphp_hpc_readslot(pslot, READ_SLOTSTATUS,
-					 &myslot.status);
+		rc = ibmphp_hpc_readslot(pslot, READ_SLOTSTATUS, &power);
 		if (!rc)
-			*value = SLOT_PWRGD(myslot.status);
+			*value = SLOT_PWRGD(power);
 	}
 
 	ibmphp_unlock_operations();
@@ -335,23 +330,20 @@ static int get_power_status(struct hotplug_slot *hotplug_slot, u8 *value)
 	return rc;
 }
 
-static int get_adapter_present(struct hotplug_slot *hotplug_slot, u8 *value)
+static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value)
 {
 	int rc = -ENODEV;
 	struct slot *pslot;
 	u8 present;
-	struct slot myslot;
 
 	debug("get_adapter_status - Entry hotplug_slot[%lx] pvalue[%lx]\n",
 					(ulong) hotplug_slot, (ulong) value);
 	ibmphp_lock_operations();
 	if (hotplug_slot) {
 		pslot = to_slot(hotplug_slot);
-		memcpy(&myslot, pslot, sizeof(struct slot));
-		rc = ibmphp_hpc_readslot(pslot, READ_SLOTSTATUS,
-					 &myslot.status);
+		rc = ibmphp_hpc_readslot(pslot, READ_SLOTSTATUS, &present);
 		if (!rc) {
-			present = SLOT_PRESENT(myslot.status);
+			present = SLOT_PRESENT(present);
 			if (present == HPC_SLOT_EMPTY)
 				*value = 0;
 			else
@@ -360,7 +352,7 @@ static int get_adapter_present(struct hotplug_slot *hotplug_slot, u8 *value)
 	}
 
 	ibmphp_unlock_operations();
-	debug("get_adapter_present - Exit rc[%d] value[%x]\n", rc, *value);
+	debug("get_adapter_status - Exit rc[%d] value[%x]\n", rc, *value);
 	return rc;
 }
 
@@ -1230,7 +1222,7 @@ const struct hotplug_slot_ops ibmphp_hotplug_slot_ops = {
 	.get_power_status =		get_power_status,
 	.get_attention_status =		get_attention_status,
 	.get_latch_status =		get_latch_status,
-	.get_adapter_status =		get_adapter_present,
+	.get_adapter_status =		get_adapter_status,
 /*	.get_max_adapter_speed =	get_max_adapter_speed,
 	.get_bus_name_status =		get_bus_name,
 */
-- 
2.27.0


                 reply	other threads:[~2021-09-12  3:44 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20210912034229.1615885-1-os.vaslot@gmail.com \
    --to=os.vaslot@gmail.com \
    --cc=bhelgaas@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lukas@wunner.de \
    /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.