All of lore.kernel.org
 help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert+renesas@glider.be>
To: Rob Herring <robh+dt@kernel.org>,
	Frank Rowand <frowand.list@gmail.com>,
	Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Cc: devicetree@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
	Geert Uytterhoeven <geert+renesas@glider.be>
Subject: [PATCH 06/13] of: unittest: Merge of_unittest_apply{,_revert}_overlay_check()
Date: Wed, 19 Jul 2023 17:00:06 +0200	[thread overview]
Message-ID: <b733ee0b398ace191a787cce965829f2777fc49e.1689776064.git.geert+renesas@glider.be> (raw)
In-Reply-To: <cover.1689776064.git.geert+renesas@glider.be>

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>
---
 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


  parent reply	other threads:[~2023-07-19 15:00 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-19 15:00 [PATCH 00/13] of: overlay/unittest: Miscellaneous fixes and improvements Geert Uytterhoeven
2023-07-19 15:00 ` [PATCH 01/13] of: dynamic: Do not use "%pOF" while holding devtree_lock Geert Uytterhoeven
2023-07-19 23:02   ` Rob Herring
2023-07-20 21:30     ` Rob Herring
2023-07-27 13:42     ` Geert Uytterhoeven
2023-07-19 15:00 ` [PATCH 02/13] of: overlay: Call of_changeset_init() early Geert Uytterhoeven
2023-07-19 15:00 ` [PATCH 03/13] of: unittest: Fix overlay type in apply/revert check Geert Uytterhoeven
2023-07-19 15:00 ` [PATCH 04/13] of: unittest: Restore indentation in overlay_bad_add_dup_prop test Geert Uytterhoeven
2023-07-19 15:00 ` [PATCH 05/13] of: unittest: Improve messages and comments in apply/revert checks Geert Uytterhoeven
2023-07-19 15:00 ` Geert Uytterhoeven [this message]
2023-07-20 18:31   ` [PATCH 06/13] of: unittest: Merge of_unittest_apply{,_revert}_overlay_check() Rob Herring
2023-07-27 14:04     ` Geert Uytterhoeven
2023-07-27 17:58       ` Rob Herring
2023-07-19 15:00 ` [PATCH 07/13] of: unittest: Cleanup partially-applied overlays Geert Uytterhoeven
2023-07-19 15:00 ` [PATCH 08/13] of: unittest: Add separators to of_unittest_overlay_high_level() Geert Uytterhoeven
2023-07-19 15:00 ` [PATCH 09/13] of: overlay: unittest: Add test for unresolved symbol Geert Uytterhoeven
2023-07-19 15:00 ` [PATCH 10/13] of: unittest-data: Convert remaining overlay DTS files to sugar syntax Geert Uytterhoeven
2023-07-19 15:00 ` [PATCH 11/13] of: unittest-data: Fix whitespace - blank lines Geert Uytterhoeven
2023-07-19 15:00 ` [PATCH 12/13] of: unittest-data: Fix whitespace - indentation Geert Uytterhoeven
2023-07-19 15:00 ` [PATCH 13/13] of: unittest-data: Fix whitespace - angular brackets Geert Uytterhoeven
2023-07-20 18:37 ` [PATCH 00/13] of: overlay/unittest: Miscellaneous fixes and improvements Rob Herring
2023-07-27 19:34   ` Frank Rowand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b733ee0b398ace191a787cce965829f2777fc49e.1689776064.git.geert+renesas@glider.be \
    --to=geert+renesas@glider.be \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=pantelis.antoniou@konsulko.com \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.