Re: [RESEND PATCH 1/2] iommu/iova: Add check for cpu_rcache in free_iova_rcaches

From: zhangzekun (A)
Date: Fri Aug 11 2023 - 22:22:00 EST


在 2023/8/11 21:32, Robin Murphy 写道:
On 2023-08-11 14:02, Zhang Zekun wrote:
free_iova_rcaches() needs to check if cpu_rcache->loaded and
cpu_rcache->prev is NULL before freeing them.

Why? iova_magazine_free() is just kfree(), and kfree(NULL) is perfectly valid, specifically to avoid having to make cleanup paths all fiddly and overcomplicated like this.

Thanks,
Robin.

Hi, Robin
Thanks for your review, I have missed that kfree() can handle NULL and it is safe
to iterate through all cpus, because __alloc_percpu() will alloc a zero-filled area,
and pointers passed to kfree() will be either NULL or a vaild one. There is no need
to add check before these pointers.

Thanks,
Zekun