Skip to contentSkip to conversation

usb: host: pci_quirks: fix memory leak, by adding iounmap

PATCH Superseded Saurabh Sengar 3 participants 12 messages Nov 6, 2015 – Dec 4, 2015

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

PATCH 1/1 usb: host: pci_quirks: fix memory leak, by adding iounmap

added iounmap inorder to free memory mapped to base before returning

---
 drivers/usb/host/pci-quirks.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/host/pci-quirks.c +2 -2
index f940056..332f687 100644
@@ -990,7 +990,7 @@ static void quirk_usb_handoff_xhci(struct pci_dev *pdev)
 			/* We're reading garbage from the controller */
 			dev_warn(&pdev->dev,
 				 "xHCI controller failing to respond");
-			return;
+			goto iounmap;
 		}
 
 		if (!ext_cap_offset)
@@ -1061,7 +1061,7 @@ hc_init:
 			 "xHCI HW did not halt within %d usec status = 0x%x\n",
 			 XHCI_MAX_HALT_USEC, val);
 	}
-
+iounmap:
 	iounmap(base);
 }
 
Signature · 1 line
1.9.1
#1 lore raw

pinging in case this patch is lost.

Quoted 32 lines · Saurabh Sengar

added iounmap inorder to free memory mapped to base before returning

---
 drivers/usb/host/pci-quirks.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/host/pci-quirks.c +2 -3
index f940056..332f687 100644
@@ -990,7 +990,7 @@ static void quirk_usb_handoff_xhci(struct pci_dev *pdev)
                        /* We're reading garbage from the controller */
                        dev_warn(&pdev->dev,
                                 "xHCI controller failing to respond");
-                       return;
+                       goto iounmap;
                }
 
                if (!ext_cap_offset)
@@ -1061,7 +1061,7 @@ hc_init:
                         "xHCI HW did not halt within %d usec status = 0x%x\n",
                         XHCI_MAX_HALT_USEC, val);
        }
-
+iounmap:
        iounmap(base);
 }
 
--

1.9.1

maintainer
#2 lore raw
Quoted 33 lines · Saurabh Sengar

pinging in case this patch is lost.

Quoted 29 lines · Saurabh Sengar

added iounmap inorder to free memory mapped to base before returning

---
  drivers/usb/host/pci-quirks.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/host/pci-quirks.c +2 -2
index f940056..332f687 100644
@@ -990,7 +990,7 @@ static void quirk_usb_handoff_xhci(struct pci_dev *pdev)
                         /* We're reading garbage from the controller */
                         dev_warn(&pdev->dev,
                                  "xHCI controller failing to respond");
-                       return;
+                       goto iounmap;
                 }
 
                 if (!ext_cap_offset)
@@ -1061,7 +1061,7 @@ hc_init:
                          "xHCI HW did not halt within %d usec status = 0x%x\n",
                          XHCI_MAX_HALT_USEC, val);
         }
-
+iounmap:
         iounmap(base);
  }
 
Quoted 3 lines
Quoted 3 lines

--
1.9.1

Thanks, I'll add it send it forward soon

-Mathias

maintainer
#3 lore raw
In reply to Saurabh Sengar
Quoted 21 lines · Saurabh Sengar

added iounmap inorder to free memory mapped to base before returning

---
 drivers/usb/host/pci-quirks.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/host/pci-quirks.c +1 -1
index f940056..332f687 100644
@@ -990,7 +990,7 @@ static void quirk_usb_handoff_xhci(struct pci_dev *pdev)
 			/* We're reading garbage from the controller */
 			dev_warn(&pdev->dev,
 				 "xHCI controller failing to respond");
-			return;
+			goto iounmap;
 		}
 
 		if (!ext_cap_offset)

drivers/usb/host/pci-quirks.c hc_init: · line 1067

Quoted 8 lines
drivers/usb/host/pci-quirks.c +1 -1
@@ -1061,7 +1061,7 @@ hc_init:
 			 "xHCI HW did not halt within %d usec status = 0x%x\n",
 			 XHCI_MAX_HALT_USEC, val);
 	}
-
+iounmap:
 	iounmap(base);
 }
 

Does not apply to the tree :(

#4 lore raw
Quoted 20 lines · Greg KH
Quoted 19 lines · Saurabh Sengar

added iounmap inorder to free memory mapped to base before returning

---
 drivers/usb/host/pci-quirks.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/host/pci-quirks.c +1 -1
index f940056..332f687 100644
@@ -990,7 +990,7 @@ static void quirk_usb_handoff_xhci(struct pci_dev *pdev)
                      /* We're reading garbage from the controller */
                      dev_warn(&pdev->dev,
                               "xHCI controller failing to respond");
-                     return;
+                     goto iounmap;
              }
 
Quoted 12 lines

drivers/usb/host/pci-quirks.c hc_init: · line 1067

Quoted 10 lines
drivers/usb/host/pci-quirks.c +1 -1
              if (!ext_cap_offset)
@@ -1061,7 +1061,7 @@ hc_init:
                       "xHCI HW did not halt within %d usec status = 0x%x\n",
                       XHCI_MAX_HALT_USEC, val);
      }
-
+iounmap:
      iounmap(base);
 }
 

Does not apply to the tree :(

This patch applies fine on top of "git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git". Just now only I have re-verified.
Am I expected to send this patch on top of some other git tree/branch ?

maintainer
#5 lore raw
Quoted 35 lines · Saurabh Sengar
Quoted 20 lines · Greg KH
Quoted 19 lines · Saurabh Sengar

added iounmap inorder to free memory mapped to base before returning

---
 drivers/usb/host/pci-quirks.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/host/pci-quirks.c +1 -1
index f940056..332f687 100644
@@ -990,7 +990,7 @@ static void quirk_usb_handoff_xhci(struct pci_dev *pdev)
                      /* We're reading garbage from the controller */
                      dev_warn(&pdev->dev,
                               "xHCI controller failing to respond");
-                     return;
+                     goto iounmap;
              }
 
Quoted 12 lines

drivers/usb/host/pci-quirks.c hc_init: · line 1067

Quoted 10 lines
drivers/usb/host/pci-quirks.c +1 -1
              if (!ext_cap_offset)
@@ -1061,7 +1061,7 @@ hc_init:
                       "xHCI HW did not halt within %d usec status = 0x%x\n",
                       XHCI_MAX_HALT_USEC, val);
      }
-
+iounmap:
      iounmap(base);
 }
 

Does not apply to the tree :(

Quoted 4 lines

This patch applies fine on top of "git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git". Just now only I have re-verified.
Am I expected to send this patch on top of some other git tree/branch ?

It will end up going in the usb.git tree, on the usb-next branch, and it conflicts with other xhci patches that just landed there ahead of yours. So it's not your fault, you did the right thing, just others also did work here so you need to redo yours as well, a normal thing in kernel development :)

hope this helps explain things.

thanks,

greg k-h

#6 lore raw

Hi Greg,

I am little unclear.
Now, shall I resend my patch on top of usb.git tree or linux.git tree.

Regards,
Saurabh

Quoted 52 lines · Greg KH
Quoted 35 lines · Saurabh Sengar
Quoted 20 lines · Greg KH
Quoted 19 lines · Saurabh Sengar

added iounmap inorder to free memory mapped to base before returning

---
 drivers/usb/host/pci-quirks.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/host/pci-quirks.c +1 -1
index f940056..332f687 100644
@@ -990,7 +990,7 @@ static void quirk_usb_handoff_xhci(struct pci_dev *pdev)
                      /* We're reading garbage from the controller */
                      dev_warn(&pdev->dev,
                               "xHCI controller failing to respond");
-                     return;
+                     goto iounmap;
              }
 
Quoted 12 lines

drivers/usb/host/pci-quirks.c hc_init: · line 1067

Quoted 10 lines
drivers/usb/host/pci-quirks.c +1 -1
              if (!ext_cap_offset)
@@ -1061,7 +1061,7 @@ hc_init:
                       "xHCI HW did not halt within %d usec status = 0x%x\n",
                       XHCI_MAX_HALT_USEC, val);
      }
-
+iounmap:
      iounmap(base);
 }
 

Does not apply to the tree :(

Quoted 4 lines

This patch applies fine on top of "git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git". Just now only I have re-verified.
Am I expected to send this patch on top of some other git tree/branch ?

It will end up going in the usb.git tree, on the usb-next branch, and it conflicts with other xhci patches that just landed there ahead of yours. So it's not your fault, you did the right thing, just others also did work here so you need to redo yours as well, a normal thing in kernel development :)

hope this helps explain things.

thanks,

greg k-h

maintainer
#7 lore raw
Quoted 4 lines · Saurabh Sengar

Hi Greg,

I am little unclear.
Now, shall I resend my patch on top of usb.git tree or linux.git tree.

The usb-next branch of the usb.git tree please.

#8 lore raw

PATCH v2 1/1 usb: host: pci_quirks: fix memory leak, by adding iounmap

added iounmap inorder to free memory mapped to base before returning

---
v2: changed logic a bit, because of recent patches pushed to usb-next

 drivers/usb/host/pci-quirks.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/host/pci-quirks.c +1 -1
index 26cb8c8..2ac198c 100644
@@ -992,7 +992,7 @@ static void quirk_usb_handoff_xhci(struct pci_dev *pdev)
 	if ((ext_cap_offset + sizeof(val)) > len) {
 		/* We're reading garbage from the controller */
 		dev_warn(&pdev->dev, "xHCI controller failing to respond");
-		return;
+		goto hc_init;
 	}
 	val = readl(base + ext_cap_offset);
 
Signature · 1 line
1.9.1
maintainer
#9 lore raw
Quoted 13 lines · Saurabh Sengar

added iounmap inorder to free memory mapped to base before returning

---
v2: changed logic a bit, because of recent patches pushed to usb-next

 drivers/usb/host/pci-quirks.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/host/pci-quirks.c +0 -0
index 26cb8c8..2ac198c 100644

drivers/usb/host/pci-quirks.c static void quirk_usb_handoff_xhci(struct pci_dev *pdev) · line 995

Quoted 5 lines
drivers/usb/host/pci-quirks.c +1 -1
@@ -992,7 +992,7 @@ static void quirk_usb_handoff_xhci(struct pci_dev *pdev)
 	if ((ext_cap_offset + sizeof(val)) > len) {
 		/* We're reading garbage from the controller */
 		dev_warn(&pdev->dev, "xHCI controller failing to respond");
-		return;
+		goto hc_init;

Are you sure this is correct? That goto location then does a whole bunch of things with the xhci controller that you just now determined is failing to respond. I can't take this as-is, sorry.

greg k-h

#10 lore raw
Quoted 24 lines · Greg KH
Quoted 13 lines · Saurabh Sengar

added iounmap inorder to free memory mapped to base before returning

---
v2: changed logic a bit, because of recent patches pushed to usb-next

 drivers/usb/host/pci-quirks.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/host/pci-quirks.c +0 -0
index 26cb8c8..2ac198c 100644

drivers/usb/host/pci-quirks.c static void quirk_usb_handoff_xhci(struct pci_dev *pdev) · line 995

Quoted 5 lines
drivers/usb/host/pci-quirks.c +1 -1
@@ -992,7 +992,7 @@ static void quirk_usb_handoff_xhci(struct pci_dev *pdev)
      if ((ext_cap_offset + sizeof(val)) > len) {
              /* We're reading garbage from the controller */
              dev_warn(&pdev->dev, "xHCI controller failing to respond");
-             return;
+             goto hc_init;

Are you sure this is correct? That goto location then does a whole bunch of things with the xhci controller that you just now determined is failing to respond. I can't take this as-is, sorry.

Quoted 1 line

greg k-h

Yes I agree, and in the first patch I didn't do this way.
But the latest patch which got introduced is doing "goto hc_init" at line 990

        ext_cap_offset = xhci_find_next_ext_cap(base, 0, XHCI_EXT_CAPS_LEGACY);

        if (!ext_cap_offset)
                goto hc_init;

I think this is wrong too, may be I am wrong.

Any way I will send the first patch again on top of usb-next as v3

#11 lore raw

PATCH v3 1/1 usb: host: pci_quirks: fix memory leak, by adding iounmap

In reply to Greg KH

added iounmap inorder to free memory mapped to base before returning

---
v3: reverted to v1 logic, on top of usb-next branch

 drivers/usb/host/pci-quirks.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/host/pci-quirks.c +2 -1
index 26cb8c8..35af362 100644
@@ -992,7 +992,7 @@ static void quirk_usb_handoff_xhci(struct pci_dev *pdev)
 	if ((ext_cap_offset + sizeof(val)) > len) {
 		/* We're reading garbage from the controller */
 		dev_warn(&pdev->dev, "xHCI controller failing to respond");
-		return;
+		goto iounmap;
 	}
 	val = readl(base + ext_cap_offset);
 
@@ -1055,6 +1055,7 @@ hc_init:
 			 XHCI_MAX_HALT_USEC, val);
 	}
 
+iounmap:
 	iounmap(base);
 }
 
Signature · 1 line
1.9.1