[v2,04/12] cxl: Unify debug messages when calling devm_cxl_add_dport()

Message ID 20221018132341.76259-5-rrichter@amd.com
State New
Headers
Series cxl: Add support for Restricted CXL hosts (RCD mode) |

Commit Message

Robert Richter Oct. 18, 2022, 1:23 p.m. UTC
  CXL dports are added in a couple of code paths using devm_cxl_add_
dport(). Debug messages are individually generated, but are incomplete
and inconsistent. Change this by moving its generation to devm_cxl_
add_dport(). This unifies the messages and reduces code duplication.
Also, generate messages on failure. Use a __devm_cxl_add_dport()
wrapper to keep the readability of the error exits.

Signed-off-by: Robert Richter <rrichter@amd.com>
---
 drivers/cxl/acpi.c           |  7 ++----
 drivers/cxl/core/pci.c       |  2 --
 drivers/cxl/core/port.c      | 48 +++++++++++++++++++++++++-----------
 tools/testing/cxl/test/cxl.c |  8 +-----
 4 files changed, 37 insertions(+), 28 deletions(-)
  

Comments

Dan Williams Oct. 21, 2022, 12:32 a.m. UTC | #1
Robert Richter wrote:
> CXL dports are added in a couple of code paths using devm_cxl_add_
> dport(). Debug messages are individually generated, but are incomplete
> and inconsistent. Change this by moving its generation to devm_cxl_
> add_dport(). This unifies the messages and reduces code duplication.
> Also, generate messages on failure. Use a __devm_cxl_add_dport()
> wrapper to keep the readability of the error exits.

Looks good, I fixed up the wrapping of devm_cxl_add_dport() and one more
fixup below, but applied for v6.2.

> 
> Signed-off-by: Robert Richter <rrichter@amd.com>
> ---
>  drivers/cxl/acpi.c           |  7 ++----
>  drivers/cxl/core/pci.c       |  2 --
>  drivers/cxl/core/port.c      | 48 +++++++++++++++++++++++++-----------
>  tools/testing/cxl/test/cxl.c |  8 +-----
>  4 files changed, 37 insertions(+), 28 deletions(-)
> 
[..]
> diff --git a/tools/testing/cxl/test/cxl.c b/tools/testing/cxl/test/cxl.c
> index a072b2d3e726..c610625e8261 100644
> --- a/tools/testing/cxl/test/cxl.c
> +++ b/tools/testing/cxl/test/cxl.c
> @@ -582,14 +582,8 @@ static int mock_cxl_port_enumerate_dports(struct cxl_port *port)
>  		dport = devm_cxl_add_dport(port, &pdev->dev, pdev->id,
>  					   CXL_RESOURCE_NONE);
>  
> -		if (IS_ERR(dport)) {
> -			dev_err(dev, "failed to add dport: %s (%ld)\n",
> -				dev_name(&pdev->dev), PTR_ERR(dport));
> +		if (IS_ERR(dport))
>  			return PTR_ERR(dport);
> -		}
> -
> -		dev_dbg(dev, "add dport%d: %s\n", pdev->id,
> -			dev_name(&pdev->dev));

This hunk causes this new compile error:

tools/testing/cxl/test/cxl.c: In function ‘mock_cxl_port_enumerate_dports’:
tools/testing/cxl/test/cxl.c:559:24: error: unused variable ‘dev’ [-Werror=unused-variable]
  559 |         struct device *dev = &port->dev;
      |                        ^~~
cc1: all warnings being treated as errors

I fixed it up locally, but just double check that you are building
cxl_test if you touch tools/testing/cxl/:

    make M=tools/testing/cxl
  
Robert Richter Oct. 21, 2022, 9 a.m. UTC | #2
On 20.10.22 17:32:58, Dan Williams wrote:
> Robert Richter wrote:

> > diff --git a/tools/testing/cxl/test/cxl.c b/tools/testing/cxl/test/cxl.c
> > index a072b2d3e726..c610625e8261 100644
> > --- a/tools/testing/cxl/test/cxl.c
> > +++ b/tools/testing/cxl/test/cxl.c
> > @@ -582,14 +582,8 @@ static int mock_cxl_port_enumerate_dports(struct cxl_port *port)
> >  		dport = devm_cxl_add_dport(port, &pdev->dev, pdev->id,
> >  					   CXL_RESOURCE_NONE);
> >  
> > -		if (IS_ERR(dport)) {
> > -			dev_err(dev, "failed to add dport: %s (%ld)\n",
> > -				dev_name(&pdev->dev), PTR_ERR(dport));
> > +		if (IS_ERR(dport))
> >  			return PTR_ERR(dport);
> > -		}
> > -
> > -		dev_dbg(dev, "add dport%d: %s\n", pdev->id,
> > -			dev_name(&pdev->dev));
> 
> This hunk causes this new compile error:
> 
> tools/testing/cxl/test/cxl.c: In function ‘mock_cxl_port_enumerate_dports’:
> tools/testing/cxl/test/cxl.c:559:24: error: unused variable ‘dev’ [-Werror=unused-variable]
>   559 |         struct device *dev = &port->dev;
>       |                        ^~~
> cc1: all warnings being treated as errors
> 
> I fixed it up locally, but just double check that you are building
> cxl_test if you touch tools/testing/cxl/:
> 
>     make M=tools/testing/cxl

Right. Thanks for fixing. Will build test in the future.

-Robert
  

Patch

diff --git a/drivers/cxl/acpi.c b/drivers/cxl/acpi.c
index 767a91f44221..31e104f0210f 100644
--- a/drivers/cxl/acpi.c
+++ b/drivers/cxl/acpi.c
@@ -282,12 +282,9 @@  static int add_host_bridge_dport(struct device *match, void *arg)
 	}
 
 	dport = devm_cxl_add_dport(root_port, match, uid, ctx.chbcr);
-	if (IS_ERR(dport)) {
-		dev_err(host, "failed to add downstream port: %s\n",
-			dev_name(match));
+	if (IS_ERR(dport))
 		return PTR_ERR(dport);
-	}
-	dev_dbg(host, "add dport%llu: %s\n", uid, dev_name(match));
+
 	return 0;
 }
 
diff --git a/drivers/cxl/core/pci.c b/drivers/cxl/core/pci.c
index 9240df53ed87..0dbbe8d39b07 100644
--- a/drivers/cxl/core/pci.c
+++ b/drivers/cxl/core/pci.c
@@ -62,8 +62,6 @@  static int match_add_dports(struct pci_dev *pdev, void *data)
 	}
 	ctx->count++;
 
-	dev_dbg(&port->dev, "add dport%d: %s\n", port_num, dev_name(&pdev->dev));
-
 	return 0;
 }
 
diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c
index 9bfd01b4e5b5..0431ed860d8e 100644
--- a/drivers/cxl/core/port.c
+++ b/drivers/cxl/core/port.c
@@ -892,20 +892,10 @@  static void cxl_dport_unlink(void *data)
 	sysfs_remove_link(&port->dev.kobj, link_name);
 }
 
-/**
- * devm_cxl_add_dport - append downstream port data to a cxl_port
- * @port: the cxl_port that references this dport
- * @dport_dev: firmware or PCI device representing the dport
- * @port_id: identifier for this dport in a decoder's target list
- * @component_reg_phys: optional location of CXL component registers
- *
- * Note that dports are appended to the devm release action's of the
- * either the port's host (for root ports), or the port itself (for
- * switch ports)
- */
-struct cxl_dport *devm_cxl_add_dport(struct cxl_port *port,
-				     struct device *dport_dev, int port_id,
-				     resource_size_t component_reg_phys)
+static struct cxl_dport *__devm_cxl_add_dport(struct cxl_port *port,
+					      struct device *dport_dev,
+					      int port_id,
+					      resource_size_t component_reg_phys)
 {
 	char link_name[CXL_TARGET_STRLEN];
 	struct cxl_dport *dport;
@@ -957,6 +947,36 @@  struct cxl_dport *devm_cxl_add_dport(struct cxl_port *port,
 
 	return dport;
 }
+
+/**
+ * devm_cxl_add_dport - append downstream port data to a cxl_port
+ * @port: the cxl_port that references this dport
+ * @dport_dev: firmware or PCI device representing the dport
+ * @port_id: identifier for this dport in a decoder's target list
+ * @component_reg_phys: optional location of CXL component registers
+ *
+ * Note that dports are appended to the devm release action's of the
+ * either the port's host (for root ports), or the port itself (for
+ * switch ports)
+ */
+struct cxl_dport *devm_cxl_add_dport(struct cxl_port *port,
+				     struct device *dport_dev, int port_id,
+				     resource_size_t component_reg_phys)
+{
+	struct cxl_dport *dport;
+
+	dport = __devm_cxl_add_dport(port, dport_dev, port_id,
+				     component_reg_phys);
+	if (IS_ERR(dport)) {
+		dev_dbg(dport_dev, "failed to add dport to %s: %ld\n",
+			dev_name(&port->dev), PTR_ERR(dport));
+	} else {
+		dev_dbg(dport_dev, "dport added to %s\n",
+			dev_name(&port->dev));
+	}
+
+	return dport;
+}
 EXPORT_SYMBOL_NS_GPL(devm_cxl_add_dport, CXL);
 
 static int add_ep(struct cxl_ep *new)
diff --git a/tools/testing/cxl/test/cxl.c b/tools/testing/cxl/test/cxl.c
index a072b2d3e726..c610625e8261 100644
--- a/tools/testing/cxl/test/cxl.c
+++ b/tools/testing/cxl/test/cxl.c
@@ -582,14 +582,8 @@  static int mock_cxl_port_enumerate_dports(struct cxl_port *port)
 		dport = devm_cxl_add_dport(port, &pdev->dev, pdev->id,
 					   CXL_RESOURCE_NONE);
 
-		if (IS_ERR(dport)) {
-			dev_err(dev, "failed to add dport: %s (%ld)\n",
-				dev_name(&pdev->dev), PTR_ERR(dport));
+		if (IS_ERR(dport))
 			return PTR_ERR(dport);
-		}
-
-		dev_dbg(dev, "add dport%d: %s\n", pdev->id,
-			dev_name(&pdev->dev));
 	}
 
 	return 0;