git: 08635c51d1e3 - main - clkdom_dump(): improve output text

From: Mitchell Horne <mhorne_at_FreeBSD.org>
Date: Fri, 08 Mar 2024 14:10:06 UTC
The branch main has been updated by mhorne:

URL: https://cgit.FreeBSD.org/src/commit/?id=08635c51d1e34f8a3e42c7cf35dc7264a5b68118

commit 08635c51d1e34f8a3e42c7cf35dc7264a5b68118
Author:     Mitchell Horne <mhorne@FreeBSD.org>
AuthorDate: 2024-03-08 14:09:08 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2024-03-08 14:09:36 +0000

    clkdom_dump(): improve output text
    
    If the call to clknode_get_freq() returns an error (unlikely), report
    this, rather than printing the error code as the clock frequency.
    
    If the clock has no parent (e.g. a fixed reference clock), print "none"
    rather than "(NULL)(-1)". This is a more human-legible presentation of the
    same information.
    
    Reviewed by:    manu
    MFC after:      1 week
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D44267
---
 sys/dev/clk/clk.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/sys/dev/clk/clk.c b/sys/dev/clk/clk.c
index 52015d4e2905..5c74d84cacc8 100644
--- a/sys/dev/clk/clk.c
+++ b/sys/dev/clk/clk.c
@@ -512,10 +512,20 @@ clkdom_dump(struct clkdom * clkdom)
 	CLK_TOPO_SLOCK();
 	TAILQ_FOREACH(clknode, &clkdom->clknode_list, clkdom_link) {
 		rv = clknode_get_freq(clknode, &freq);
-		printf("Clock: %s, parent: %s(%d), freq: %ju\n", clknode->name,
-		    clknode->parent == NULL ? "(NULL)" : clknode->parent->name,
-		    clknode->parent_idx,
-		    (uintmax_t)((rv == 0) ? freq: rv));
+		if (rv != 0) {
+			printf("Clock: %s, error getting frequency: %d\n",
+			    clknode->name, rv);
+			continue;
+		}
+
+		if (clknode->parent != NULL) {
+			printf("Clock: %s, parent: %s(%d), freq: %ju\n",
+			    clknode->name, clknode->parent->name,
+			    clknode->parent_idx, (uintmax_t)freq);
+		} else {
+			printf("Clock: %s, parent: none, freq: %ju\n",
+			    clknode->name, (uintmax_t)freq);
+		}
 	}
 	CLK_TOPO_UNLOCK();
 }