mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 09/15] resource: implement resize_region
Date: Fri, 6 Feb 2026 16:26:15 +0100	[thread overview]
Message-ID: <92758958-730e-4c1b-9f8c-669774f904bb@pengutronix.de> (raw)
In-Reply-To: <aXymTDe0IbYjBO2h@pengutronix.de>

Hi,

On 1/30/26 1:38 PM, Sascha Hauer wrote:
> On Tue, Jan 27, 2026 at 09:39:19AM +0100, Ahmad Fatoum wrote:
>> resize_region allows enlarging or reducing a region end while checking
>> for conflicts. This is less effort than removing a region and
>> reallocating it.
>>
>> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
>> ---
>>  common/resource.c      | 45 ++++++++++++++++++++++++++++++++++++++++++
>>  include/linux/ioport.h |  2 ++
>>  2 files changed, 47 insertions(+)
>>
>> diff --git a/common/resource.c b/common/resource.c
>> index e391d268e0bb..39867da63b69 100644
>> --- a/common/resource.c
>> +++ b/common/resource.c
>> @@ -92,6 +92,51 @@ struct resource *__request_region(struct resource *parent,
>>  	return new;
>>  }
>>  
>> +int resize_region(struct resource *res, resource_size_t size)
>> +{
>> +	struct resource *parent;
>> +	struct resource *next;
>> +	resource_size_t newend;
>> +
>> +	if (!res)
>> +		return 0;
>> +	if (!size)
>> +		return release_region(res);
> 
> This frees the resource itself. I am not sure if this is useful. It's an
> invitation for the caller to reference freed memory. I think the caller
> must distinguish between resizing and releasing the resource anyway, so
> he could equally call resize_region() or release_region() directly.

You're right. I did actually have a use after free for 0 size :D

>> +
>> +	if (size == resource_size(res))
>> +		return 0;
>> +
>> +	if (size < resource_size(res)) {
>> +		res->end = res->start + size - 1;
>> +		return 0;
>> +	}
> 
> A resource can have child resources. For completeness we should check if
> the child resources are still inside the now smaller parent resource.

Ok will do.

Cheers,
Ahmad

> 
> Sascha
> 

-- 
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:[~2026-02-06 15:27 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-27  8:39 [PATCH 00/15] bootm: prepare loadable abstraction rework Ahmad Fatoum
2026-01-27  8:39 ` [PATCH 01/15] FIT: implement fit_count_images Ahmad Fatoum
2026-01-27  8:39 ` [PATCH 02/15] FIT: add image index argument to fit_open_image Ahmad Fatoum
2026-01-27  8:39 ` [PATCH 03/15] resource: implement gap-aware lookup_region Ahmad Fatoum
2026-01-27  8:39 ` [PATCH 04/15] bootm: give bootm_load_ functions an end address Ahmad Fatoum
2026-01-27 15:31   ` Ahmad Fatoum
2026-01-30 13:35     ` Sascha Hauer
2026-01-27  8:39 ` [PATCH 05/15] bootm: store separate image_type and kernel_type Ahmad Fatoum
2026-01-27  8:39 ` [PATCH 06/15] bootm: cache os_file for appendroot purposes Ahmad Fatoum
2026-01-27  8:39 ` [PATCH 07/15] bootm: fit: move length calculation into fit_open Ahmad Fatoum
2026-01-27  8:39 ` [PATCH 08/15] libfile: factor out zero-page resistant read_file as __read_full_anywhere Ahmad Fatoum
2026-01-27  8:39 ` [PATCH 09/15] resource: implement resize_region Ahmad Fatoum
2026-01-30 12:38   ` Sascha Hauer
2026-02-06 15:26     ` Ahmad Fatoum [this message]
2026-01-27  8:39 ` [PATCH 10/15] bootm: rename image_data::os/initrd with _uimage suffix Ahmad Fatoum
2026-01-27  8:39 ` [PATCH 11/15] uimage: record original file name in uimage_handle Ahmad Fatoum
2026-01-27  8:39 ` [PATCH 12/15] bootm: factor out file detection into helper Ahmad Fatoum
2026-01-27  8:39 ` [PATCH 13/15] efi: payload: bootm: add dry run support Ahmad Fatoum
2026-01-27  8:39 ` [PATCH 14/15] efi: payload: bootm: fix memory corruption on initrd load error Ahmad Fatoum
2026-01-27  8:39 ` [PATCH 15/15] efi: initrd: make efi_initrd_register initrd pointer param const Ahmad Fatoum
2026-02-10  9:02 ` (subset) [PATCH 00/15] bootm: prepare loadable abstraction rework Sascha Hauer

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=92758958-730e-4c1b-9f8c-669774f904bb@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@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