Skip to contentSkip to conversation

PCI: controller: Remove duplicate error message

PATCH In review Dejin Zheng 4 participants 10 messages May 26, 2020 – Jul 17, 2020

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI: controller: Remove duplicate error message

It will print an error message by itself when devm_pci_remap_cfg_resource() goes wrong. so remove the duplicate error message.

---
 drivers/pci/controller/cadence/pcie-cadence-host.c |  4 +---
 drivers/pci/controller/dwc/pcie-al.c               | 13 +++----------
 drivers/pci/controller/dwc/pcie-armada8k.c         |  1 -
 drivers/pci/controller/dwc/pcie-spear13xx.c        |  1 -
 4 files changed, 4 insertions(+), 15 deletions(-)
drivers/pci/controller/cadence/pcie-cadence-host.c +1 -3
index 8c2543f28ba0..60bfb5bcbd37 100644
@@ -234,10 +234,8 @@ int cdns_pcie_host_setup(struct cdns_pcie_rc *rc)
 
 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "cfg");
 	rc->cfg_base = devm_pci_remap_cfg_resource(dev, res);
-	if (IS_ERR(rc->cfg_base)) {
-		dev_err(dev, "missing \"cfg\"\n");
+	if (IS_ERR(rc->cfg_base))
 		return PTR_ERR(rc->cfg_base);
-	}
 	rc->cfg_res = res;
 
 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mem");
drivers/pci/controller/dwc/pcie-al.c +3 -10
index 270868f3859a..d57d4ee15848 100644
@@ -67,13 +67,8 @@ static int al_pcie_init(struct pci_config_window *cfg)
 	dev_dbg(dev, "Root port dbi res: %pR\n", res);
 
 	al_pcie->dbi_base = devm_pci_remap_cfg_resource(dev, res);
-	if (IS_ERR(al_pcie->dbi_base)) {
-		long err = PTR_ERR(al_pcie->dbi_base);
-
-		dev_err(dev, "couldn't remap dbi base %pR (err:%ld)\n",
-			res, err);
-		return err;
-	}
+	if (IS_ERR(al_pcie->dbi_base))
+		return PTR_ERR(al_pcie->dbi_base);
 
 	cfg->priv = al_pcie;
 
@@ -408,10 +403,8 @@ static int al_pcie_probe(struct platform_device *pdev)
 
 	dbi_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dbi");
 	pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_res);
-	if (IS_ERR(pci->dbi_base)) {
-		dev_err(dev, "couldn't remap dbi base %pR\n", dbi_res);
+	if (IS_ERR(pci->dbi_base))
 		return PTR_ERR(pci->dbi_base);
-	}
 
 	ecam_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "config");
 	if (!ecam_res) {
drivers/pci/controller/dwc/pcie-armada8k.c +0 -1
index 49596547e8c2..896b95d6917c 100644
@@ -317,7 +317,6 @@ static int armada8k_pcie_probe(struct platform_device *pdev)
 	base = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ctrl");
 	pci->dbi_base = devm_pci_remap_cfg_resource(dev, base);
 	if (IS_ERR(pci->dbi_base)) {
-		dev_err(dev, "couldn't remap regs base %p\n", base);
 		ret = PTR_ERR(pci->dbi_base);
 		goto fail_clkreg;
 	}
drivers/pci/controller/dwc/pcie-spear13xx.c +0 -1
index 7d0cdfd8138b..cdfde1bd7d8e 100644
@@ -273,7 +273,6 @@ static int spear13xx_pcie_probe(struct platform_device *pdev)
 	dbi_base = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dbi");
 	pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
 	if (IS_ERR(pci->dbi_base)) {
-		dev_err(dev, "couldn't remap dbi base %p\n", dbi_base);
 		ret = PTR_ERR(pci->dbi_base);
 		goto fail_clk;
 	}
Signature · 1 line
2.25.0
#1 lore raw
Quoted 10 lines · Dejin Zheng

CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.

It will print an error message by itself when devm_pci_remap_cfg_resource() goes wrong. so remove the duplicate error message.

It seems like that in the first error case in devm_pci_remap_cfg_resource(), the print will be less indicative. Could you please share an example print log with the duplicate print?

Thanks,
Jonathan

#2 lore raw
Quoted 7 lines · Jonathan
Quoted 6 lines · Dejin Zheng

CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.

Quoted 9 lines
Quoted 4 lines

It will print an error message by itself when devm_pci_remap_cfg_resource() goes wrong. so remove the duplicate error message.

It seems like that in the first error case in devm_pci_remap_cfg_resource(), the print will be less indicative. Could you please share an example print log with the duplicate print?

Hi Jonathan:

Thank you very much for using your precious time to review my patch.

I did not have this log and just found it by review codes. the function of devm_pci_remap_cfg_resource() is designed to handle error messages by itself. and Its recommended usage is as follows in the function description

	base = devm_pci_remap_cfg_resource(&pdev->dev, res);
	if (IS_ERR(base))
		return PTR_ERR(base);

In fact, I think its error handling is clear enough, It just goes wrong in three places, as follows:

void __iomem *devm_pci_remap_cfg_resource(struct device *dev,
struct resource *res)

{
        resource_size_t size;
        const char *name;
        void __iomem *dest_ptr;

        BUG_ON(!dev);

        if (!res || resource_type(res) != IORESOURCE_MEM) {
                dev_err(dev, "invalid resource\n");
                return IOMEM_ERR_PTR(-EINVAL);
        }

        size = resource_size(res);
        name = res->name ?: dev_name(dev);

        if (!devm_request_mem_region(dev, res->start, size, name)) {
                dev_err(dev, "can't request region for resource %pR\n", res);
                return IOMEM_ERR_PTR(-EBUSY);
        }

        dest_ptr = devm_pci_remap_cfgspace(dev, res->start, size);
        if (!dest_ptr) {
                dev_err(dev, "ioremap failed for resource %pR\n", res);
                devm_release_mem_region(dev, res->start, size);
                dest_ptr = IOMEM_ERR_PTR(-ENOMEM);
        }

        return dest_ptr;
}

BR,
Dejin

Quoted 2 lines

Thanks,
Jonathan

#3 lore raw
Quoted 27 lines · Dejin Zheng

CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.

Quoted 14 lines · Jonathan
Quoted 8 lines · Dejin Zheng

CAUTION: This email originated from outside of the organization. Do
not click links or open attachments unless you can confirm the sender
and know the content is safe.

Quoted 4 lines

It will print an error message by itself when devm_pci_remap_cfg_resource() goes wrong. so remove the duplicate error message.

Quoted 5 lines

It seems like that in the first error case in devm_pci_remap_cfg_resource(), the print will be less indicative. Could
you please share an example print log with the duplicate print?

Quoted 4 lines

Hi Jonathan:

Thank you very much for using your precious time to review my patch.

Sure, no problem.

Quoted 11 lines

I did not have this log and just found it by review codes. the function
of devm_pci_remap_cfg_resource() is designed to handle error messages by
itself. and Its recommended usage is as follows in the function description

        base = devm_pci_remap_cfg_resource(&pdev->dev, res);
        if (IS_ERR(base))
                return PTR_ERR(base);

I assume that the recommended usage's main intent was to point out that IS_ERR() should be used, but this is mainly speculation.

Quoted 6 lines

In fact, I think its error handling is clear enough, It just goes wrong
in three places, as follows:

void __iomem *devm_pci_remap_cfg_resource(struct device *dev,
struct resource *res)

Quoted 12 lines
{
        resource_size_t size;
        const char *name;
        void __iomem *dest_ptr;

        BUG_ON(!dev);

        if (!res || resource_type(res) != IORESOURCE_MEM) {
                dev_err(dev, "invalid resource\n");
                return IOMEM_ERR_PTR(-EINVAL);
        }

In the above error case there is no indication of which resource failed (mainly relevant if the resource name is missing in the devicetree, since in the drivers you are changing platform_get_resource_byname() is mostly used). In the existing drivers' code, on return from this function in this case, the name would be printed by the caller.

Quoted 9 lines
        size = resource_size(res);
        name = res->name ?: dev_name(dev);

        if (!devm_request_mem_region(dev, res->start, size, name)) {
                dev_err(dev, "can't request region for resource
%pR\n", res);
                return IOMEM_ERR_PTR(-EBUSY);
        }
Quoted 8 lines
        dest_ptr = devm_pci_remap_cfgspace(dev, res->start, size);
        if (!dest_ptr) {
                dev_err(dev, "ioremap failed for resource %pR\n",
res);
                devm_release_mem_region(dev, res->start, size);
                dest_ptr = IOMEM_ERR_PTR(-ENOMEM);
        }

The other 2 error cases as well don't print the resource name as far as I recall (they will at least print the resource start/end).

Quoted 8 lines
        return dest_ptr;
}

BR,
Dejin

Quoted 2 lines

Thanks,
Jonathan

reviewer
#4 lore raw
Quoted 42 lines · Jonathan
Quoted 27 lines · Dejin Zheng

CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.

Quoted 14 lines · Jonathan
Quoted 8 lines · Dejin Zheng

CAUTION: This email originated from outside of the organization. Do
not click links or open attachments unless you can confirm the sender
and know the content is safe.

Quoted 4 lines

It will print an error message by itself when devm_pci_remap_cfg_resource() goes wrong. so remove the duplicate error message.

Quoted 5 lines

It seems like that in the first error case in devm_pci_remap_cfg_resource(), the print will be less indicative. Could
you please share an example print log with the duplicate print?

Quoted 4 lines

Hi Jonathan:

Thank you very much for using your precious time to review my patch.

Sure, no problem.

Quoted 7 lines

I did not have this log and just found it by review codes. the function
of devm_pci_remap_cfg_resource() is designed to handle error messages by
itself. and Its recommended usage is as follows in the function description

Quoted 6 lines
Quoted 4 lines
        base = devm_pci_remap_cfg_resource(&pdev->dev, res);
        if (IS_ERR(base))
                return PTR_ERR(base);

I assume that the recommended usage's main intent was to point out that IS_ERR() should be used, but this is mainly speculation.

It's generally preferred to print error messages in a called function rather than in return error handling.

Quoted 18 lines
Quoted 6 lines

In fact, I think its error handling is clear enough, It just goes wrong
in three places, as follows:

void __iomem *devm_pci_remap_cfg_resource(struct device *dev,
struct resource *res)

Quoted 12 lines
{
        resource_size_t size;
        const char *name;
        void __iomem *dest_ptr;

        BUG_ON(!dev);

        if (!res || resource_type(res) != IORESOURCE_MEM) {
                dev_err(dev, "invalid resource\n");
                return IOMEM_ERR_PTR(-EINVAL);
        }
Quoted 5 lines

In the above error case there is no indication of which resource failed (mainly relevant if the resource name is missing in the devicetree, since in the drivers you are changing platform_get_resource_byname() is mostly used). In the existing drivers' code, on return from this function in this case, the name would be printed by the caller.

A driver should only have one call to devm_pci_remap_cfg_resource() as there's only 1 config space. However, it looks like this function is frequently used on what is not config space which is a bigger issue.

If this error happens, it's almost always going to be a NULL ptr as platform_get_resource_byname() would have set IORESOURCE_MEM. Perhaps a WARN here so you get a backtrace to the caller location.

Quoted 17 lines
Quoted 9 lines
        size = resource_size(res);
        name = res->name ?: dev_name(dev);

        if (!devm_request_mem_region(dev, res->start, size, name)) {
                dev_err(dev, "can't request region for resource
%pR\n", res);
                return IOMEM_ERR_PTR(-EBUSY);
        }
Quoted 8 lines
        dest_ptr = devm_pci_remap_cfgspace(dev, res->start, size);
        if (!dest_ptr) {
                dev_err(dev, "ioremap failed for resource %pR\n",
res);
                devm_release_mem_region(dev, res->start, size);
                dest_ptr = IOMEM_ERR_PTR(-ENOMEM);
        }
Quoted 2 lines

The other 2 error cases as well don't print the resource name as far as I recall (they will at least print the resource start/end).

Start/end are what are important for why either of these functions failed.

But sure, we could add 'name' here. That's a separate patch IMO.

Rob

#5 lore raw

On Tue, Jun 02, 2020 at 09:01:13AM -0600, Rob Herring wrote:

[...]

Quoted 24 lines
Quoted 18 lines
Quoted 6 lines

In fact, I think its error handling is clear enough, It just goes wrong
in three places, as follows:

void __iomem *devm_pci_remap_cfg_resource(struct device *dev,
struct resource *res)

Quoted 12 lines
{
        resource_size_t size;
        const char *name;
        void __iomem *dest_ptr;

        BUG_ON(!dev);

        if (!res || resource_type(res) != IORESOURCE_MEM) {
                dev_err(dev, "invalid resource\n");
                return IOMEM_ERR_PTR(-EINVAL);
        }
Quoted 5 lines

In the above error case there is no indication of which resource failed (mainly relevant if the resource name is missing in the devicetree, since in the drivers you are changing platform_get_resource_byname() is mostly used). In the existing drivers' code, on return from this function in this case, the name would be printed by the caller.

Quoted 3 lines

A driver should only have one call to devm_pci_remap_cfg_resource() as there's only 1 config space. However, it looks like this function is frequently used on what is not config space which is a bigger issue.

That certainly is and should be fixed.

Quoted 3 lines

If this error happens, it's almost always going to be a NULL ptr as platform_get_resource_byname() would have set IORESOURCE_MEM. Perhaps a WARN here so you get a backtrace to the caller location.

+1

Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
        size = resource_size(res);
        name = res->name ?: dev_name(dev);

        if (!devm_request_mem_region(dev, res->start, size, name)) {
                dev_err(dev, "can't request region for resource
%pR\n", res);
                return IOMEM_ERR_PTR(-EBUSY);
        }

        dest_ptr = devm_pci_remap_cfgspace(dev, res->start, size);
        if (!dest_ptr) {
                dev_err(dev, "ioremap failed for resource %pR\n",
res);
                devm_release_mem_region(dev, res->start, size);
                dest_ptr = IOMEM_ERR_PTR(-ENOMEM);
        }
Quoted 7 lines
Quoted 2 lines

The other 2 error cases as well don't print the resource name as far as I recall (they will at least print the resource start/end).

Start/end are what are important for why either of these functions failed.

But sure, we could add 'name' here. That's a separate patch IMO.

I agree. In sum, I think it is OK to proceed with this patch, provided we send follow-ups as discussed here, are we in agreement ?

Lorenzo

#6 lore raw
Quoted 11 lines · Lorenzo Pieralisi

On Tue, Jun 02, 2020 at 09:01:13AM -0600, Rob Herring wrote:

[...]

Quoted 7 lines
Quoted 2 lines

The other 2 error cases as well don't print the resource name as far as I recall (they will at least print the resource start/end).

Start/end are what are important for why either of these functions failed.

But sure, we could add 'name' here. That's a separate patch IMO.

Hi Lorenzo, Bob and Jonathan:

Thank you very much for helping me review this patch, I sent a new patch for print the resource name when the request memory region or remapping of configuration space fails. and it is here:
https://patchwork.kernel.org/patch/11657801/

BR,
Dejin

Quoted 5 lines

I agree. In sum, I think it is OK to proceed with this patch, provided we send follow-ups as discussed here, are we in agreement ?

Lorenzo

#7 lore raw
Quoted 8 lines · Dejin Zheng
Quoted 7 lines · Lorenzo Pieralisi

On Tue, Jun 02, 2020 at 09:01:13AM -0600, Rob Herring wrote:

[...]

Quoted 3 lines
Quoted 2 lines

The other 2 error cases as well don't print the resource name as far as I recall (they will at least print the resource start/end).

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

Start/end are what are important for why either of these functions failed.

But sure, we could add 'name' here. That's a separate patch IMO.

Hi Lorenzo, Bob and Jonathan:

Thank you very much for helping me review this patch,

I merge this patch in pci/misc, thanks.

Quoted 3 lines

I sent a new patch for print the resource name when the request memory region or remapping of configuration space fails. and it is here:
https://patchwork.kernel.org/patch/11657801/

We will get to it soon.

Lorenzo

#8 lore raw
Quoted 20 lines · Lorenzo Pieralisi
Quoted 8 lines · Dejin Zheng
Quoted 7 lines · Lorenzo Pieralisi

On Tue, Jun 02, 2020 at 09:01:13AM -0600, Rob Herring wrote:

[...]

Quoted 3 lines
Quoted 2 lines

The other 2 error cases as well don't print the resource name as far as I recall (they will at least print the resource start/end).

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

Start/end are what are important for why either of these functions failed.

But sure, we could add 'name' here. That's a separate patch IMO.

Hi Lorenzo, Bob and Jonathan:

Thank you very much for helping me review this patch,

I merge this patch in pci/misc, thanks.

Quoted 7 lines
Quoted 3 lines

I sent a new patch for print the resource name when the request memory region or remapping of configuration space fails. and it is here:
https://patchwork.kernel.org/patch/11657801/

We will get to it soon.

Lorenzo

Lorenzo, Thanks very much!

Dejin

reviewer Reviewed-by on v1 1/1
#9 lore raw
In reply to Dejin Zheng
Quoted 4 lines · Dejin Zheng

It will print an error message by itself when devm_pci_remap_cfg_resource() goes wrong. so remove the duplicate error message.

Quoted 8 lines
---
 drivers/pci/controller/cadence/pcie-cadence-host.c |  4 +---
 drivers/pci/controller/dwc/pcie-al.c               | 13 +++----------
 drivers/pci/controller/dwc/pcie-armada8k.c         |  1 -
 drivers/pci/controller/dwc/pcie-spear13xx.c        |  1 -
 4 files changed, 4 insertions(+), 15 deletions(-)