--- a/sys/dev/drm/amd/amdgpu/amdgpu_vm.c +++ b/sys/dev/drm/amd/amdgpu/amdgpu_vm.c @@ -3322,8 +3322,8 @@ * can not be used. * This code is removing all entries so it is fairly easy to replace. */ - while (vm->va.rb_leftmost) { - mapping = container_of((void *)vm->va.rb_leftmost, struct amdgpu_bo_va_mapping, rb); + while ((mapping = rb_entry_safe(rb_first(&vm->va.rb_root), + struct amdgpu_bo_va_mapping, rb))) { #endif /* Don't remove the mapping here, we don't want to trigger a * rebalance and the tree is about to be destroyed anyway.