Message ID | 20220831081603.3415-5-rrichter@amd.com |
---|---|
State | Superseded |
Delegated to: | Dan Williams |
Headers | show |
Series | cxl: Add support for Restricted CXL hosts (RCD mode) | expand |
On Wed, 31 Aug 2022, 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. > >Signed-off-by: Robert Richter <rrichter@amd.com> Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>
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. > > Signed-off-by: Robert Richter <rrichter@amd.com> > --- > drivers/cxl/acpi.c | 7 ++----- > drivers/cxl/core/pci.c | 2 -- > drivers/cxl/core/port.c | 28 ++++++++++++++++++++-------- > tools/testing/cxl/test/cxl.c | 8 +------- > 4 files changed, 23 insertions(+), 22 deletions(-) > > 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 8604cda88787..61e9915162d5 100644 > --- a/drivers/cxl/core/port.c > +++ b/drivers/cxl/core/port.c > @@ -914,12 +914,16 @@ struct cxl_dport *devm_cxl_add_dport(struct cxl_port *port, > } > > if (snprintf(link_name, CXL_TARGET_STRLEN, "dport%d", port_id) >= > - CXL_TARGET_STRLEN) > - return ERR_PTR(-EINVAL); > + CXL_TARGET_STRLEN) { > + rc = -EINVAL; > + goto err; > + } > > dport = devm_kzalloc(host, sizeof(*dport), GFP_KERNEL); > - if (!dport) > - return ERR_PTR(-ENOMEM); > + if (!dport) { > + rc = -ENOMEM; > + goto err; > + } Similar comment as before of using a goto just to ensure the log message is called, I suspect a wrapper to do the logging ends up with less code thrash.
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 8604cda88787..61e9915162d5 100644 --- a/drivers/cxl/core/port.c +++ b/drivers/cxl/core/port.c @@ -914,12 +914,16 @@ struct cxl_dport *devm_cxl_add_dport(struct cxl_port *port, } if (snprintf(link_name, CXL_TARGET_STRLEN, "dport%d", port_id) >= - CXL_TARGET_STRLEN) - return ERR_PTR(-EINVAL); + CXL_TARGET_STRLEN) { + rc = -EINVAL; + goto err; + } dport = devm_kzalloc(host, sizeof(*dport), GFP_KERNEL); - if (!dport) - return ERR_PTR(-ENOMEM); + if (!dport) { + rc = -ENOMEM; + goto err; + } dport->dport = dport_dev; dport->port_id = port_id; @@ -930,22 +934,30 @@ struct cxl_dport *devm_cxl_add_dport(struct cxl_port *port, rc = add_dport(port, dport); cond_cxl_root_unlock(port); if (rc) - return ERR_PTR(rc); + goto err; get_device(dport_dev); rc = devm_add_action_or_reset(host, cxl_dport_remove, dport); if (rc) - return ERR_PTR(rc); + goto err; rc = sysfs_create_link(&port->dev.kobj, &dport_dev->kobj, link_name); if (rc) - return ERR_PTR(rc); + goto err; rc = devm_add_action_or_reset(host, cxl_dport_unlink, dport); if (rc) - return ERR_PTR(rc); + goto err; + + dev_dbg(&port->dev, "added %s (%s) as dport of device %s\n", + dev_name(&port->dev), link_name, dev_name(dport_dev)); return dport; +err: + dev_dbg(&port->dev, "failed to add %s (%s) as dport of device %s: %d\n", + dev_name(&port->dev), link_name, dev_name(dport_dev), rc); + + return ERR_PTR(rc); } EXPORT_SYMBOL_NS_GPL(devm_cxl_add_dport, CXL); 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;
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. Signed-off-by: Robert Richter <rrichter@amd.com> --- drivers/cxl/acpi.c | 7 ++----- drivers/cxl/core/pci.c | 2 -- drivers/cxl/core/port.c | 28 ++++++++++++++++++++-------- tools/testing/cxl/test/cxl.c | 8 +------- 4 files changed, 23 insertions(+), 22 deletions(-)