Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

USB: ehci-ppc-of: problems in unwind

The iounmap(ehci->ohci_hcctrl_reg); should be the first thing we do
because the ioremap() was the last thing we did. Also if we hit any of
the goto statements in the original code then it would have led to a
NULL dereference of "ehci". This bug was introduced in: 796bcae7361c
"USB: powerpc: Workaround for the PPC440EPX USBH_23 errata [take 3]"

I modified the few lines in front a little so that my code didn't
obscure the return success code path.

Signed-off-by: Dan Carpenter <error27@gmail.com>
Reviewed-by: Grant Likely <grant.likely@secretlab.ca>
Cc: stable <stable@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Dan Carpenter and committed by
Greg Kroah-Hartman
08a3b3b1 0f1312b2

+7 -5
+7 -5
drivers/usb/host/ehci-ppc-of.c
··· 192 192 } 193 193 194 194 rv = usb_add_hcd(hcd, irq, 0); 195 - if (rv == 0) 196 - return 0; 195 + if (rv) 196 + goto err_ehci; 197 197 198 + return 0; 199 + 200 + err_ehci: 201 + if (ehci->has_amcc_usb23) 202 + iounmap(ehci->ohci_hcctrl_reg); 198 203 iounmap(hcd->regs); 199 204 err_ioremap: 200 205 irq_dispose_mapping(irq); 201 206 err_irq: 202 207 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 203 - 204 - if (ehci->has_amcc_usb23) 205 - iounmap(ehci->ohci_hcctrl_reg); 206 208 err_rmr: 207 209 usb_put_hcd(hcd); 208 210