From 6f48f6f2a2df05bd7663917b694a4d881998f6c5 Mon Sep 17 00:00:00 2001 From: Andrew Goodbody Date: Wed, 23 Jul 2025 16:54:07 +0100 Subject: [PATCH 1/2] clk: versaclock: return value calculated by ERR_PTR In versaclock_get_name -ENOMEM is passed to ERR_PTR but nothing is done with the value that this calculates which is obviously not the intention of the code. This is confirmed by the code around where this function is called. Instead return the value from ERR_PTR. This issue was found by Smatch. Signed-off-by: Andrew Goodbody --- drivers/clk/clk_versaclock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/clk/clk_versaclock.c b/drivers/clk/clk_versaclock.c index 9ccaf13d242..790ea4dbe82 100644 --- a/drivers/clk/clk_versaclock.c +++ b/drivers/clk/clk_versaclock.c @@ -850,7 +850,7 @@ static char *versaclock_get_name(const char *dev_name, const char *clk_name, int buf = malloc(length); if (!buf) - ERR_PTR(-ENOMEM); + return ERR_PTR(-ENOMEM); if (index < 0) snprintf(buf, length, "%s.%s", dev_name, clk_name); From 2a13b59ed4317ec4483d1502d9db161f46985a32 Mon Sep 17 00:00:00 2001 From: Andrew Goodbody Date: Wed, 23 Jul 2025 16:54:08 +0100 Subject: [PATCH 2/2] clk: versaclock: Use IS_ERR check before dereference In versaclock_probe vc5->pin_xin may be an error pointer so need to check with IS_ERR before attempting to dereference it. This issue was found by Smatch. Signed-off-by: Andrew Goodbody --- drivers/clk/clk_versaclock.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/clk/clk_versaclock.c b/drivers/clk/clk_versaclock.c index 790ea4dbe82..19a787eaf0c 100644 --- a/drivers/clk/clk_versaclock.c +++ b/drivers/clk/clk_versaclock.c @@ -904,12 +904,12 @@ int versaclock_probe(struct udevice *dev) if (IS_ERR(mux_name)) return PTR_ERR(mux_name); - clk_register(&vc5->clk_mux, "versaclock-mux", mux_name, vc5->pin_xin->dev->name); - - if (!IS_ERR(vc5->pin_xin)) + if (!IS_ERR(vc5->pin_xin)) { + clk_register(&vc5->clk_mux, "versaclock-mux", mux_name, vc5->pin_xin->dev->name); vc5_mux_set_parent(&vc5->clk_mux, 1); - else + } else { vc5_mux_set_parent(&vc5->clk_mux, 0); + } /* Configure Optional Loading Capacitance for external XTAL */ if (!(vc5->chip_info->flags & VC5_HAS_INTERNAL_XTAL)) {