diff --git a/drivers/gpu/nvgpu/os/posix/bitmap.c b/drivers/gpu/nvgpu/os/posix/bitmap.c index 006f2898b..46b5b7065 100644 --- a/drivers/gpu/nvgpu/os/posix/bitmap.c +++ b/drivers/gpu/nvgpu/os/posix/bitmap.c @@ -57,7 +57,7 @@ static unsigned long __find_next_bit(const unsigned long *addr, unsigned long start, bool invert) { - unsigned long idx; + unsigned long idx, idx_max; unsigned long w; unsigned long start_mask; @@ -87,12 +87,18 @@ static unsigned long __find_next_bit(const unsigned long *addr, start = round_up(start, BITS_PER_LONG); + idx_max = (n - 1) / BITS_PER_LONG; + /* * Find the first non-zero word taking into account start and * invert. */ while (!w) { idx++; + if (idx > idx_max) { + return n; + } + start += BITS_PER_LONG; w = addr[idx] ^ invert_mask; diff --git a/userspace/units/posix/bitops/posix-bitops.c b/userspace/units/posix/bitops/posix-bitops.c index 6f8f6e221..aebc69039 100644 --- a/userspace/units/posix/bitops/posix-bitops.c +++ b/userspace/units/posix/bitops/posix-bitops.c @@ -199,7 +199,8 @@ static int test_find_first_bit(struct unit_module *m, * Now make sure that for full/empty bitmap find_next_*() returns * the size parameter. */ - memset(words, args->find_zeros ? 0xff : 0x00, sizeof(words)); + memset(words, args->find_zeros ? 0xff : 0x00, + NUM_WORDS * sizeof(words[0])); result = finder_function(words, NUM_WORDS * BITS_PER_LONG); if (result != NUM_WORDS * BITS_PER_LONG) unit_return_fail(m, "find_first_%s() failed with empty map\n",