Skip to content

Commit

Permalink
drivers: clk: limit print_clock_subtree() recursive calls
Browse files Browse the repository at this point in the history
Limit print_clock_subtree() recursive calls to 32.

Reported-by: Jens Wiklander <[email protected]>
Link: OP-TEE#6481 (comment)
Signed-off-by: Etienne Carriere <[email protected]>
  • Loading branch information
etienne-lms committed Nov 23, 2023
1 parent c7f9abc commit 34475e3
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions core/drivers/clk/clk.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#include <stddef.h>
#include <stdio.h>

/* Max number of recursive calls to print_clock_subtree() */
#define CLK_PRINT_TREE_MAX_RECURSION 32

/* Global clock tree lock */
static unsigned int clk_lock = SPINLOCK_UNLOCK;

Expand Down Expand Up @@ -392,6 +395,12 @@ static void print_clock_subtree(struct clk *clk_root __maybe_unused,
#ifdef CFG_DRIVERS_CLK_PRINT_TREE
struct clk *clk = NULL;

if (indent == CLK_PRINT_TREE_MAX_RECURSION) {
EMSG("Abort clk subtree loop, %d recursive calls reached",
CLK_PRINT_TREE_MAX_RECURSION);
return;
}

STAILQ_FOREACH(clk, &clock_list, link) {
if (clk_get_parent(clk) == clk_root) {
print_clock(clk, indent + 1);
Expand Down

0 comments on commit 34475e3

Please sign in to comment.