misc: tegra-profiler: fix coverity defect
Igor Nabirushkin [Sat, 4 Jun 2016 10:38:58 +0000 (14:38 +0400)]
Fix coverity defect "Use of untrusted scalar value".

Coverity ID 24041

Bug 200192567

Change-Id: I92b4464525f45481e23a4fcfe2aea51de8cb8e07
Signed-off-by: Igor Nabirushkin <inabirushkin@nvidia.com>
Reviewed-on: http://git-master/r/1171552
(cherry picked from commit a3f967b70c47aa583ef2e1f4164c688ed641f388)
Reviewed-on: http://git-master/r/1249584
(cherry picked from commit 17f5d17ac835466558832cf6ed67eb72d2fc28c1)

drivers/misc/tegra-profiler/comm.c

index 781e010..e90982d 100644 (file)
@@ -311,7 +311,7 @@ static int
 init_mmap_hdr(struct quadd_mmap_rb_info *mmap_rb,
              struct quadd_mmap_area *mmap)
 {
-       int cpu_id;
+       unsigned int cpu_id;
        size_t size;
        unsigned long flags;
        struct vm_area_struct *vma;
@@ -324,6 +324,10 @@ init_mmap_hdr(struct quadd_mmap_rb_info *mmap_rb,
                return -EIO;
 
        cpu_id = mmap_rb->cpu_id;
+
+       if (cpu_id >= nr_cpu_ids)
+               return -EIO;
+
        cc = &per_cpu(cpu_ctx, cpu_id);
 
        rb = &cc->rb;