public inbox for linux-kernel-mentees@lists.linux-foundation.org
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Remington Brasga <rbrasga@uci.edu>,
	Christian Heusel <christian@heusel.eu>,
	Shuah Khan <skhan@linuxfoundation.org>,
	"Ahmed S . Darwish" <darwi@linutronix.de>
Cc: linux-kernel@vger.kernel.org,
	linux-kernel-mentees@lists.linuxfoundation.org,
	Remington Brasga <rbrasga@uci.edu>
Subject: Re: [PATCH] kcpuid: Fix potential dereferencing of null pointers
Date: Sun, 29 Sep 2024 12:52:30 +0200	[thread overview]
Message-ID: <87v7ye20lt.ffs@tglx> (raw)
In-Reply-To: <20240926223557.2048-1-rbrasga@uci.edu>

On Thu, Sep 26 2024 at 22:35, Remington Brasga wrote:
>  	if (!func->leafs) {
>  		func->leafs = malloc(sizeof(struct subleaf));
> -		if (!func->leafs)
> +		if (!func->leafs) {
>  			perror("malloc func leaf");
> +			return false; // On malloc failure

Please get rid of these horrible and pointless tail comments.

Returning false here does not make sense. This simply should terminate
the program.

> +		}
>  
>  		func->nr = 1;
>  	} else {
>  		s = func->nr;
>  		func->leafs = realloc(func->leafs, (s + 1) * sizeof(*leaf));
> -		if (!func->leafs)
> +		if (!func->leafs) {
>  			perror("realloc f->leafs");
> +			return false; // On realloc failure
> +		}
>  
>  		func->nr++;
>  	}
>  
> +	// Check for valid index
> +	if (s >= func->nr) {

What's the point of this? s is guaranteed to be < func->nr, no?

Thanks,

        tglx

      reply	other threads:[~2024-09-29 11:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-26 22:35 [PATCH] kcpuid: Fix potential dereferencing of null pointers Remington Brasga
2024-09-29 10:52 ` Thomas Gleixner [this message]

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=87v7ye20lt.ffs@tglx \
    --to=tglx@linutronix.de \
    --cc=christian@heusel.eu \
    --cc=darwi@linutronix.de \
    --cc=linux-kernel-mentees@lists.linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rbrasga@uci.edu \
    --cc=skhan@linuxfoundation.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