video: tegra: nvmap: Fix type casting issue

CERT-C is reporting following issue:
- Casting (size + 4095UL & 0xfffffffffffff000UL) >> 12 from unsigned
long to unsigned int without checking its value may result in lost or
misinterpreted data.
Fix this by adding overflow condition.

CID 490676
Bug 3745813

Change-Id: I39b741b6150c12dcdd3de7c70bbcf89f8e692a23
Signed-off-by: Ketan Patil <ketanp@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2778588
Reviewed-by: svcacv <svcacv@nvidia.com>
Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com>
Reviewed-by: svc-mobile-cert <svc-mobile-cert@nvidia.com>
Reviewed-by: Pritesh Raithatha <praithatha@nvidia.com>
Reviewed-by: Sachin Nikam <snikam@nvidia.com>
GVS: Gerrit_Virtual_Submit <buildbot_gerritrpt@nvidia.com>
This commit is contained in:
Ketan Patil
2022-09-20 05:14:51 +00:00
committed by Laxman Dewangan
parent 8ceb954814
commit a2338fa761

View File

@@ -359,14 +359,20 @@ static void *__nvmap_dma_alloc_from_coherent(struct device *dev,
unsigned long flags; unsigned long flags;
unsigned int count, i = 0, j = 0; unsigned int count, i = 0, j = 0;
unsigned int alloc_size; unsigned int alloc_size;
unsigned long align, pageno; unsigned long align, pageno, page_count;
void *addr = NULL; void *addr = NULL;
struct page **pages = NULL; struct page **pages = NULL;
int do_memset = 0; int do_memset = 0;
int *bitmap_nos = NULL; int *bitmap_nos = NULL;
if (dma_get_attr(DMA_ATTR_ALLOC_EXACT_SIZE, attrs)) if (dma_get_attr(DMA_ATTR_ALLOC_EXACT_SIZE, attrs)) {
count = PAGE_ALIGN(size) >> PAGE_SHIFT; page_count = PAGE_ALIGN(size) >> PAGE_SHIFT;
if (page_count > UINT_MAX) {
dev_err(dev, "Page count more than max value\n");
return NULL;
}
count = (unsigned int)page_count;
}
else else
count = 1 << order; count = 1 << order;