Skip to content

Commit

Permalink
librdmacm: Fix an overflow bug in qsort comparison function
Browse files Browse the repository at this point in the history
[ Upstream commit c4a5ac8 ]

The comparison function dev_cmp() doesn't work with 64b pointers in some
cases, as it casts the pointer to int. For example it's not able to sort
this list:
  {0xfffe0c2f0b00, 0xaaac741b4a90, 0xaaac741b4d70}

Fixes: e5d371c ("librdmacm: Globally store and sort IB device list")
Signed-off-by: Mark Zhang <[email protected]>
Reviewed-by: Leon Romanovsky <[email protected]>
Signed-off-by: Yishai Hadas <[email protected]>
Signed-off-by: Nicolas Morey <[email protected]>
  • Loading branch information
MarkZhang81 authored and nmorey committed May 27, 2024
1 parent 4f8027c commit b0fb0a7
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion librdmacm/cma.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ static void remove_cma_dev(struct cma_device *cma_dev)

static int dev_cmp(const void *a, const void *b)
{
return (int)(*(char *const *)a - *(char *const *)b);
return (*(uintptr_t *)a > *(uintptr_t *)b) - (*(uintptr_t *)a < *(uintptr_t *)b);
}

static int sync_devices_list(void)
Expand Down

0 comments on commit b0fb0a7

Please sign in to comment.