idr: Fix handling of IDs above INT_MAX
authorMatthew Wilcox <mawilcox@microsoft.com>
Mon, 26 Feb 2018 19:39:30 +0000 (14:39 -0500)
committerMatthew Wilcox <mawilcox@microsoft.com>
Mon, 26 Feb 2018 19:39:30 +0000 (14:39 -0500)
commit4b0ad07653ee94182e2d8f21404242c9e83ad0b4
tree88d581f08d2eac9d8b5d933c2740b91003e44401
parent3d4d5d618639c3155cfce57101d619a0935434d2
idr: Fix handling of IDs above INT_MAX

Khalid reported that the kernel selftests are currently failing:

selftests: test_bpf.sh
========================================
test_bpf: [FAIL]
not ok 1..8 selftests:  test_bpf.sh [FAIL]

He bisected it to 6ce711f2750031d12cec91384ac5cfa0a485b60a ("idr: Make
1-based IDRs more efficient").

The root cause is doing a signed comparison in idr_alloc_u32() instead
of an unsigned comparison.  I went looking for any similar problems and
found a couple (which would each result in the failure to warn in two
situations that aren't supposed to happen).

I knocked up a few test-cases to prove that I was right and added them
to the test-suite.

Reported-by: Khalid Aziz <khalid.aziz@oracle.com>
Tested-by: Khalid Aziz <khalid.aziz@oracle.com>
Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
lib/idr.c
tools/testing/radix-tree/idr-test.c