]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
usb: dwc3: use local copy of resource to fix-up register offset
authorMasahiro Yamada <yamada.masahiro@socionext.com>
Thu, 19 Apr 2018 11:03:37 +0000 (20:03 +0900)
committerFelipe Balbi <felipe.balbi@linux.intel.com>
Tue, 15 May 2018 07:23:47 +0000 (10:23 +0300)
It is not a good idea to directly modify the resource of a platform
device.  Modify its local copy, and pass it to devm_ioremap_resource()
so that we do not need to restore it in the failure path and the remove
hook.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
drivers/usb/dwc3/core.c

index 449a0982111b9f169ad6db0a7f87818f0e266dac..25d7e9d6fb0d1319362dee7ae482df98287782e5 100644 (file)
@@ -1245,7 +1245,7 @@ static void dwc3_check_params(struct dwc3 *dwc)
 static int dwc3_probe(struct platform_device *pdev)
 {
        struct device           *dev = &pdev->dev;
-       struct resource         *res;
+       struct resource         *res, dwc_res;
        struct dwc3             *dwc;
 
        int                     ret;
@@ -1270,20 +1270,19 @@ static int dwc3_probe(struct platform_device *pdev)
        dwc->xhci_resources[0].flags = res->flags;
        dwc->xhci_resources[0].name = res->name;
 
-       res->start += DWC3_GLOBALS_REGS_START;
-
        /*
         * Request memory region but exclude xHCI regs,
         * since it will be requested by the xhci-plat driver.
         */
-       regs = devm_ioremap_resource(dev, res);
-       if (IS_ERR(regs)) {
-               ret = PTR_ERR(regs);
-               goto err0;
-       }
+       dwc_res = *res;
+       dwc_res.start += DWC3_GLOBALS_REGS_START;
+
+       regs = devm_ioremap_resource(dev, &dwc_res);
+       if (IS_ERR(regs))
+               return PTR_ERR(regs);
 
        dwc->regs       = regs;
-       dwc->regs_size  = resource_size(res);
+       dwc->regs_size  = resource_size(&dwc_res);
 
        dwc3_get_properties(dwc);
 
@@ -1350,29 +1349,14 @@ static int dwc3_probe(struct platform_device *pdev)
        pm_runtime_put_sync(&pdev->dev);
        pm_runtime_disable(&pdev->dev);
 
-err0:
-       /*
-        * restore res->start back to its original value so that, in case the
-        * probe is deferred, we don't end up getting error in request the
-        * memory region the next time probe is called.
-        */
-       res->start -= DWC3_GLOBALS_REGS_START;
-
        return ret;
 }
 
 static int dwc3_remove(struct platform_device *pdev)
 {
        struct dwc3     *dwc = platform_get_drvdata(pdev);
-       struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 
        pm_runtime_get_sync(&pdev->dev);
-       /*
-        * restore res->start back to its original value so that, in case the
-        * probe is deferred, we don't end up getting error in request the
-        * memory region the next time probe is called.
-        */
-       res->start -= DWC3_GLOBALS_REGS_START;
 
        dwc3_debugfs_exit(dwc);
        dwc3_core_exit_mode(dwc);