Commit eeb07c57 authored by Frank Rowand's avatar Frank Rowand

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: default avatarGuenter Roeck <linux@roeck-us.net>
Tested-by: default avatarAlan Tull <atull@kernel.org>
Signed-off-by: default avatarFrank Rowand <frank.rowand@sony.com>
parent 160b1d4e
...@@ -379,6 +379,7 @@ static void __init of_unittest_parse_phandle_with_args(void) ...@@ -379,6 +379,7 @@ static void __init of_unittest_parse_phandle_with_args(void)
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
bool passed = true; bool passed = true;
memset(&args, 0, sizeof(args));
rc = of_parse_phandle_with_args(np, "phandle-list", rc = of_parse_phandle_with_args(np, "phandle-list",
"#phandle-cells", i, &args); "#phandle-cells", i, &args);
...@@ -432,6 +433,7 @@ static void __init of_unittest_parse_phandle_with_args(void) ...@@ -432,6 +433,7 @@ static void __init of_unittest_parse_phandle_with_args(void)
} }
/* Check for missing list property */ /* Check for missing list property */
memset(&args, 0, sizeof(args));
rc = of_parse_phandle_with_args(np, "phandle-list-missing", rc = of_parse_phandle_with_args(np, "phandle-list-missing",
"#phandle-cells", 0, &args); "#phandle-cells", 0, &args);
unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc); 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,6 +442,7 @@ static void __init of_unittest_parse_phandle_with_args(void)
unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc); unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc);
/* Check for missing cells property */ /* Check for missing cells property */
memset(&args, 0, sizeof(args));
rc = of_parse_phandle_with_args(np, "phandle-list", rc = of_parse_phandle_with_args(np, "phandle-list",
"#phandle-cells-missing", 0, &args); "#phandle-cells-missing", 0, &args);
unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); 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,6 +451,7 @@ static void __init of_unittest_parse_phandle_with_args(void)
unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
/* Check for bad phandle in list */ /* Check for bad phandle in list */
memset(&args, 0, sizeof(args));
rc = of_parse_phandle_with_args(np, "phandle-list-bad-phandle", rc = of_parse_phandle_with_args(np, "phandle-list-bad-phandle",
"#phandle-cells", 0, &args); "#phandle-cells", 0, &args);
unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); 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,6 +460,7 @@ static void __init of_unittest_parse_phandle_with_args(void)
unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
/* Check for incorrectly formed argument list */ /* Check for incorrectly formed argument list */
memset(&args, 0, sizeof(args));
rc = of_parse_phandle_with_args(np, "phandle-list-bad-args", rc = of_parse_phandle_with_args(np, "phandle-list-bad-args",
"#phandle-cells", 1, &args); "#phandle-cells", 1, &args);
unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); 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,6 +511,7 @@ static void __init of_unittest_parse_phandle_with_args_map(void)
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
bool passed = true; bool passed = true;
memset(&args, 0, sizeof(args));
rc = of_parse_phandle_with_args_map(np, "phandle-list", rc = of_parse_phandle_with_args_map(np, "phandle-list",
"phandle", i, &args); "phandle", i, &args);
...@@ -563,21 +569,25 @@ static void __init of_unittest_parse_phandle_with_args_map(void) ...@@ -563,21 +569,25 @@ static void __init of_unittest_parse_phandle_with_args_map(void)
} }
/* Check for missing list property */ /* Check for missing list property */
memset(&args, 0, sizeof(args));
rc = of_parse_phandle_with_args_map(np, "phandle-list-missing", rc = of_parse_phandle_with_args_map(np, "phandle-list-missing",
"phandle", 0, &args); "phandle", 0, &args);
unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc); unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc);
/* Check for missing cells,map,mask property */ /* Check for missing cells,map,mask property */
memset(&args, 0, sizeof(args));
rc = of_parse_phandle_with_args_map(np, "phandle-list", rc = of_parse_phandle_with_args_map(np, "phandle-list",
"phandle-missing", 0, &args); "phandle-missing", 0, &args);
unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
/* Check for bad phandle in list */ /* Check for bad phandle in list */
memset(&args, 0, sizeof(args));
rc = of_parse_phandle_with_args_map(np, "phandle-list-bad-phandle", rc = of_parse_phandle_with_args_map(np, "phandle-list-bad-phandle",
"phandle", 0, &args); "phandle", 0, &args);
unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
/* Check for incorrectly formed argument list */ /* Check for incorrectly formed argument list */
memset(&args, 0, sizeof(args));
rc = of_parse_phandle_with_args_map(np, "phandle-list-bad-args", rc = of_parse_phandle_with_args_map(np, "phandle-list-bad-args",
"phandle", 1, &args); "phandle", 1, &args);
unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
...@@ -787,7 +797,7 @@ static void __init of_unittest_parse_interrupts(void) ...@@ -787,7 +797,7 @@ static void __init of_unittest_parse_interrupts(void)
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
bool passed = true; bool passed = true;
args.args_count = 0; memset(&args, 0, sizeof(args));
rc = of_irq_parse_one(np, i, &args); rc = of_irq_parse_one(np, i, &args);
passed &= !rc; passed &= !rc;
...@@ -808,7 +818,7 @@ static void __init of_unittest_parse_interrupts(void) ...@@ -808,7 +818,7 @@ static void __init of_unittest_parse_interrupts(void)
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
bool passed = true; bool passed = true;
args.args_count = 0; memset(&args, 0, sizeof(args));
rc = of_irq_parse_one(np, i, &args); rc = of_irq_parse_one(np, i, &args);
/* Test the values from tests-phandle.dtsi */ /* Test the values from tests-phandle.dtsi */
...@@ -864,6 +874,7 @@ static void __init of_unittest_parse_interrupts_extended(void) ...@@ -864,6 +874,7 @@ static void __init of_unittest_parse_interrupts_extended(void)
for (i = 0; i < 7; i++) { for (i = 0; i < 7; i++) {
bool passed = true; bool passed = true;
memset(&args, 0, sizeof(args));
rc = of_irq_parse_one(np, i, &args); rc = of_irq_parse_one(np, i, &args);
/* Test the values from tests-phandle.dtsi */ /* Test the values from tests-phandle.dtsi */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment