Skip to content

Commit bd885fc

Browse files
committed
vfio: Fix smatch errors in vfio_combine_iova_ranges()
smatch reports: vfio_combine_iova_ranges() error: uninitialized symbol 'last'. vfio_combine_iova_ranges() error: potentially dereferencing uninitialized 'comb_end'. vfio_combine_iova_ranges() error: potentially dereferencing uninitialized 'comb_start'. These errors are only reachable via invalid input, in the case of @last when we receive an empty rb-tree or for @comb_{start,end} if the rb-tree is empty or otherwise fails to produce a second node that reduces the gap. Add tests with warnings for these cases. Reported-by: Cong Liu <liucong2@kylinos.cn> Link: https://lore.kernel.org/all/20230920095532.88135-1-liucong2@kylinos.cn Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Brett Creeley <brett.creeley@amd.com> Link: https://lore.kernel.org/r/20231002224325.3150842-1-alex.williamson@redhat.com Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
1 parent f9af5ad commit bd885fc

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

drivers/vfio/vfio_main.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,11 @@ void vfio_combine_iova_ranges(struct rb_root_cached *root, u32 cur_nodes,
946946
unsigned long last;
947947

948948
comb_start = interval_tree_iter_first(root, 0, ULONG_MAX);
949+
950+
/* Empty list */
951+
if (WARN_ON_ONCE(!comb_start))
952+
return;
953+
949954
curr = comb_start;
950955
while (curr) {
951956
last = curr->last;
@@ -975,6 +980,11 @@ void vfio_combine_iova_ranges(struct rb_root_cached *root, u32 cur_nodes,
975980
prev = curr;
976981
curr = interval_tree_iter_next(curr, 0, ULONG_MAX);
977982
}
983+
984+
/* Empty list or no nodes to combine */
985+
if (WARN_ON_ONCE(min_gap == ULONG_MAX))
986+
break;
987+
978988
comb_start->last = comb_end->last;
979989
interval_tree_remove(comb_end, root);
980990
cur_nodes--;

0 commit comments

Comments
 (0)