[PATCH] riscv: cpuinfo: Fix NULL dereference and inconsistent error code

MOHAMED AYMAN mohamedaymanworkspace at gmail.com
Sun May 3 09:11:35 PDT 2026


Thanks for the review Michael.

You're right, both of_property_read_string() and of_node_put() handle
NULL np internally, so the c_show() hunk is unnecessary. I'll drop it
in v3.

I'll also send the -ENODEV fix as a standalone patch as you suggested. :)

On Sun, May 3, 2026 at 3:26 PM Michael Ellerman <mpe at kernel.org> wrote:
>
> On 3/5/2026 02:17, Mohamed Ayman wrote:
> > Fix a potential NULL pointer dereference in c_show() by ensuring
> > the device tree node returned by of_get_cpu_node() is checked before use.
>
> Where is the NULL pointer deref?
>
> of_property_read_string() can cope with a NULL np, it just returns an error.
>
> of_node_put() also handles a NULL np.
>
> > Also replace a non-standard return value (-1) in
> > riscv_of_parent_hartid() with -ENODEV to follow Linux kernel
> > conventions for "not found" error returns.
>
> That should be a separate patch. It does look like a good change. At
> least some of the callers of riscv_of_parent_hartid() pass the return
> value up to their callers, so -1 could be misinterpreted somewhere as EPERM.
>
> cheers
>



More information about the linux-riscv mailing list