[PATCH 09/15] resource: implement resize_region

Sascha Hauer s.hauer at pengutronix.de
Fri Jan 30 04:38:36 PST 2026


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 at 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.

> +
> +	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.

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 |



More information about the barebox mailing list