[PATCH] resource: add CONFIG_DEBUG_RESOURCES option

Ahmad Fatoum a.fatoum at pengutronix.de
Mon Jul 22 10:06:41 PDT 2024


Whether a resource conflict is indeed a problem depends on how the user
handles it. Most users will propagate an -EBUSY error, but some will
gracefully handle it and move on.

We thus can't just warn unconditionally about conflicts in __request_region.
It's still useful to enable warnings there though while debugging, so
let's add a Kconfig option that enables these debugging prints.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 common/Kconfig.debug |  8 ++++++++
 common/resource.c    | 17 ++++++++++-------
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/common/Kconfig.debug b/common/Kconfig.debug
index 5d245de23c07..989f3ccc2a20 100644
--- a/common/Kconfig.debug
+++ b/common/Kconfig.debug
@@ -99,6 +99,14 @@ config DEBUG_LIST
 
 	  If unsure, say N.
 
+config DEBUG_RESOURCES
+	bool "Debug resource reservation"
+	help
+	  Enable this to bump verbosity of the resource reservation code
+	  from debug log level to info.
+
+	  If unsure, say N.
+
 config PBL_BREAK
 	bool "Execute software break on pbl start"
 	depends on ARM && (!CPU_32v4T && !ARCH_TEGRA)
diff --git a/common/resource.c b/common/resource.c
index 76f19de4942f..436a0488ddf0 100644
--- a/common/resource.c
+++ b/common/resource.c
@@ -13,6 +13,12 @@
 #include <linux/resource_ext.h>
 #include <asm/io.h>
 
+#ifdef CONFIG_DEBUG_RESOURCES
+#define res_dbg(args...)	pr_info(args)
+#else
+#define res_dbg(args...)	pr_debug(args)
+#endif
+
 static int init_resource(struct resource *res, const char *name)
 {
 	INIT_LIST_HEAD(&res->children);
@@ -35,8 +41,7 @@ struct resource *__request_region(struct resource *parent,
 	struct resource *r, *new;
 
 	if (end < start) {
-		debug("%s: request region 0x%08llx:0x%08llx: end < start\n",
-				__func__,
+		res_dbg("request region(0x%08llx:0x%08llx): end < start\n",
 				(unsigned long long)start,
 				(unsigned long long)end);
 		return ERR_PTR(-EINVAL);
@@ -44,8 +49,7 @@ struct resource *__request_region(struct resource *parent,
 
 	/* outside parent resource? */
 	if (start < parent->start || end > parent->end) {
-		debug("%s: 0x%08llx:0x%08llx outside parent resource 0x%08llx:0x%08llx\n",
-				__func__,
+		res_dbg("request region(0x%08llx:0x%08llx): outside parent resource 0x%08llx:0x%08llx\n",
 				(unsigned long long)start,
 				(unsigned long long)end,
 				(unsigned long long)parent->start,
@@ -62,8 +66,7 @@ struct resource *__request_region(struct resource *parent,
 			goto ok;
 		if (start > r->end)
 			continue;
-		debug("%s: 0x%08llx:0x%08llx (%s) conflicts with 0x%08llx:0x%08llx (%s)\n",
-				__func__,
+		res_dbg("request region(0x%08llx:0x%08llx): %s conflicts with 0x%08llx:0x%08llx (%s)\n",
 				(unsigned long long)start,
 				(unsigned long long)end,
 				name,
@@ -74,7 +77,7 @@ struct resource *__request_region(struct resource *parent,
 	}
 
 ok:
-	debug("%s ok: 0x%08llx:0x%08llx flags=0x%x\n", __func__,
+	res_dbg("request region(0x%08llx:0x%08llx): success flags=0x%x\n",
 			(unsigned long long)start,
 			(unsigned long long)end, flags);
 
-- 
2.39.2




More information about the barebox mailing list