Re: [PATCH v7 3/5] Add debugfs based silicon debug support in DWC
From: Krzysztof Wilczyński
Date: Wed Mar 05 2025 - 16:57:45 EST
> > > > Even though debugfs_init() failure is not supposed to fail the probe(),
> > > > dwc_pcie_rasdes_debugfs_init() has a devm_kzalloc() and propagating that
> > > > failure would be canolically correct IMO.
> > >
> > > I'm not sure about this. What's the requirement to propagate
> > > devm_kzalloc() failures? I think devres will free any allocs that
> > > were successful regardless.
> > >
> > > IIUC, we resolved the Gray Hawk Single issue by changing
> > > dwc_pcie_rasdes_debugfs_init() to return success without doing
> > > anything when there's no RAS DES Capability.
> > >
> > > But dwc_pcie_debugfs_init() can still return failure, and that still
> > > causes dw_pcie_ep_init_registers() to fail, which breaks the "don't
> > > propagate debugfs issues upstream" rule:
> > >
> > > int dw_pcie_ep_init_registers(struct dw_pcie_ep *ep)
> > > {
> > > ...
> > > ret = dwc_pcie_debugfs_init(pci);
> > > if (ret)
> > > goto err_remove_edma;
> > >
> > > return 0;
> > >
> > > err_remove_edma:
> > > dw_pcie_edma_remove(pci);
> > >
> > > return ret;
> > > }
> > >
> > > We can say that kzalloc() failure should "never" happen, and therefore
> > > it's OK to fail the driver probe if it happens, but that doesn't seem
> > > like a strong argument for breaking the "don't propagate debugfs
> > > issues" rule. And someday there may be other kinds of failures from
> > > dwc_pcie_debugfs_init().
> > >
> >
> > Fine with me. I was not too sure about propagating failure either.
>
> What if we do this?
>
> diff --git i/drivers/pci/controller/dwc/pcie-designware-debugfs.c w/drivers/pci/controller/dwc/pcie-designware-debugfs.c
> index 586a9d107434..fddf71f014c4 100644
> --- i/drivers/pci/controller/dwc/pcie-designware-debugfs.c
> +++ w/drivers/pci/controller/dwc/pcie-designware-debugfs.c
> @@ -162,7 +162,7 @@ void dwc_pcie_debugfs_deinit(struct dw_pcie *pci)
> debugfs_remove_recursive(pci->debugfs->debug_dir);
> }
>
> -int dwc_pcie_debugfs_init(struct dw_pcie *pci)
> +void dwc_pcie_debugfs_init(struct dw_pcie *pci)
> {
> char dirname[DWC_DEBUGFS_BUF_MAX];
> struct device *dev = pci->dev;
> @@ -174,17 +174,15 @@ int dwc_pcie_debugfs_init(struct dw_pcie *pci)
> snprintf(dirname, DWC_DEBUGFS_BUF_MAX, "dwc_pcie_%s", dev_name(dev));
> dir = debugfs_create_dir(dirname, NULL);
> debugfs = devm_kzalloc(dev, sizeof(*debugfs), GFP_KERNEL);
> - if (!debugfs)
> - return -ENOMEM;
> + if (!debugfs) {
> + dev_err(dev, "failed to allocate memory for debugfs\n");
> + return;
> + }
>
> debugfs->debug_dir = dir;
> pci->debugfs = debugfs;
> err = dwc_pcie_rasdes_debugfs_init(pci, dir);
> - if (err) {
> - dev_err(dev, "failed to initialize RAS DES debugfs, err=%d\n",
> - err);
> - return err;
> - }
> -
> - return 0;
> + if (err)
> + dev_warn(dev, "failed to initialize RAS DES debugfs, err=%d",
> + err);
> }
> diff --git i/drivers/pci/controller/dwc/pcie-designware-ep.c w/drivers/pci/controller/dwc/pcie-designware-ep.c
> index c6e76a07c2c9..11ff292ca87d 100644
> --- i/drivers/pci/controller/dwc/pcie-designware-ep.c
> +++ w/drivers/pci/controller/dwc/pcie-designware-ep.c
> @@ -838,9 +838,7 @@ int dw_pcie_ep_init_registers(struct dw_pcie_ep *ep)
>
> dw_pcie_ep_init_non_sticky_registers(pci);
>
> - ret = dwc_pcie_debugfs_init(pci);
> - if (ret)
> - goto err_remove_edma;
> + dwc_pcie_debugfs_init(pci);
>
> return 0;
>
> diff --git i/drivers/pci/controller/dwc/pcie-designware-host.c w/drivers/pci/controller/dwc/pcie-designware-host.c
> index 2081e8c72d12..6501fb062c70 100644
> --- i/drivers/pci/controller/dwc/pcie-designware-host.c
> +++ w/drivers/pci/controller/dwc/pcie-designware-host.c
> @@ -548,9 +548,7 @@ int dw_pcie_host_init(struct dw_pcie_rp *pp)
> if (pp->ops->post_init)
> pp->ops->post_init(pp);
>
> - ret = dwc_pcie_debugfs_init(pci);
> - if (ret)
> - goto err_stop_link;
> + dwc_pcie_debugfs_init(pci);
>
> return 0;
>
> diff --git i/drivers/pci/controller/dwc/pcie-designware.h w/drivers/pci/controller/dwc/pcie-designware.h
> index 7f9807d4e5de..dd129718fb41 100644
> --- i/drivers/pci/controller/dwc/pcie-designware.h
> +++ w/drivers/pci/controller/dwc/pcie-designware.h
> @@ -815,12 +815,11 @@ dw_pcie_ep_get_func_from_ep(struct dw_pcie_ep *ep, u8 func_no)
> #endif
>
> #ifdef CONFIG_PCIE_DW_DEBUGFS
> -int dwc_pcie_debugfs_init(struct dw_pcie *pci);
> +void dwc_pcie_debugfs_init(struct dw_pcie *pci);
> void dwc_pcie_debugfs_deinit(struct dw_pcie *pci);
> #else
> -static inline int dwc_pcie_debugfs_init(struct dw_pcie *pci)
> +static inline void dwc_pcie_debugfs_init(struct dw_pcie *pci)
> {
> - return 0;
> }
> static inline void dwc_pcie_debugfs_deinit(struct dw_pcie *pci)
> {
>
> I think this would be fine, especially given the rules around debugfs and
> a quick look around Git history to see what the prefernce would be typically.
Changed dev_warn() to dev_err() per Bjorn's feedback off mailing list,
and squashed against the current code on the branch.
Thank you!
Krzysztof