[PATCH] clk: si5341: Fix NULL pointer dereference in probe

Yang Zi posted 1 patch 1 month ago
drivers/clk/clk-si5341.c | 3 +++
1 file changed, 3 insertions(+)
[PATCH] clk: si5341: Fix NULL pointer dereference in probe
Posted by Yang Zi 1 month ago
si5341_probe() dereferences client->dev.of_node->name without first
checking that a device tree node is present. When the device is
instantiated without DT, e.g. via sysfs "new_device", client->dev.of_node
is NULL and probe crashes with a NULL pointer dereference.

Add an early check and return -ENODEV when no of_node is available, since
this driver requires device tree bindings.

Signed-off-by: Yang Zi <2959243019@qq.com>
---
 drivers/clk/clk-si5341.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/clk/clk-si5341.c b/drivers/clk/clk-si5341.c
index 2499b771cd83..9d901c2fd0df 100644
--- a/drivers/clk/clk-si5341.c
+++ b/drivers/clk/clk-si5341.c
@@ -1567,6 +1567,9 @@ static int si5341_probe(struct i2c_client *client)
     bool initialization_required;
     u32 status;
 
+    if (!client->dev.of_node)
+        return -ENODEV;
+
     data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
     if (!data)
         return -ENOMEM;


Re: [PATCH] clk: si5341: Fix NULL pointer dereference in probe
Posted by Brian Masney 1 month ago
Hi Yang,

On Tue, Aug 25, 2026 at 04:59:56PM +0800, Yang Zi wrote:
> si5341_probe() dereferences client->dev.of_node->name without first
> checking that a device tree node is present. When the device is
> instantiated without DT, e.g. via sysfs "new_device", client->dev.of_node
> is NULL and probe crashes with a NULL pointer dereference.
> 
> Add an early check and return -ENODEV when no of_node is available, since
> this driver requires device tree bindings.
> 
> Signed-off-by: Yang Zi <2959243019@qq.com>

This patch doesn't apply against linux-next. Otherwise the change looks
fine to me.

Brian


> ---
>  drivers/clk/clk-si5341.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/clk/clk-si5341.c b/drivers/clk/clk-si5341.c
> index 2499b771cd83..9d901c2fd0df 100644
> --- a/drivers/clk/clk-si5341.c
> +++ b/drivers/clk/clk-si5341.c
> @@ -1567,6 +1567,9 @@ static int si5341_probe(struct i2c_client *client)
>      bool initialization_required;
>      u32 status;
>  
> +    if (!client->dev.of_node)
> +        return -ENODEV;
> +
>      data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
>      if (!data)
>          return -ENOMEM;
> 
>