RE: [PATCH 04/15] cxl: Unify debug messages when calling devm_cxl_add_dport()

From: Dan Williams
Date: Thu Sep 08 2022 - 01:55:58 EST


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@xxxxxxx>
> ---
> 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.