Skip to content

Commit

Permalink
vfio: Fix smatch errors in vfio_combine_iova_ranges()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Link: https://lore.kernel.org/all/[email protected]
Reviewed-by: Jason Gunthorpe <[email protected]>
Reviewed-by: Brett Creeley <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Alex Williamson <[email protected]>
  • Loading branch information
awilliam committed Oct 9, 2023
1 parent f9af5ad commit bd885fc
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions drivers/vfio/vfio_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,11 @@ void vfio_combine_iova_ranges(struct rb_root_cached *root, u32 cur_nodes,
unsigned long last;

comb_start = interval_tree_iter_first(root, 0, ULONG_MAX);

/* Empty list */
if (WARN_ON_ONCE(!comb_start))
return;

curr = comb_start;
while (curr) {
last = curr->last;
Expand Down Expand Up @@ -975,6 +980,11 @@ void vfio_combine_iova_ranges(struct rb_root_cached *root, u32 cur_nodes,
prev = curr;
curr = interval_tree_iter_next(curr, 0, ULONG_MAX);
}

/* Empty list or no nodes to combine */
if (WARN_ON_ONCE(min_gap == ULONG_MAX))
break;

comb_start->last = comb_end->last;
interval_tree_remove(comb_end, root);
cur_nodes--;
Expand Down

0 comments on commit bd885fc

Please sign in to comment.