public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Conor Dooley <conor@kernel.org>
To: Mohamed Ayman <mohamedaymanworkspace@gmail.com>
Cc: Paul Walmsley <pjw@kernel.org>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>,
	Alexandre Ghiti <alex@ghiti.fr>,
	Andrew Jones <ajones@ventanamicro.com>,
	Conor Dooley <conor.dooley@microchip.com>,
	Anup Patel <apatel@ventanamicro.com>,
	"open list:RISC-V ARCHITECTURE" <linux-riscv@lists.infradead.org>,
	open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] riscv: cpuinfo: Fix NULL dereference and inconsistent error code
Date: Sun, 3 May 2026 18:54:48 +0100	[thread overview]
Message-ID: <20260503-duller-canyon-a2be827f9488@spud> (raw)
In-Reply-To: <20260502160301.453029-1-mohamedaymanworkspace@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1820 bytes --]

Hey,

On Sat, May 02, 2026 at 07:02:57PM +0300, 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.
> 
> 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.
> 
> Both issues improve robustness and consistency with existing RISC-V CPU info handling code.


These two things should be two different patches, since they're
completely unrelated.

Additionally, the patch is missing a signoff.

> ---
>  arch/riscv/kernel/cpu.c | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/riscv/kernel/cpu.c b/arch/riscv/kernel/cpu.c
> index 3dbc8cc557dd..e0bc7526861f 100644
> --- a/arch/riscv/kernel/cpu.c
> +++ b/arch/riscv/kernel/cpu.c
> @@ -135,7 +135,7 @@ int riscv_of_parent_hartid(struct device_node *node, unsigned long *hartid)
>  		}
>  	}
>  
> -	return -1;
> +	return -ENODEV;
>  }
>  
>  unsigned long __init riscv_get_marchid(void)
> @@ -348,12 +348,13 @@ static int c_show(struct seq_file *m, void *v)
>  
>  	if (acpi_disabled) {
>  		node = of_get_cpu_node(cpu_id, NULL);
> +		if (node) {

Is it actually possible for this to fail?

Cheers,
Conor.

> +			if (!of_property_read_string(node, "compatible", &compat) &&
> +				strcmp(compat, "riscv"))
> +				seq_printf(m, "uarch\t\t: %s\n", compat);
>  
> -		if (!of_property_read_string(node, "compatible", &compat) &&
> -		    strcmp(compat, "riscv"))
> -			seq_printf(m, "uarch\t\t: %s\n", compat);
> -
> -		of_node_put(node);
> +			of_node_put(node);
> +		}
>  	}
>  
>  	seq_printf(m, "mvendorid\t: 0x%lx\n", ci->mvendorid);
> -- 
> 2.34.1
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

  reply	other threads:[~2026-05-03 17:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-02 16:02 [PATCH] riscv: cpuinfo: Fix NULL dereference and inconsistent error code Mohamed Ayman
2026-05-03 17:54 ` Conor Dooley [this message]
  -- strict thread matches above, loose matches on Subject: below --
2026-05-02 16:17 Mohamed Ayman
2026-05-03 12:26 ` Michael Ellerman
2026-05-03 16:11   ` MOHAMED AYMAN

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260503-duller-canyon-a2be827f9488@spud \
    --to=conor@kernel.org \
    --cc=ajones@ventanamicro.com \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=apatel@ventanamicro.com \
    --cc=conor.dooley@microchip.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=mohamedaymanworkspace@gmail.com \
    --cc=palmer@dabbelt.com \
    --cc=pjw@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox