[PATCH 06/13] of: unittest: Merge of_unittest_apply{,_revert}_overlay_check()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 drivers/of/unittest.c | 61 ++++++++++++++++---------------------------
 1 file changed, 22 insertions(+), 39 deletions(-)

diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index 42abfcd0cdffa4af..4c21c8ce99b9d8ff 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -2101,46 +2101,10 @@ static int __init of_unittest_apply_overlay(int overlay_nr, int *ovcs_id)
 	return 0;
 }
 
-/* apply an overlay while checking before and after states */
-static int __init of_unittest_apply_overlay_check(int overlay_nr,
-		int unittest_nr, int before, int after,
-		enum overlay_type ovtype)
-{
-	int ret, ovcs_id;
-
-	/* unittest device must be in before state */
-	if (of_unittest_device_exists(unittest_nr, ovtype) != before) {
-		unittest(0, "%s with device @\"%s\" %s\n",
-				overlay_name_from_nr(overlay_nr),
-				unittest_path(unittest_nr, ovtype),
-				!before ? "enabled" : "disabled");
-		return -EINVAL;
-	}
-
-	/* apply the overlay */
-	ovcs_id = 0;
-	ret = of_unittest_apply_overlay(overlay_nr, &ovcs_id);
-	if (ret != 0) {
-		/* of_unittest_apply_overlay already called unittest() */
-		return ret;
-	}
-
-	/* unittest device must be in after state */
-	if (of_unittest_device_exists(unittest_nr, ovtype) != after) {
-		unittest(0, "%s with device @\"%s\" %s\n",
-				overlay_name_from_nr(overlay_nr),
-				unittest_path(unittest_nr, ovtype),
-				!after ? "enabled" : "disabled");
-		return -EINVAL;
-	}
-
-	return 0;
-}
-
-/* apply an overlay and then revert it while checking before, after states */
-static int __init of_unittest_apply_revert_overlay_check(int overlay_nr,
+/* apply an overlay and optionally revert it while checking states */
+static int __init __of_unittest_apply_revert_overlay_check(int overlay_nr,
 		int unittest_nr, int before, int after,
-		enum overlay_type ovtype)
+		enum overlay_type ovtype, bool revert)
 {
 	int ret, ovcs_id, save_ovcs_id;
 
@@ -2170,6 +2134,9 @@ static int __init of_unittest_apply_revert_overlay_check(int overlay_nr,
 		return -EINVAL;
 	}
 
+	if (!revert)
+		return 0;
+
 	/* remove the overlay */
 	save_ovcs_id = ovcs_id;
 	ret = of_overlay_remove(&ovcs_id);
@@ -2193,6 +2160,22 @@ static int __init of_unittest_apply_revert_overlay_check(int overlay_nr,
 	return 0;
 }
 
+/* apply an overlay while checking before and after states */
+static inline int __init of_unittest_apply_overlay_check(int overlay_nr,
+	int unittest_nr, int before, int after, enum overlay_type ovtype)
+{
+	return __of_unittest_apply_revert_overlay_check(overlay_nr,
+				unittest_nr, before, after, ovtype, false);
+}
+
+/* apply an overlay and then revert it while checking before, after states */
+static int __init of_unittest_apply_revert_overlay_check(int overlay_nr,
+	int unittest_nr, int before, int after, enum overlay_type ovtype)
+{
+	return __of_unittest_apply_revert_overlay_check(overlay_nr,
+				unittest_nr, before, after, ovtype, true);
+}
+
 /* test activation of device */
 static void __init of_unittest_overlay_0(void)
 {
-- 
2.34.1




[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux