Re: [PATCH RFC] cache: Make cpu_cache_invalidate_memregion() error out if there are no handlers
From: Jonathan Cameron
Date: Tue Sep 22 2026 - 21:52:57 EST
On Tue, 22 Sep 2026 09:29:31 +0200
Bence Csokas <bence.csokas@xxxxxxx> wrote:
> Currently, if there are no registered handlers,
> cpu_cache_invalidate_memregion() returns 0. Callers are expected to check
> cpu_cache_has_invalidate_memregion() and return -ENXIO themselves, instead
> of calling this function. If a caller forgets to do this, they may
> erroneously think the operation succeeded. This is in contrast to x86,
> where cpu_cache_invalidate_memregion() itself checks if the operation is
> supported, and returns -ENXIO if it is not.
>
> Signed-off-by: Bence Csokas <bence.csokas@xxxxxxx>
As you noted short of a race we should never hit this in practice as
all callers must check for support first. Still good to close
that race.
Reviewed-by: Jonathan Cameron <jonathan.cameron@xxxxxxxxxxxxxxxx>
Jonathan
> ---
> lib/cache_maint.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/lib/cache_maint.c b/lib/cache_maint.c
> index 9256a9ffc34c..132d2816d6b1 100644
> --- a/lib/cache_maint.c
> +++ b/lib/cache_maint.c
> @@ -59,12 +59,12 @@ static int cache_inval_done_one(struct cache_coherency_ops_inst *cci)
>
> static int cache_invalidate_memregion(phys_addr_t addr, size_t size)
> {
> - int ret;
> struct cache_coherency_ops_inst *cci;
> struct cc_inval_params params = {
> .addr = addr,
> .size = size,
> };
> + int ret = -ENXIO;
>
> guard(rwsem_read)(&cache_ops_instance_list_lock);
> list_for_each_entry(cci, &cache_ops_instance_list, node) {
> @@ -78,7 +78,7 @@ static int cache_invalidate_memregion(phys_addr_t addr, size_t size)
> return ret;
> }
>
> - return 0;
> + return ret;
> }
>
> struct cache_coherency_ops_inst *
>