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 v2 06/13] of: unittest: Merge of_unittest_apply{,_revert}_overlay_check()
Date: Fri, 28 Jul 2023 10:50:32 +0200	[thread overview]
Message-ID: <4bafe338655beab6b244047e737c0c2aa60b613d.1690533838.git.geert+renesas@glider.be> (raw)
In-Reply-To: <cover.1690533838.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>
---
v2:
  - Merge differently, as requested by Rob.
---
 drivers/of/unittest.c | 45 +++++++++++++++++--------------------------
 1 file changed, 18 insertions(+), 27 deletions(-)

diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index 42abfcd0cdffa4af..b23a44de091bd044 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -2101,8 +2101,7 @@ 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,
+static int __init __of_unittest_apply_overlay_check(int overlay_nr,
 		int unittest_nr, int before, int after,
 		enum overlay_type ovtype)
 {
@@ -2134,6 +2133,19 @@ static int __init of_unittest_apply_overlay_check(int overlay_nr,
 		return -EINVAL;
 	}
 
+	return ovcs_id;
+}
+
+/* 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 ovcs_id = __of_unittest_apply_overlay_check(overlay_nr,
+				unittest_nr, before, after, ovtype);
+	if (ovcs_id < 0)
+		return ovcs_id;
+
 	return 0;
 }
 
@@ -2144,31 +2156,10 @@ 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 with device @\"%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;
 
 	/* remove the overlay */
 	save_ovcs_id = ovcs_id;
-- 
2.34.1


  parent reply	other threads:[~2023-07-28  8:53 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-28  8:50 [PATCH v2 00/13] of: overlay/unittest: Miscellaneous fixes and improvements Geert Uytterhoeven
2023-07-28  8:50 ` [PATCH v2 01/13] of: dynamic: Do not use "%pOF" while holding devtree_lock Geert Uytterhoeven
2023-07-28  8:50 ` [PATCH v2 02/13] of: overlay: Call of_changeset_init() early Geert Uytterhoeven
2023-07-28  8:50 ` [PATCH v2 03/13] of: unittest: Fix overlay type in apply/revert check Geert Uytterhoeven
2023-07-28  8:50 ` [PATCH v2 04/13] of: unittest: Restore indentation in overlay_bad_add_dup_prop test Geert Uytterhoeven
2023-07-28  8:50 ` [PATCH v2 05/13] of: unittest: Improve messages and comments in apply/revert checks Geert Uytterhoeven
2023-07-28  8:50 ` Geert Uytterhoeven [this message]
2023-07-28  8:50 ` [PATCH v2 07/13] of: unittest: Cleanup partially-applied overlays Geert Uytterhoeven
2023-08-01 20:50   ` Rob Herring
2023-08-14  9:21     ` Geert Uytterhoeven
2023-08-24  1:06       ` Rob Herring
2023-07-28  8:50 ` [PATCH v2 08/13] of: unittest: Add separators to of_unittest_overlay_high_level() Geert Uytterhoeven
2023-07-28  8:50 ` [PATCH v2 09/13] of: overlay: unittest: Add test for unresolved symbol Geert Uytterhoeven
2023-07-28  8:50 ` [PATCH v2 10/13] of: unittest-data: Convert remaining overlay DTS files to sugar syntax Geert Uytterhoeven
2023-07-28  8:50 ` [PATCH v2 11/13] of: unittest-data: Fix whitespace - blank lines Geert Uytterhoeven
2023-07-28  8:50 ` [PATCH v2 12/13] of: unittest-data: Fix whitespace - indentation Geert Uytterhoeven
2023-07-28  8:50 ` [PATCH v2 13/13] of: unittest-data: Fix whitespace - angular brackets Geert Uytterhoeven
2023-07-31 16:14 ` [PATCH v2 00/13] of: overlay/unittest: Miscellaneous fixes and improvements Rob Herring
2023-07-31 16:35   ` Rob Herring
2023-08-14 10:08     ` Geert Uytterhoeven

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=4bafe338655beab6b244047e737c0c2aa60b613d.1690533838.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.