Linux-RISC-V Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Nick Kossifidis <mick@ics.forth.gr>
To: Petr Pavlu <petr.pavlu@suse.com>
Cc: palmer@dabbelt.com, paul.walmsley@sifive.com,
	aou@eecs.berkeley.edu, mick@ics.forth.gr,
	linux-riscv@lists.infradead.org
Subject: Re: [PATCH] riscv: Fix a number of free'd resources in init_resources()
Date: Sun, 08 Aug 2021 01:54:51 +0300	[thread overview]
Message-ID: <7419f5a24ad3f53d74432d14fe0881b6@mailhost.ics.forth.gr> (raw)
In-Reply-To: <7e3ebd5a-cd41-4591-ba2d-0151fa45e8ea@suse.com>

Στις 2021-08-07 20:54, Petr Pavlu έγραψε:
> Function init_resources() allocates a boot memory block to hold an 
> array of
> resources which it adds to iomem_resource. The array is filled in from 
> its
> end and the function then attempts to free any unused memory at the
> beginning. The problem is that size of the unused memory is incorrectly
> calculated and this can result in releasing memory which is in use by
> active resources. Their data then gets corrupted later when the memory 
> is
> reused by a different part of the system.
> 
> Fix the size of the released memory to correctly match the number of 
> unused
> resource entries.
> 
> Fixes: ffe0e5261268 ("RISC-V: Improve init_resources()")
> Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>
> ---
>  arch/riscv/kernel/setup.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
> index 18bd0e4bc36c..120b2f6f71bc 100644
> --- a/arch/riscv/kernel/setup.c
> +++ b/arch/riscv/kernel/setup.c
> @@ -229,8 +229,8 @@ static void __init init_resources(void)
>  	}
> 
>  	/* Clean-up any unused pre-allocated resources */
> -	mem_res_sz = (num_resources - res_idx + 1) * sizeof(*mem_res);
> -	memblock_free(__pa(mem_res), mem_res_sz);
> +	if (res_idx >= 0)
> +		memblock_free(__pa(mem_res), (res_idx + 1) * sizeof(*mem_res));
>  	return;
> 
>   error:

Ouch! Thanks for the fix.

Acked-by: Nick Kossifidis <mick@ics.forth.gr>

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  reply	other threads:[~2021-08-07 22:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-07 17:54 [PATCH] riscv: Fix a number of free'd resources in init_resources() Petr Pavlu
2021-08-07 22:54 ` Nick Kossifidis [this message]
2021-08-08 10:35 ` Sunil V L
2021-08-20 17:33 ` Palmer Dabbelt

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=7419f5a24ad3f53d74432d14fe0881b6@mailhost.ics.forth.gr \
    --to=mick@ics.forth.gr \
    --cc=aou@eecs.berkeley.edu \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.com \
    --cc=petr.pavlu@suse.com \
    /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