diff mbox series

[v5,24/28] clk: Test the clock pointer in clk_hw_get_name()

Message ID 20220516132527.328190-25-maxime@cerno.tech (mailing list archive)
State Superseded, archived
Headers show
Series clk: More clock rate fixes and tests | expand

Commit Message

Maxime Ripard May 16, 2022, 1:25 p.m. UTC
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.

Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com> # imx8mp
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com> # exynos4210, meson g12b
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
---
 drivers/clk/clk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Stephen Boyd June 29, 2022, 9:13 a.m. UTC | #1
Quoting Maxime Ripard (2022-05-16 06:25:23)
> 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.

Why do you have a NULL clk_hw pointer? Is there some caller that is
simplified with this patch?
Maxime Ripard June 29, 2022, 9:39 a.m. UTC | #2
Hi,

On Wed, Jun 29, 2022 at 02:13:49AM -0700, Stephen Boyd wrote:
> Quoting Maxime Ripard (2022-05-16 06:25:23)
> > 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.
> 
> Why do you have a NULL clk_hw pointer? Is there some caller that is
> simplified with this patch?

I encountered it while debugging the clock tree and assumed it would be
a good idea, but I don't another reason.

I'll drop it

Maxime
diff mbox series

Patch

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index d953ca61ea38..364e6baa3d1c 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -262,7 +262,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);