gpu: nvgpu: unit: fix valgrind errors in posix bitmap

Fix cases where valgrind reported conditional jump or move depends on
uninitialised value(s)

JIRA NVGPU-3098

Change-Id: I5699d1f8539ec29e6f1bac6452e216c72c4d9007
Signed-off-by: Philip Elcan <pelcan@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/2094640
Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: Thomas Fleury <tfleury@nvidia.com>
Reviewed-by: Alex Waterman <alexw@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
Philip Elcan
2019-04-10 17:04:20 -04:00
committed by mobile promotions
parent b0973eacbb
commit 13ad8142ef
2 changed files with 9 additions and 2 deletions

View File

@@ -57,7 +57,7 @@ static unsigned long __find_next_bit(const unsigned long *addr,
unsigned long start, unsigned long start,
bool invert) bool invert)
{ {
unsigned long idx; unsigned long idx, idx_max;
unsigned long w; unsigned long w;
unsigned long start_mask; 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); 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 * Find the first non-zero word taking into account start and
* invert. * invert.
*/ */
while (!w) { while (!w) {
idx++; idx++;
if (idx > idx_max) {
return n;
}
start += BITS_PER_LONG; start += BITS_PER_LONG;
w = addr[idx] ^ invert_mask; w = addr[idx] ^ invert_mask;

View File

@@ -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 * Now make sure that for full/empty bitmap find_next_*() returns
* the size parameter. * 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); result = finder_function(words, NUM_WORDS * BITS_PER_LONG);
if (result != NUM_WORDS * BITS_PER_LONG) if (result != NUM_WORDS * BITS_PER_LONG)
unit_return_fail(m, "find_first_%s() failed with empty map\n", unit_return_fail(m, "find_first_%s() failed with empty map\n",