summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/common/mm/bitmap_allocator.c
diff options
context:
space:
mode:
authorAmulya <Amurthyreddy@nvidia.com>2018-08-28 03:04:55 -0400
committermobile promotions <svcmobile_promotions@nvidia.com>2018-09-19 06:24:12 -0400
commit941ac9a9d07bedb4062fd0c4d32eb2ef80a42359 (patch)
treec53622d96a4c2e7c18693ecf4059d7e403cd7808 /drivers/gpu/nvgpu/common/mm/bitmap_allocator.c
parent2805f03aa0496502b64ff760f667bfe9d8a27928 (diff)
nvgpu: common: MISRA 10.1 boolean fixes
Fix violations where a variable of type non-boolean is used as a boolean in gpu/nvgpu/common. JIRA NVGPU-646 Change-Id: I9773d863b715f83ae1772b75d5373f77244bc8ca Signed-off-by: Amulya <Amurthyreddy@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/1807132 GVS: Gerrit_Virtual_Submit Tested-by: Amulya Murthyreddy <amurthyreddy@nvidia.com> Reviewed-by: Vijayakumar Subbu <vsubbu@nvidia.com> Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/common/mm/bitmap_allocator.c')
-rw-r--r--drivers/gpu/nvgpu/common/mm/bitmap_allocator.c38
1 files changed, 20 insertions, 18 deletions
diff --git a/drivers/gpu/nvgpu/common/mm/bitmap_allocator.c b/drivers/gpu/nvgpu/common/mm/bitmap_allocator.c
index 6b9db23c..e5b9b378 100644
--- a/drivers/gpu/nvgpu/common/mm/bitmap_allocator.c
+++ b/drivers/gpu/nvgpu/common/mm/bitmap_allocator.c
@@ -42,10 +42,10 @@ static u64 nvgpu_bitmap_alloc_base(struct nvgpu_allocator *a)
42 return ba->base; 42 return ba->base;
43} 43}
44 44
45static int nvgpu_bitmap_alloc_inited(struct nvgpu_allocator *a) 45static bool nvgpu_bitmap_alloc_inited(struct nvgpu_allocator *a)
46{ 46{
47 struct nvgpu_bitmap_allocator *ba = a->priv; 47 struct nvgpu_bitmap_allocator *ba = a->priv;
48 int inited = ba->inited; 48 bool inited = ba->inited;
49 49
50 nvgpu_smp_rmb(); 50 nvgpu_smp_rmb();
51 return inited; 51 return inited;
@@ -160,7 +160,7 @@ static struct nvgpu_bitmap_alloc *find_alloc_metadata(
160 struct nvgpu_rbtree_node *node = NULL; 160 struct nvgpu_rbtree_node *node = NULL;
161 161
162 nvgpu_rbtree_search(addr, &node, a->allocs); 162 nvgpu_rbtree_search(addr, &node, a->allocs);
163 if (!node) { 163 if (node == NULL) {
164 return NULL; 164 return NULL;
165 } 165 }
166 166
@@ -180,7 +180,7 @@ static int nvgpu_bitmap_store_alloc(struct nvgpu_bitmap_allocator *a,
180 struct nvgpu_bitmap_alloc *alloc = 180 struct nvgpu_bitmap_alloc *alloc =
181 nvgpu_kmem_cache_alloc(a->meta_data_cache); 181 nvgpu_kmem_cache_alloc(a->meta_data_cache);
182 182
183 if (!alloc) { 183 if (alloc == NULL) {
184 return -ENOMEM; 184 return -ENOMEM;
185 } 185 }
186 186
@@ -243,8 +243,8 @@ static u64 nvgpu_bitmap_alloc(struct nvgpu_allocator *na, u64 len)
243 * either of these possibilities assume that the caller will keep what 243 * either of these possibilities assume that the caller will keep what
244 * data it needs around to successfully free this allocation. 244 * data it needs around to successfully free this allocation.
245 */ 245 */
246 if (!(a->flags & GPU_ALLOC_NO_ALLOC_PAGE) && 246 if ((a->flags & GPU_ALLOC_NO_ALLOC_PAGE) == 0ULL &&
247 nvgpu_bitmap_store_alloc(a, addr, blks * a->blk_size)) { 247 nvgpu_bitmap_store_alloc(a, addr, blks * a->blk_size) != 0) {
248 goto fail_reset_bitmap; 248 goto fail_reset_bitmap;
249 } 249 }
250 250
@@ -280,7 +280,7 @@ static void nvgpu_bitmap_free(struct nvgpu_allocator *na, u64 addr)
280 } 280 }
281 281
282 alloc = find_alloc_metadata(a, addr); 282 alloc = find_alloc_metadata(a, addr);
283 if (!alloc) { 283 if (alloc == NULL) {
284 goto done; 284 goto done;
285 } 285 }
286 286
@@ -299,7 +299,7 @@ static void nvgpu_bitmap_free(struct nvgpu_allocator *na, u64 addr)
299 a->bytes_freed += alloc->length; 299 a->bytes_freed += alloc->length;
300 300
301done: 301done:
302 if (a->meta_data_cache && alloc) { 302 if (a->meta_data_cache != NULL && alloc != NULL) {
303 nvgpu_kmem_cache_free(a->meta_data_cache, alloc); 303 nvgpu_kmem_cache_free(a->meta_data_cache, alloc);
304 } 304 }
305 alloc_unlock(na); 305 alloc_unlock(na);
@@ -377,27 +377,29 @@ int nvgpu_bitmap_allocator_init(struct gk20a *g, struct nvgpu_allocator *na,
377{ 377{
378 int err; 378 int err;
379 struct nvgpu_bitmap_allocator *a; 379 struct nvgpu_bitmap_allocator *a;
380 bool is_blk_size_pwr_2 = (blk_size & (blk_size - 1ULL)) == 0ULL;
381 bool is_base_aligned = (base & (blk_size - 1ULL)) == 0ULL;
382 bool is_length_aligned = (length & (blk_size - 1ULL)) == 0ULL;
380 383
381 if (WARN_ON(blk_size & (blk_size - 1U))) { 384 if (WARN_ON(!is_blk_size_pwr_2)) {
382 return -EINVAL; 385 return -EINVAL;
383 } 386 }
384 387
385 /* 388 /*
386 * blk_size must be a power-of-2; base length also need to be aligned 389 * blk_size must be a power-of-2; base and length also need to be
387 * to blk_size. 390 * aligned to blk_size.
388 */ 391 */
389 if (blk_size & (blk_size - 1U) || 392 if (!is_blk_size_pwr_2 || !is_base_aligned || !is_length_aligned) {
390 base & (blk_size - 1U) || length & (blk_size - 1U)) {
391 return -EINVAL; 393 return -EINVAL;
392 } 394 }
393 395
394 if (base == 0U) { 396 if (base == 0ULL) {
395 base = blk_size; 397 base = blk_size;
396 length -= blk_size; 398 length -= blk_size;
397 } 399 }
398 400
399 a = nvgpu_kzalloc(g, sizeof(struct nvgpu_bitmap_allocator)); 401 a = nvgpu_kzalloc(g, sizeof(struct nvgpu_bitmap_allocator));
400 if (!a) { 402 if (a == NULL) {
401 return -ENOMEM; 403 return -ENOMEM;
402 } 404 }
403 405
@@ -406,10 +408,10 @@ int nvgpu_bitmap_allocator_init(struct gk20a *g, struct nvgpu_allocator *na,
406 goto fail; 408 goto fail;
407 } 409 }
408 410
409 if (!(flags & GPU_ALLOC_NO_ALLOC_PAGE)) { 411 if ((flags & GPU_ALLOC_NO_ALLOC_PAGE) == 0ULL) {
410 a->meta_data_cache = nvgpu_kmem_cache_create(g, 412 a->meta_data_cache = nvgpu_kmem_cache_create(g,
411 sizeof(struct nvgpu_bitmap_alloc)); 413 sizeof(struct nvgpu_bitmap_alloc));
412 if (!a->meta_data_cache) { 414 if (a->meta_data_cache == NULL) {
413 err = -ENOMEM; 415 err = -ENOMEM;
414 goto fail; 416 goto fail;
415 } 417 }
@@ -426,7 +428,7 @@ int nvgpu_bitmap_allocator_init(struct gk20a *g, struct nvgpu_allocator *na,
426 428
427 a->bitmap = nvgpu_kcalloc(g, BITS_TO_LONGS(a->num_bits), 429 a->bitmap = nvgpu_kcalloc(g, BITS_TO_LONGS(a->num_bits),
428 sizeof(*a->bitmap)); 430 sizeof(*a->bitmap));
429 if (!a->bitmap) { 431 if (a->bitmap == NULL) {
430 err = -ENOMEM; 432 err = -ENOMEM;
431 goto fail; 433 goto fail;
432 } 434 }