From 9d96826773e58f5955170ffbfad15276df384f0e Mon Sep 17 00:00:00 2001 From: Surbhi Singh Date: Wed, 21 Aug 2024 13:33:07 +0000 Subject: [PATCH] video: tegra: nvmap: Add Check for NULL & 0 Value Fix for Rule: Misra-C 2012 Rule 10.1 -In nvmap_pp.c return type of non_zero_cnt is integer not boolean, hence compare it with 0. -In nvmap_dmabuf.c the result for & operation would be 0 or 1, hence compare it with 0. -In nvmap_core.c the return type of kzalloc is pointer, hence compare it with NULL. -In nvmap_dev.c priv is a pointer, hence compare it with NULL. CID 1608945 CID 1617267 CID 1622229 CID 1625991 CID 1630899 JIRA TMM-5627 Change-Id: Ib40286f852cdade2e115384d18f615ae52134bdd Signed-off-by: Surbhi Singh Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/3197795 Reviewed-by: Ketan Patil Reviewed-by: Sachin Nikam Reviewed-by: Ashish Mhetre Reviewed-by: Pritesh Raithatha GVS: buildbot_gerritrpt Tested-by: Sachin Nikam --- drivers/video/tegra/nvmap/nvmap_core.c | 2 +- drivers/video/tegra/nvmap/nvmap_dev.c | 2 +- drivers/video/tegra/nvmap/nvmap_dmabuf.c | 2 +- drivers/video/tegra/nvmap/nvmap_init.c | 2 +- drivers/video/tegra/nvmap/nvmap_pp.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/video/tegra/nvmap/nvmap_core.c b/drivers/video/tegra/nvmap/nvmap_core.c index e9decf1f..d723c6eb 100644 --- a/drivers/video/tegra/nvmap/nvmap_core.c +++ b/drivers/video/tegra/nvmap/nvmap_core.c @@ -217,7 +217,7 @@ struct sg_table *__nvmap_sg_table(struct nvmap_client *client, npages = PAGE_ALIGN(h->size) >> PAGE_SHIFT; sgt = kzalloc(sizeof(*sgt), GFP_KERNEL); - if (!sgt) { + if (sgt == NULL) { err = -ENOMEM; goto err; } diff --git a/drivers/video/tegra/nvmap/nvmap_dev.c b/drivers/video/tegra/nvmap/nvmap_dev.c index f7aec89c..e6e85ffb 100644 --- a/drivers/video/tegra/nvmap/nvmap_dev.c +++ b/drivers/video/tegra/nvmap/nvmap_dev.c @@ -298,7 +298,7 @@ static int nvmap_open(struct inode *inode, struct file *filp) BUG_ON(dev != nvmap_dev); priv = __nvmap_create_client(dev, "user"); - if (!priv) + if (priv == NULL) return -ENOMEM; trace_nvmap_open(priv, priv->name); diff --git a/drivers/video/tegra/nvmap/nvmap_dmabuf.c b/drivers/video/tegra/nvmap/nvmap_dmabuf.c index d46ea5b7..2d75353e 100644 --- a/drivers/video/tegra/nvmap/nvmap_dmabuf.c +++ b/drivers/video/tegra/nvmap/nvmap_dmabuf.c @@ -369,7 +369,7 @@ int __nvmap_map(struct nvmap_handle *h, struct vm_area_struct *vma) if (!h) return -EINVAL; - if (!(h->heap_type & nvmap_dev->cpu_access_mask)) { + if ((h->heap_type & nvmap_dev->cpu_access_mask) == 0U) { nvmap_handle_put(h); return -EPERM; } diff --git a/drivers/video/tegra/nvmap/nvmap_init.c b/drivers/video/tegra/nvmap/nvmap_init.c index d98fd530..ec35def2 100644 --- a/drivers/video/tegra/nvmap/nvmap_init.c +++ b/drivers/video/tegra/nvmap/nvmap_init.c @@ -698,7 +698,7 @@ int __init nvmap_co_setup(struct reserved_mem *rmem) int ret = 0; co = nvmap_get_carveout_pdata(rmem->name); - if (!co) + if (co == NULL) return ret; rmem->ops = &nvmap_co_ops; diff --git a/drivers/video/tegra/nvmap/nvmap_pp.c b/drivers/video/tegra/nvmap/nvmap_pp.c index 7697419e..05798b48 100644 --- a/drivers/video/tegra/nvmap/nvmap_pp.c +++ b/drivers/video/tegra/nvmap/nvmap_pp.c @@ -312,7 +312,7 @@ int nvmap_page_pool_alloc_lots(struct nvmap_page_pool *pool, while (ind < nr) { struct page *page = NULL; - if (!non_zero_cnt) + if (non_zero_cnt == 0U) page = get_page_list_page(pool, use_numa, numa_id); if (!page) {