From 9afe207ea4c386ea9ad85ca91957aa5da5e31cfb Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E9=99=88=E6=81=92=E6=98=8E?= Date: Tue, 24 May 2011 10:16:23 +0800 Subject: [PATCH] rk29: vpu_mem: fix bug on invalid cache operation --- arch/arm/mach-rk29/vpu_mem.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/arch/arm/mach-rk29/vpu_mem.c b/arch/arm/mach-rk29/vpu_mem.c index 187c2a5248a9..89e8e968d64c 100644 --- a/arch/arm/mach-rk29/vpu_mem.c +++ b/arch/arm/mach-rk29/vpu_mem.c @@ -813,8 +813,12 @@ void vpu_mem_cache_opt(struct file *file, long index, unsigned int cmd) return; down_read(&vdm_rwsem); - { + do { vdm_link *link = find_used_link(session, index); + if (NULL == link) { + pr_err("vpu_mem_cache_opt on non-exsist index %ld\n", index); + break; + } start = vpu_mem.vbase + index * VPU_MEM_MIN_ALLOC; end = start + link->pfn * VPU_MEM_MIN_ALLOC;; switch (cmd) { @@ -833,7 +837,7 @@ void vpu_mem_cache_opt(struct file *file, long index, unsigned int cmd) default : break; } - } + } while (0); up_read(&vdm_rwsem); } @@ -1023,6 +1027,8 @@ static long vpu_mem_ioctl(struct file *file, unsigned int cmd, unsigned long arg { if (copy_from_user(&index, (void __user *)arg, sizeof(index))) return -EFAULT; + if (index < 0) + return -EINVAL; vpu_mem_cache_opt(file, index, cmd); break; } -- 2.34.1