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

usb: dwc3: use local copy of resource to fix-up register offset

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>

authored by

Masahiro Yamada and committed by
Felipe Balbi
44feb8e6 1ef6c42a

+8 -24
+8 -24
drivers/usb/dwc3/core.c
··· 1245 1245 static int dwc3_probe(struct platform_device *pdev) 1246 1246 { 1247 1247 struct device *dev = &pdev->dev; 1248 - struct resource *res; 1248 + struct resource *res, dwc_res; 1249 1249 struct dwc3 *dwc; 1250 1250 1251 1251 int ret; ··· 1270 1270 dwc->xhci_resources[0].flags = res->flags; 1271 1271 dwc->xhci_resources[0].name = res->name; 1272 1272 1273 - res->start += DWC3_GLOBALS_REGS_START; 1274 - 1275 1273 /* 1276 1274 * Request memory region but exclude xHCI regs, 1277 1275 * since it will be requested by the xhci-plat driver. 1278 1276 */ 1279 - regs = devm_ioremap_resource(dev, res); 1280 - if (IS_ERR(regs)) { 1281 - ret = PTR_ERR(regs); 1282 - goto err0; 1283 - } 1277 + dwc_res = *res; 1278 + dwc_res.start += DWC3_GLOBALS_REGS_START; 1279 + 1280 + regs = devm_ioremap_resource(dev, &dwc_res); 1281 + if (IS_ERR(regs)) 1282 + return PTR_ERR(regs); 1284 1283 1285 1284 dwc->regs = regs; 1286 - dwc->regs_size = resource_size(res); 1285 + dwc->regs_size = resource_size(&dwc_res); 1287 1286 1288 1287 dwc3_get_properties(dwc); 1289 1288 ··· 1349 1350 pm_runtime_put_sync(&pdev->dev); 1350 1351 pm_runtime_disable(&pdev->dev); 1351 1352 1352 - err0: 1353 - /* 1354 - * restore res->start back to its original value so that, in case the 1355 - * probe is deferred, we don't end up getting error in request the 1356 - * memory region the next time probe is called. 1357 - */ 1358 - res->start -= DWC3_GLOBALS_REGS_START; 1359 - 1360 1353 return ret; 1361 1354 } 1362 1355 1363 1356 static int dwc3_remove(struct platform_device *pdev) 1364 1357 { 1365 1358 struct dwc3 *dwc = platform_get_drvdata(pdev); 1366 - struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1367 1359 1368 1360 pm_runtime_get_sync(&pdev->dev); 1369 - /* 1370 - * restore res->start back to its original value so that, in case the 1371 - * probe is deferred, we don't end up getting error in request the 1372 - * memory region the next time probe is called. 1373 - */ 1374 - res->start -= DWC3_GLOBALS_REGS_START; 1375 1361 1376 1362 dwc3_debugfs_exit(dwc); 1377 1363 dwc3_core_exit_mode(dwc);