[PATCH 21/22] clk: Test the clock pointer in clk_hw_get_name()

Maxime Ripard
2022-04-08T09:14:42Z

Unlike __clk_get_name(), clk_hw_get_name() doesn't test wether passed
clk_hw pointer is NULL or not and dereferences it directly. This can
then lead to NULL pointer dereference.

Let's make sure the pointer isn't NULL before dereferencing it.

Signed-off-by: Maxime Ripard <maxime@cerno.tech>
---
drivers/clk/clk.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 3fbd55119215..8bbb6adeeead 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -269,7 +269,7 @@ EXPORT_SYMBOL_GPL(__clk_get_name);

const char *clk_hw_get_name(const struct clk_hw *hw)
{
- return hw->core->name;
+ return !hw ? NULL : hw->core->name;
}
EXPORT_SYMBOL_GPL(clk_hw_get_name);

--
2.35.1