[PATCH v4 1/3] drm/drm_mm: Safe macro for iterating through nodes in range

Christian König christian.koenig at amd.com
Fri Mar 7 09:59:04 UTC 2025


Am 06.03.25 um 23:21 schrieb Tomasz Lis:
> Benefits of drm_mm_for_each_node_safe and drm_mm_for_each_node_in_range
> squished together into one macro.

Looks sane in general, but the other patches who actually use that never made it into my inbox.

Please send them out to me once more and maybe put Arun in CC as well.

Thanks,
Christian.

>
> Signed-off-by: Tomasz Lis <tomasz.lis at intel.com>
> ---
> Cc: dri-devel at lists.freedesktop.org
> Cc: Christian König <christian.koenig at amd.com>
> Cc: Arun R Murthy <arun.r.murthy at intel.com>
> Cc: Matthew Brost <matthew.brost at intel.com>
>
>  include/drm/drm_mm.h | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
>
> diff --git a/include/drm/drm_mm.h b/include/drm/drm_mm.h
> index f654874c4ce6..43e99441f6ba 100644
> --- a/include/drm/drm_mm.h
> +++ b/include/drm/drm_mm.h
> @@ -504,6 +504,25 @@ __drm_mm_interval_first(const struct drm_mm *mm, u64 start, u64 last);
>  	     node__->start < (end__);					\
>  	     node__ = list_next_entry(node__, node_list))
>  
> +/**
> + * drm_mm_for_each_node_in_range_safe - iterator to walk over a range of
> + * allocated nodes
> + * @node__: drm_mm_node structure to assign to in each iteration step
> + * @next__: &struct drm_mm_node to store the next step
> + * @mm__: drm_mm allocator to walk
> + * @start__: starting offset, the first node will overlap this
> + * @end__: ending offset, the last node will start before this (but may overlap)
> + *
> + * This iterator walks over all nodes in the range allocator that lie
> + * between @start and @end. It is implemented similarly to list_for_each_safe(),
> + * so safe against removal of elements.
> + */
> +#define drm_mm_for_each_node_in_range_safe(node__, next__, mm__, start__, end__)	\
> +	for (node__ = __drm_mm_interval_first((mm__), (start__), (end__)-1), \
> +		next__ = list_next_entry(node__, node_list); \
> +	     node__->start < (end__);					\
> +	     node__ = next__, next__ = list_next_entry(next__, node_list))
> +
>  void drm_mm_scan_init_with_range(struct drm_mm_scan *scan,
>  				 struct drm_mm *mm,
>  				 u64 size, u64 alignment, unsigned long color,



More information about the dri-devel mailing list