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

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

 



On Wed, Jul 19, 2023 at 05:00:06PM +0200, Geert Uytterhoeven wrote:
> 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(-)

I would do something like this instead:

8<-------------------------------------------------------------------
diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index a406a12eb208..a9635935aa26 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -2102,7 +2102,7 @@ static int __init of_unittest_apply_overlay(int overlay_nr, int *ovcs_id)
 }
 
 /* apply an overlay while checking before and after states */
-static int __init of_unittest_apply_overlay_check(int overlay_nr,
+static int __init _of_unittest_apply_overlay_check(int overlay_nr,
 		int unittest_nr, int before, int after,
 		enum overlay_type ovtype)
 {
@@ -2133,6 +2133,16 @@ static int __init of_unittest_apply_overlay_check(int overlay_nr,
 		return -EINVAL;
 	}
 
+	return ovcs_id;
+}
+
+static int __init of_unittest_apply_overlay_check(int overlay_nr,
+		int unittest_nr, int before, int after,
+		enum overlay_type ovtype)
+{
+	int ovcs_id = _of_unittest_apply_overlay_check(overlay_nr, unittest_nr, before, after, ovtype);
+	if (ovcs_id < 0)
+		return ovcs_id;
 	return 0;
 }
 
@@ -2143,31 +2153,9 @@ static int __init of_unittest_apply_revert_overlay_check(int overlay_nr,
 {
 	int ret, ovcs_id, save_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 failed to create @\"%s\" %s\n",
-				overlay_name_from_nr(overlay_nr),
-				unittest_path(unittest_nr, ovtype),
-				!after ? "enabled" : "disabled");
-		return -EINVAL;
-	}
+	ovcs_id = _of_unittest_apply_overlay_check(overlay_nr, unittest_nr, before, after, ovtype);
+	if (ovcs_id < 0)
+		return ovcs_id;
 
 	save_ovcs_id = ovcs_id;
 	ret = of_overlay_remove(&ovcs_id);



[Index of Archives]     [Linux Samsung SOC]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux