aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/of/unittest.c
diff options
context:
space:
mode:
authorFrank Rowand <frank.rowand@sony.com>2018-10-04 23:40:21 -0400
committerFrank Rowand <frank.rowand@sony.com>2018-11-09 01:12:37 -0500
commiteeb07c573ec307c53fe2f6ac6d8d11c261f64006 (patch)
treec6f825e39534e2b3e936cd358ad9316f324a6489 /drivers/of/unittest.c
parent160b1d4e4127f0ef5d9ac281b6fa6ef1fb78c45f (diff)
of: unittest: initialize args before calling of_*parse_*()
Callers of of_irq_parse_one() blindly use the pointer args.np without checking whether of_irq_parse_one() had an error and thus did not set the value of args.np. Initialize args to zero so that using the format "%pOF" to show the value of args.np will show "(null)" when of_irq_parse_one() has an error. This prevents the dereference of a random value. Make the same fix for callers of of_parse_phandle_with_args() and of_parse_phandle_with_args_map(). Reported-by: Guenter Roeck <linux@roeck-us.net> Tested-by: Alan Tull <atull@kernel.org> Signed-off-by: Frank Rowand <frank.rowand@sony.com>
Diffstat (limited to 'drivers/of/unittest.c')
-rw-r--r--drivers/of/unittest.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index fe01c5869b0f..9a10a48eb6a1 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -379,6 +379,7 @@ static void __init of_unittest_parse_phandle_with_args(void)
379 for (i = 0; i < 8; i++) { 379 for (i = 0; i < 8; i++) {
380 bool passed = true; 380 bool passed = true;
381 381
382 memset(&args, 0, sizeof(args));
382 rc = of_parse_phandle_with_args(np, "phandle-list", 383 rc = of_parse_phandle_with_args(np, "phandle-list",
383 "#phandle-cells", i, &args); 384 "#phandle-cells", i, &args);
384 385
@@ -432,6 +433,7 @@ static void __init of_unittest_parse_phandle_with_args(void)
432 } 433 }
433 434
434 /* Check for missing list property */ 435 /* Check for missing list property */
436 memset(&args, 0, sizeof(args));
435 rc = of_parse_phandle_with_args(np, "phandle-list-missing", 437 rc = of_parse_phandle_with_args(np, "phandle-list-missing",
436 "#phandle-cells", 0, &args); 438 "#phandle-cells", 0, &args);
437 unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc); 439 unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc);
@@ -440,6 +442,7 @@ static void __init of_unittest_parse_phandle_with_args(void)
440 unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc); 442 unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc);
441 443
442 /* Check for missing cells property */ 444 /* Check for missing cells property */
445 memset(&args, 0, sizeof(args));
443 rc = of_parse_phandle_with_args(np, "phandle-list", 446 rc = of_parse_phandle_with_args(np, "phandle-list",
444 "#phandle-cells-missing", 0, &args); 447 "#phandle-cells-missing", 0, &args);
445 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); 448 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
@@ -448,6 +451,7 @@ static void __init of_unittest_parse_phandle_with_args(void)
448 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); 451 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
449 452
450 /* Check for bad phandle in list */ 453 /* Check for bad phandle in list */
454 memset(&args, 0, sizeof(args));
451 rc = of_parse_phandle_with_args(np, "phandle-list-bad-phandle", 455 rc = of_parse_phandle_with_args(np, "phandle-list-bad-phandle",
452 "#phandle-cells", 0, &args); 456 "#phandle-cells", 0, &args);
453 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); 457 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
@@ -456,6 +460,7 @@ static void __init of_unittest_parse_phandle_with_args(void)
456 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); 460 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
457 461
458 /* Check for incorrectly formed argument list */ 462 /* Check for incorrectly formed argument list */
463 memset(&args, 0, sizeof(args));
459 rc = of_parse_phandle_with_args(np, "phandle-list-bad-args", 464 rc = of_parse_phandle_with_args(np, "phandle-list-bad-args",
460 "#phandle-cells", 1, &args); 465 "#phandle-cells", 1, &args);
461 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); 466 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
@@ -506,6 +511,7 @@ static void __init of_unittest_parse_phandle_with_args_map(void)
506 for (i = 0; i < 8; i++) { 511 for (i = 0; i < 8; i++) {
507 bool passed = true; 512 bool passed = true;
508 513
514 memset(&args, 0, sizeof(args));
509 rc = of_parse_phandle_with_args_map(np, "phandle-list", 515 rc = of_parse_phandle_with_args_map(np, "phandle-list",
510 "phandle", i, &args); 516 "phandle", i, &args);
511 517
@@ -563,21 +569,25 @@ static void __init of_unittest_parse_phandle_with_args_map(void)
563 } 569 }
564 570
565 /* Check for missing list property */ 571 /* Check for missing list property */
572 memset(&args, 0, sizeof(args));
566 rc = of_parse_phandle_with_args_map(np, "phandle-list-missing", 573 rc = of_parse_phandle_with_args_map(np, "phandle-list-missing",
567 "phandle", 0, &args); 574 "phandle", 0, &args);
568 unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc); 575 unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc);
569 576
570 /* Check for missing cells,map,mask property */ 577 /* Check for missing cells,map,mask property */
578 memset(&args, 0, sizeof(args));
571 rc = of_parse_phandle_with_args_map(np, "phandle-list", 579 rc = of_parse_phandle_with_args_map(np, "phandle-list",
572 "phandle-missing", 0, &args); 580 "phandle-missing", 0, &args);
573 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); 581 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
574 582
575 /* Check for bad phandle in list */ 583 /* Check for bad phandle in list */
584 memset(&args, 0, sizeof(args));
576 rc = of_parse_phandle_with_args_map(np, "phandle-list-bad-phandle", 585 rc = of_parse_phandle_with_args_map(np, "phandle-list-bad-phandle",
577 "phandle", 0, &args); 586 "phandle", 0, &args);
578 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); 587 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
579 588
580 /* Check for incorrectly formed argument list */ 589 /* Check for incorrectly formed argument list */
590 memset(&args, 0, sizeof(args));
581 rc = of_parse_phandle_with_args_map(np, "phandle-list-bad-args", 591 rc = of_parse_phandle_with_args_map(np, "phandle-list-bad-args",
582 "phandle", 1, &args); 592 "phandle", 1, &args);
583 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); 593 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
@@ -787,7 +797,7 @@ static void __init of_unittest_parse_interrupts(void)
787 for (i = 0; i < 4; i++) { 797 for (i = 0; i < 4; i++) {
788 bool passed = true; 798 bool passed = true;
789 799
790 args.args_count = 0; 800 memset(&args, 0, sizeof(args));
791 rc = of_irq_parse_one(np, i, &args); 801 rc = of_irq_parse_one(np, i, &args);
792 802
793 passed &= !rc; 803 passed &= !rc;
@@ -808,7 +818,7 @@ static void __init of_unittest_parse_interrupts(void)
808 for (i = 0; i < 4; i++) { 818 for (i = 0; i < 4; i++) {
809 bool passed = true; 819 bool passed = true;
810 820
811 args.args_count = 0; 821 memset(&args, 0, sizeof(args));
812 rc = of_irq_parse_one(np, i, &args); 822 rc = of_irq_parse_one(np, i, &args);
813 823
814 /* Test the values from tests-phandle.dtsi */ 824 /* Test the values from tests-phandle.dtsi */
@@ -864,6 +874,7 @@ static void __init of_unittest_parse_interrupts_extended(void)
864 for (i = 0; i < 7; i++) { 874 for (i = 0; i < 7; i++) {
865 bool passed = true; 875 bool passed = true;
866 876
877 memset(&args, 0, sizeof(args));
867 rc = of_irq_parse_one(np, i, &args); 878 rc = of_irq_parse_one(np, i, &args);
868 879
869 /* Test the values from tests-phandle.dtsi */ 880 /* Test the values from tests-phandle.dtsi */