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

powerpc/fsl-rio: Fix fsl_rio_setup error paths and use-after-unmap

Several of the error paths from fsl_rio_setup are missing error
messages.

Worse, fsl_rio_setup initializes several global pointers and does not
NULL them out after freeing/unmapping on error. This caused
fsl_rio_mcheck_exception() to crash when accessing rio_regs_win which
was non-NULL but had been unmapped.

Signed-off-by: Scott Wood <scottwood@freescale.com>
Cc: Liu Gang <Gang.Liu@freescale.com>
---
Liu Gang, are you sure all of these error conditions are fatal? Why
does the rio driver fail if rmu is not present (e.g. on t4240)?

+9 -1
+9 -1
arch/powerpc/sysdev/fsl_rio.c
··· 391 391 ops->get_inb_message = fsl_get_inb_message; 392 392 393 393 rmu_node = of_parse_phandle(dev->dev.of_node, "fsl,srio-rmu-handle", 0); 394 - if (!rmu_node) 394 + if (!rmu_node) { 395 + dev_err(&dev->dev, "No valid fsl,srio-rmu-handle property\n"); 395 396 goto err_rmu; 397 + } 396 398 rc = of_address_to_resource(rmu_node, 0, &rmu_regs); 397 399 if (rc) { 398 400 dev_err(&dev->dev, "Can't get %s property 'reg'\n", ··· 415 413 /*set up doobell node*/ 416 414 np = of_find_compatible_node(NULL, NULL, "fsl,srio-dbell-unit"); 417 415 if (!np) { 416 + dev_err(&dev->dev, "No fsl,srio-dbell-unit node\n"); 418 417 rc = -ENODEV; 419 418 goto err_dbell; 420 419 } ··· 444 441 /*set up port write node*/ 445 442 np = of_find_compatible_node(NULL, NULL, "fsl,srio-port-write-unit"); 446 443 if (!np) { 444 + dev_err(&dev->dev, "No fsl,srio-port-write-unit node\n"); 447 445 rc = -ENODEV; 448 446 goto err_pw; 449 447 } ··· 637 633 return 0; 638 634 err: 639 635 kfree(pw); 636 + pw = NULL; 640 637 err_pw: 641 638 kfree(dbell); 639 + dbell = NULL; 642 640 err_dbell: 643 641 iounmap(rmu_regs_win); 642 + rmu_regs_win = NULL; 644 643 err_rmu: 645 644 kfree(ops); 646 645 err_ops: 647 646 iounmap(rio_regs_win); 647 + rio_regs_win = NULL; 648 648 err_rio_regs: 649 649 return rc; 650 650 }