mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Denis Orlov <denorl2009@gmail.com>
Cc: barebox@lists.infradead.org,
	Clement Leger <clement.leger@kalray.eu>,
	Oleksij Rempel <o.rempel@pengutronix.de>
Subject: Re: [PATCH] common: elf: use proper field to get segment memory size
Date: Thu, 16 Mar 2023 10:51:05 +0100	[thread overview]
Message-ID: <20230316095105.GX7446@pengutronix.de> (raw)
In-Reply-To: <20230315101126.4101087-1-denorl2009@gmail.com>

On Wed, Mar 15, 2023 at 01:11:26PM +0300, Denis Orlov wrote:
> For a program header, the value of 'p_filesz' may be less than the one
> of 'p_memsz', in which case the leftover amount of space should be
> filled with zeroes. This is done correctly when loading elf to memory.
> However, when we are requesting memory beforehand we do pass the value
> of 'p_filesz', instead of 'p_memsz', to 'request_sdram_region',
> resulting in potentially smaller amount of memory to be reserved.
> 
> As 'p_memsz' is always greater or equal to 'p_filesz', use only the
> former for checking memory requirements in 'request_elf_segment'.
> 
> Signed-off-by: Denis Orlov <denorl2009@gmail.com>
> ---
>  common/elf.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/common/elf.c b/common/elf.c
> index eec62cad61..c9b3d7bb37 100644
> --- a/common/elf.c
> +++ b/common/elf.c
> @@ -59,14 +59,13 @@ static int request_elf_segment(struct elf_image *elf, void *phdr)
>  {
>  	void *dst = (void *) (phys_addr_t) elf_phdr_p_paddr(elf, phdr);
>  	int ret;
> -	u64 p_filesz = elf_phdr_p_filesz(elf, phdr);
>  	u64 p_memsz = elf_phdr_p_memsz(elf, phdr);
>  
>  	/* we care only about PT_LOAD segments */
>  	if (elf_phdr_p_type(elf, phdr) != PT_LOAD)
>  		return 0;
>  
> -	if (!p_filesz)
> +	if (!p_memsz)
>  		return 0;
>  
>  	if (dst < elf->low_addr)
> @@ -74,9 +73,9 @@ static int request_elf_segment(struct elf_image *elf, void *phdr)
>  	if (dst + p_memsz > elf->high_addr)
>  		elf->high_addr = dst + p_memsz;
>  
> -	pr_debug("Requesting segment 0x%p (%llu bytes)\n", dst, p_filesz);
> +	pr_debug("Requesting segment 0x%p (%llu bytes)\n", dst, p_memsz);
>  
> -	ret = elf_request_region(elf, (resource_size_t)dst, p_filesz, phdr);
> +	ret = elf_request_region(elf, (resource_size_t)dst, p_memsz, phdr);
>  	if (ret)
>  		return ret;
>  
> -- 
> 2.30.2
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



      reply	other threads:[~2023-03-16  9:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-15 10:11 Denis Orlov
2023-03-16  9:51 ` Sascha Hauer [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=20230316095105.GX7446@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=clement.leger@kalray.eu \
    --cc=denorl2009@gmail.com \
    --cc=o.rempel@pengutronix.de \
    /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