git: 327987597bff - stable/14 - clkdom_dump(): improve output text

From: Mitchell Horne <mhorne_at_FreeBSD.org>
Date: Thu, 18 Apr 2024 18:12:26 UTC
The branch stable/14 has been updated by mhorne:

URL: https://cgit.FreeBSD.org/src/commit/?id=327987597bff4db5984d7704e7235647cc76c931

commit 327987597bff4db5984d7704e7235647cc76c931
Author:     Mitchell Horne <mhorne@FreeBSD.org>
AuthorDate: 2024-03-08 14:09:08 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2024-04-18 18:11:31 +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
    
    (cherry picked from commit 08635c51d1e34f8a3e42c7cf35dc7264a5b68118)
---
 sys/dev/extres/clk/clk.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/sys/dev/extres/clk/clk.c b/sys/dev/extres/clk/clk.c
index c569b05b6189..46a1aaaf6fd9 100644
--- a/sys/dev/extres/clk/clk.c
+++ b/sys/dev/extres/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();
 }