Skip to content

Commit b7a46e7

Browse files
geerturobherring
authored andcommitted
of: unittest: Merge of_unittest_apply{,_revert}_overlay_check()
of_unittest_apply_overlay_check() and the first part of of_unittest_apply_revert_overlay_check() are identical. Reduce code duplication by replacing them by two wrappers around a common helper. Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Link: https://lore.kernel.org/r/4bafe338655beab6b244047e737c0c2aa60b613d.1690533838.git.geert+renesas@glider.be Signed-off-by: Rob Herring <robh@kernel.org>
1 parent 35df904 commit b7a46e7

1 file changed

Lines changed: 18 additions & 27 deletions

File tree

drivers/of/unittest.c

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2134,8 +2134,7 @@ static int __init of_unittest_apply_overlay(int overlay_nr, int *ovcs_id)
21342134
return 0;
21352135
}
21362136

2137-
/* apply an overlay while checking before and after states */
2138-
static int __init of_unittest_apply_overlay_check(int overlay_nr,
2137+
static int __init __of_unittest_apply_overlay_check(int overlay_nr,
21392138
int unittest_nr, int before, int after,
21402139
enum overlay_type ovtype)
21412140
{
@@ -2167,6 +2166,19 @@ static int __init of_unittest_apply_overlay_check(int overlay_nr,
21672166
return -EINVAL;
21682167
}
21692168

2169+
return ovcs_id;
2170+
}
2171+
2172+
/* apply an overlay while checking before and after states */
2173+
static int __init of_unittest_apply_overlay_check(int overlay_nr,
2174+
int unittest_nr, int before, int after,
2175+
enum overlay_type ovtype)
2176+
{
2177+
int ovcs_id = __of_unittest_apply_overlay_check(overlay_nr,
2178+
unittest_nr, before, after, ovtype);
2179+
if (ovcs_id < 0)
2180+
return ovcs_id;
2181+
21702182
return 0;
21712183
}
21722184

@@ -2177,31 +2189,10 @@ static int __init of_unittest_apply_revert_overlay_check(int overlay_nr,
21772189
{
21782190
int ret, ovcs_id, save_ovcs_id;
21792191

2180-
/* unittest device must be in before state */
2181-
if (of_unittest_device_exists(unittest_nr, ovtype) != before) {
2182-
unittest(0, "%s with device @\"%s\" %s\n",
2183-
overlay_name_from_nr(overlay_nr),
2184-
unittest_path(unittest_nr, ovtype),
2185-
!before ? "enabled" : "disabled");
2186-
return -EINVAL;
2187-
}
2188-
2189-
/* apply the overlay */
2190-
ovcs_id = 0;
2191-
ret = of_unittest_apply_overlay(overlay_nr, &ovcs_id);
2192-
if (ret != 0) {
2193-
/* of_unittest_apply_overlay already called unittest() */
2194-
return ret;
2195-
}
2196-
2197-
/* unittest device must be in after state */
2198-
if (of_unittest_device_exists(unittest_nr, ovtype) != after) {
2199-
unittest(0, "%s with device @\"%s\" %s\n",
2200-
overlay_name_from_nr(overlay_nr),
2201-
unittest_path(unittest_nr, ovtype),
2202-
!after ? "enabled" : "disabled");
2203-
return -EINVAL;
2204-
}
2192+
ovcs_id = __of_unittest_apply_overlay_check(overlay_nr, unittest_nr,
2193+
before, after, ovtype);
2194+
if (ovcs_id < 0)
2195+
return ovcs_id;
22052196

22062197
/* remove the overlay */
22072198
save_ovcs_id = ovcs_id;

0 commit comments

Comments
 (0)