[PATCH v2] lib/vsprintf: introduce OF_DEVICE_NODE_FLAG_MAX for %pOF

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

 



Introduce OF_DEVICE_NODE_FLAG_MAX for device node printk, if add
new device node flag, please add the corresponding flag abbreviation
to tbuf in device_node_string.

Signed-off-by: lijiazi <lijiazi@xxxxxxxxxx>
---
 Documentation/core-api/printk-formats.rst |  2 ++
 include/linux/of.h                        |  6 ++++++
 lib/vsprintf.c                            | 14 +++++++-------
 3 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/Documentation/core-api/printk-formats.rst b/Documentation/core-api/printk-formats.rst
index 8ebe46b1..c73ccad 100644
--- a/Documentation/core-api/printk-formats.rst
+++ b/Documentation/core-api/printk-formats.rst
@@ -441,6 +441,8 @@ Examples::
 							d - detached
 							P - Populated
 							B - Populated bus
+                                                        O - Overlay
+                                                        F - Overlay free cset
 
 Passed by reference.
 
diff --git a/include/linux/of.h b/include/linux/of.h
index c669c0a..0453601 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -147,6 +147,12 @@ extern raw_spinlock_t devtree_lock;
 #define OF_OVERLAY		5 /* allocated for an overlay */
 #define OF_OVERLAY_FREE_CSET	6 /* in overlay cset being freed */
 
+/* Add flag max for %pOF related printk, if add new flag, please
+ * increase following marco, and add abbreviations to tbuf in
+ * device_node_string function.
+ */
+#define OF_DEVICE_NODE_FLAG_MAX 6 /* maximum available flags */
+
 #define OF_BAD_ADDR	((u64)-1)
 
 #ifdef CONFIG_OF
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 7c488a1..3c219b4 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1937,9 +1937,9 @@ static noinline_for_stack
 char *device_node_string(char *buf, char *end, struct device_node *dn,
 			 struct printf_spec spec, const char *fmt)
 {
-	char tbuf[sizeof("xxxx") + 1];
+	char tbuf[OF_DEVICE_NODE_FLAG_MAX + 1] = { "DdPBOF" };
 	const char *p;
-	int ret;
+	int ret, i;
 	char *buf_start = buf;
 	struct property *prop;
 	bool has_mult, pass;
@@ -1997,11 +1997,11 @@ char *device_node_string(char *buf, char *end, struct device_node *dn,
 			buf = string(buf, end, p, str_spec);
 			break;
 		case 'F':	/* flags */
-			tbuf[0] = of_node_check_flag(dn, OF_DYNAMIC) ? 'D' : '-';
-			tbuf[1] = of_node_check_flag(dn, OF_DETACHED) ? 'd' : '-';
-			tbuf[2] = of_node_check_flag(dn, OF_POPULATED) ? 'P' : '-';
-			tbuf[3] = of_node_check_flag(dn, OF_POPULATED_BUS) ? 'B' : '-';
-			tbuf[4] = 0;
+			for (i = 0; i < OF_DEVICE_NODE_FLAG_MAX; i++) {
+				if (!of_node_check_flag(dn, OF_DYNAMIC + i))
+					tbuf[i] = '-';
+			}
+			tbuf[OF_DEVICE_NODE_FLAG_MAX] = 0;
 			buf = string_nocheck(buf, end, tbuf, str_spec);
 			break;
 		case 'c':	/* major compatible string */
-- 
2.7.4




[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