Skip to contentSkip to conversation

PCI: dwc: solve returning success but actually failed

PATCH2 Applied Zhangjiantao(Kirin,Nanjing) 3 participants 5 messages Mar 8, 2022 – Apr 8, 2022

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

When dma_mapping_error() returns error because of no enough memory available, dw_pcie_host_init() will return success, which will mislead the callers.

Fixes 07940c369a6b ("PCI: dwc: Fix MSI page leakage in suspend/resume")
---
  drivers/pci/controller/dwc/pcie-designware-host.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/drivers/pci/controller/dwc/pcie-designware-host.c index f4755f3a03be..9dcb51728dd1 100644

drivers/pci/controller/dwc/pcie-designware-host.c +2 -1
@@ -390,7 +390,8 @@ int dw_pcie_host_init(struct pcie_port *pp)
                                sizeof(pp->msi_msg),
                                DMA_FROM_DEVICE,
                                DMA_ATTR_SKIP_CPU_SYNC);
-            if (dma_mapping_error(pci->dev, pp->msi_data)) {
+            ret = dma_mapping_error(pci->dev, pp->msi_data);
+            if (ret) {
                  dev_err(pci->dev, "Failed to map MSI data\n");
                  pp->msi_data = 0;
                  goto err_free_msi;

--
2.17.1

Jiantao Zhang

Quoted 32 lines · Bjorn Helgaas
Quoted 1 line · Zhangjiantao(Kirin,Nanjing)

When dma_mapping_error returns error because of no enough memory available, dw_pcie_host_init will return success, which will mislead the callers.

Wrap to fit in 75 columns, add "()" after function names.

Quoted 13 lines
---
   drivers/pci/controller/dwc/pcie-designware-host.c | 1 +
   1 file changed, 1 insertion(+)
drivers/pci/controller/dwc/pcie-designware-host.c +0 -0
index f4755f3a03be..ac691d733848 100644

drivers/pci/controller/dwc/pcie-designware-host.c int dw_pcie_host_init(struct pcie_port *pp) · line 396

Quoted 4 lines
drivers/pci/controller/dwc/pcie-designware-host.c +1 -0
@@ -393,6 +393,7 @@ int dw_pcie_host_init(struct pcie_port *pp)
               if (dma_mapping_error(pci->dev, pp->msi_data)) {
                   dev_err(pci->dev, "Failed to map MSI data\n");
                   pp->msi_data = 0;
+                ret = -1;

We should save the return value from dma_mapping_error() and return *that*, not -1.

Whitespace error (indent with tabs, same as the surrounding code).

Quoted 6 lines
drivers/pci/controller/dwc/pcie-designware-host.c +0 -1
                   goto err_free_msi;
               }
           }
--

2.17.1

.

reviewer
#1 lore raw
Quoted 2 lines · Zhangjiantao(Kirin,Nanjing)

When dma_mapping_error() returns error because of no enough memory available, dw_pcie_host_init() will return success, which will mislead the callers.

Again, wrap long lines. And please reword the subject as I previously suggested.

It should be 'PATCH v2', not 'PATCH2' in the subject. 'git send-email -v2' does that for you.

Quoted 3 lines
Fixes 07940c369a6b ("PCI: dwc: Fix MSI page leakage in suspend/resume")

Drop the blank line here.

Quoted 1 line

As you are sending the patch, your S-o-b goes last. And the author name still doesn't match here: 'Jiantao Zhang' vs. 'Zhangjiantao(Kirin,Nanjing)'

Quoted 23 lines
---
  drivers/pci/controller/dwc/pcie-designware-host.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/pci/controller/dwc/pcie-designware-host.c +2 -2
index f4755f3a03be..9dcb51728dd1 100644
@@ -390,7 +390,8 @@ int dw_pcie_host_init(struct pcie_port *pp)
                                sizeof(pp->msi_msg),
                                DMA_FROM_DEVICE,
                                DMA_ATTR_SKIP_CPU_SYNC);
-            if (dma_mapping_error(pci->dev, pp->msi_data)) {
+            ret = dma_mapping_error(pci->dev, pp->msi_data);
+            if (ret) {
                  dev_err(pci->dev, "Failed to map MSI data\n");
                  pp->msi_data = 0;
                  goto err_free_msi;
--

2.17.1

Quoted 4 lines

Jiantao Zhang

Quoted 1 line · Bjorn Helgaas

On Fri, Mar 04, 2022 at 12:06:10PM +0000, Zhangjiantao(Kirin,Nanjing) wrote:

All this should not be in new versions of patches.

Quoted 31 lines
Quoted 31 lines
Quoted 1 line

When dma_mapping_error returns error because of no enough memory available, dw_pcie_host_init will return success, which will mislead the callers.

Wrap to fit in 75 columns, add "()" after function names.

Quoted 13 lines
---
   drivers/pci/controller/dwc/pcie-designware-host.c | 1 +
   1 file changed, 1 insertion(+)
drivers/pci/controller/dwc/pcie-designware-host.c +0 -0
index f4755f3a03be..ac691d733848 100644

drivers/pci/controller/dwc/pcie-designware-host.c int dw_pcie_host_init(struct pcie_port *pp) · line 396

Quoted 4 lines
drivers/pci/controller/dwc/pcie-designware-host.c +1 -0
@@ -393,6 +393,7 @@ int dw_pcie_host_init(struct pcie_port *pp)
               if (dma_mapping_error(pci->dev, pp->msi_data)) {
                   dev_err(pci->dev, "Failed to map MSI data\n");
                   pp->msi_data = 0;
+                ret = -1;

We should save the return value from dma_mapping_error() and return *that*, not -1.

Whitespace error (indent with tabs, same as the surrounding code).

Quoted 6 lines
drivers/pci/controller/dwc/pcie-designware-host.c +0 -1
                   goto err_free_msi;
               }
           }
--

2.17.1

.

#2 lore raw

PATCH v2 1/1 PCI: dwc: Fix setting error return on MSI DMA mapping failure

When dma_mapping_error() returns error because of no enough memory, but dw_pcie_host_init() returns success, which will mislead the callers.

Fixes 07940c369a6b ("PCI: dwc: Fix MSI page leakage in suspend/resume")
---
  drivers/pci/controller/dwc/pcie-designware-host.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/pci/controller/dwc/pcie-designware-host.c +2 -1
index f4755f3a03be..9dcb51728dd1 100644
@@ -390,7 +390,8 @@ int dw_pcie_host_init(struct pcie_port *pp)
                                sizeof(pp->msi_msg),
                                DMA_FROM_DEVICE,
                                DMA_ATTR_SKIP_CPU_SYNC);
-            if (dma_mapping_error(pci->dev, pp->msi_data)) {
+            ret = dma_mapping_error(pci->dev, pp->msi_data);
+            if (ret) {
                  dev_err(pci->dev, "Failed to map MSI data\n");
                  pp->msi_data = 0;
                  goto err_free_msi;

--
2.17.1

Jiantao Zhang

Quoted 1 line · Zhangjiantao(Kirin,Nanjing)

When dma_mapping_error() returns error because of no enough memory available, dw_pcie_host_init() will return success, which will mislead the callers.

Again, wrap long lines. And please reword the subject as I previously suggested.

It should be 'PATCH v2', not 'PATCH2' in the subject. 'git send-email -v2' does that for you.

Quoted 2 lines
Fixes 07940c369a6b ("PCI: dwc: Fix MSI page leakage in suspend/resume")

Drop the blank line here.

Quoted 1 line

As you are sending the patch, your S-o-b goes last. And the author name still doesn't match here: 'Jiantao Zhang' vs. 'Zhangjiantao(Kirin,Nanjing)'

Quoted 23 lines
---
   drivers/pci/controller/dwc/pcie-designware-host.c | 3 ++-
   1 file changed, 2 insertions(+), 1 deletion(-)
drivers/pci/controller/dwc/pcie-designware-host.c +2 -2
index f4755f3a03be..9dcb51728dd1 100644
@@ -390,7 +390,8 @@ int dw_pcie_host_init(struct pcie_port *pp)
                                 sizeof(pp->msi_msg),
                                 DMA_FROM_DEVICE,
                                 DMA_ATTR_SKIP_CPU_SYNC);
-            if (dma_mapping_error(pci->dev, pp->msi_data)) {
+            ret = dma_mapping_error(pci->dev, pp->msi_data);
+            if (ret) {
                   dev_err(pci->dev, "Failed to map MSI data\n");
                   pp->msi_data = 0;
                   goto err_free_msi;
--

2.17.1

Quoted 4 lines

Jiantao Zhang

Quoted 1 line · Bjorn Helgaas

On Fri, Mar 04, 2022 at 12:06:10PM +0000, Zhangjiantao(Kirin,Nanjing) wrote:

All this should not be in new versions of patches.

Quoted 31 lines
Quoted 31 lines
Quoted 1 line

When dma_mapping_error returns error because of no enough memory available, dw_pcie_host_init will return success, which will mislead the callers.

Wrap to fit in 75 columns, add "()" after function names.

Quoted 13 lines
---
    drivers/pci/controller/dwc/pcie-designware-host.c | 1 +
    1 file changed, 1 insertion(+)
drivers/pci/controller/dwc/pcie-designware-host.c +0 -0
index f4755f3a03be..ac691d733848 100644

drivers/pci/controller/dwc/pcie-designware-host.c int dw_pcie_host_init(struct pcie_port *pp) · line 396

Quoted 4 lines
drivers/pci/controller/dwc/pcie-designware-host.c +1 -0
@@ -393,6 +393,7 @@ int dw_pcie_host_init(struct pcie_port *pp)
                if (dma_mapping_error(pci->dev, pp->msi_data)) {
                    dev_err(pci->dev, "Failed to map MSI data\n");
                    pp->msi_data = 0;
+                ret = -1;

We should save the return value from dma_mapping_error() and return *that*, not -1.

Whitespace error (indent with tabs, same as the surrounding code).

Quoted 6 lines
drivers/pci/controller/dwc/pcie-designware-host.c +0 -1
                    goto err_free_msi;
                }
            }
--

2.17.1

.

reviewer Reviewed-by on v2 1/1
#3 lore raw

Re: [PATCH v2] PCI: dwc: Fix setting error return on MSI DMA mapping failure

Quoted 9 lines · Jiantao Zhang

When dma_mapping_error() returns error because of no enough memory, but dw_pcie_host_init() returns success, which will mislead the callers.

Fixes 07940c369a6b ("PCI: dwc: Fix MSI page leakage in suspend/resume")
---
  drivers/pci/controller/dwc/pcie-designware-host.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)