rk29: vpu_mem: fix bug on invalid cache operation
author陈恒明 <chm@rockchip.com>
Tue, 24 May 2011 02:16:23 +0000 (10:16 +0800)
committer陈恒明 <chm@rockchip.com>
Tue, 24 May 2011 02:16:23 +0000 (10:16 +0800)
arch/arm/mach-rk29/vpu_mem.c

index 187c2a5248a99addb032aeae5bf03a0e648beff3..89e8e968d64c3f10a145e9c60ecc4e6d845de44e 100644 (file)
@@ -813,8 +813,12 @@ void vpu_mem_cache_opt(struct file *file, long index, unsigned int cmd)
                return;\r
 \r
        down_read(&vdm_rwsem);\r
-    {\r
+    do {\r
         vdm_link *link = find_used_link(session, index);\r
+        if (NULL == link) {\r
+            pr_err("vpu_mem_cache_opt on non-exsist index %ld\n", index);\r
+            break;\r
+        }\r
         start = vpu_mem.vbase + index * VPU_MEM_MIN_ALLOC;\r
         end   = start + link->pfn * VPU_MEM_MIN_ALLOC;;\r
         switch (cmd) {\r
@@ -833,7 +837,7 @@ void vpu_mem_cache_opt(struct file *file, long index, unsigned int cmd)
         default :\r
             break;\r
         }\r
-    }\r
+    } while (0);\r
     up_read(&vdm_rwsem);\r
 }\r
 \r
@@ -1023,6 +1027,8 @@ static long vpu_mem_ioctl(struct file *file, unsigned int cmd, unsigned long arg
                {\r
                        if (copy_from_user(&index, (void __user *)arg, sizeof(index)))\r
                                return -EFAULT;\r
+            if (index < 0)\r
+                return -EINVAL;\r
                        vpu_mem_cache_opt(file, index, cmd);\r
                        break;\r
                }\r