Linux CXL
 help / color / mirror / Atom feed
* [PATCH v3] cxl/core/pci: Move reading of control register to immediately before usage
@ 2024-06-04  3:21 Foryun Ma
  2024-06-05 12:15 ` Jonathan Cameron
  2024-06-05 15:35 ` Alison Schofield
  0 siblings, 2 replies; 3+ messages in thread
From: Foryun Ma @ 2024-06-04  3:21 UTC (permalink / raw)
  To: alison.schofield
  Cc: dan.j.williams, angus.chen, dave.jiang, dave, foryun.ma,
	linux-cxl, rrichter

Relocate the reading of the DVSEC control register to immediately
before usage and avoid unnecessary PCI config access from the read
if DVSEC capability check, hdm_count check, or device validity check
results in failure.

Signed-off-by: Foryun Ma <foryun.ma@jaguarmicro.com>

---
V2->V3: move the check to after the comment
V1->V2: change the subject and commit log, suggested by dave.jiang
	and add change log, suggested by Alison Schofield
---
 drivers/cxl/core/pci.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/cxl/core/pci.c b/drivers/cxl/core/pci.c
index 8567dd11eaac..a663e7566c48 100644
--- a/drivers/cxl/core/pci.c
+++ b/drivers/cxl/core/pci.c
@@ -338,10 +338,6 @@ int cxl_dvsec_rr_decode(struct device *dev, int d,
 	if (rc)
 		return rc;
 
-	rc = pci_read_config_word(pdev, d + CXL_DVSEC_CTRL_OFFSET, &ctrl);
-	if (rc)
-		return rc;
-
 	if (!(cap & CXL_DVSEC_MEM_CAPABLE)) {
 		dev_dbg(dev, "Not MEM Capable\n");
 		return -ENXIO;
@@ -368,6 +364,10 @@ int cxl_dvsec_rr_decode(struct device *dev, int d,
 	 * disabled, and they will remain moot after the HDM Decoder
 	 * capability is enabled.
 	 */
+	rc = pci_read_config_word(pdev, d + CXL_DVSEC_CTRL_OFFSET, &ctrl);
+	if (rc)
+		return rc;
+
 	info->mem_enabled = FIELD_GET(CXL_DVSEC_MEM_ENABLE, ctrl);
 	if (!info->mem_enabled)
 		return 0;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-06-05 15:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-04  3:21 [PATCH v3] cxl/core/pci: Move reading of control register to immediately before usage Foryun Ma
2024-06-05 12:15 ` Jonathan Cameron
2024-06-05 15:35 ` Alison Schofield

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox