From patchwork Tue Nov 16 21:55:32 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 329711 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oAGLuOpl005442 for ; Tue, 16 Nov 2010 21:56:25 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932736Ab0KPVzs (ORCPT ); Tue, 16 Nov 2010 16:55:48 -0500 Received: from smtp-vbr12.xs4all.nl ([194.109.24.32]:3941 "EHLO smtp-vbr12.xs4all.nl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932708Ab0KPVzq (ORCPT ); Tue, 16 Nov 2010 16:55:46 -0500 Received: from localhost (209.80-203-30.nextgentel.com [80.203.30.209]) by smtp-vbr12.xs4all.nl (8.13.8/8.13.8) with ESMTP id oAGLtdNa020722 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Tue, 16 Nov 2010 22:55:44 +0100 (CET) (envelope-from hverkuil@xs4all.nl) Message-Id: In-Reply-To: References: From: Hans Verkuil Date: Tue, 16 Nov 2010 22:55:32 +0100 Subject: [RFCv2 PATCH 01/15] v4l2-dev: use mutex_lock_interruptible instead of plain mutex_lock To: linux-media@vger.kernel.org Cc: Arnd Bergmann X-Virus-Scanned: by XS4ALL Virus Scanner Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Tue, 16 Nov 2010 21:56:25 +0000 (UTC) diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c index 0ca7978..8eb0756 100644 --- a/drivers/media/video/v4l2-dev.c +++ b/drivers/media/video/v4l2-dev.c @@ -191,8 +191,12 @@ static ssize_t v4l2_read(struct file *filp, char __user *buf, if (!vdev->fops->read) return -EINVAL; - if (vdev->lock) - mutex_lock(vdev->lock); + if (vdev->lock) { + int res = mutex_lock_interruptible(vdev->lock); + + if (res) + return res; + } if (video_is_registered(vdev)) ret = vdev->fops->read(filp, buf, sz, off); if (vdev->lock) @@ -208,8 +212,12 @@ static ssize_t v4l2_write(struct file *filp, const char __user *buf, if (!vdev->fops->write) return -EINVAL; - if (vdev->lock) - mutex_lock(vdev->lock); + if (vdev->lock) { + int res = mutex_lock_interruptible(vdev->lock); + + if (res) + return res; + } if (video_is_registered(vdev)) ret = vdev->fops->write(filp, buf, sz, off); if (vdev->lock) @@ -224,8 +232,8 @@ static unsigned int v4l2_poll(struct file *filp, struct poll_table_struct *poll) if (!vdev->fops->poll) return ret; - if (vdev->lock) - mutex_lock(vdev->lock); + if (vdev->lock && mutex_lock_interruptible(vdev->lock)) + return ret; if (video_is_registered(vdev)) ret = vdev->fops->poll(filp, poll); if (vdev->lock) @@ -239,8 +247,12 @@ static long v4l2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) int ret = -ENODEV; if (vdev->fops->unlocked_ioctl) { - if (vdev->lock) - mutex_lock(vdev->lock); + if (vdev->lock) { + int res = mutex_lock_interruptible(vdev->lock); + + if (res) + return res; + } if (video_is_registered(vdev)) ret = vdev->fops->unlocked_ioctl(filp, cmd, arg); if (vdev->lock) @@ -264,8 +276,12 @@ static int v4l2_mmap(struct file *filp, struct vm_area_struct *vm) if (!vdev->fops->mmap) return ret; - if (vdev->lock) - mutex_lock(vdev->lock); + if (vdev->lock) { + int res = mutex_lock_interruptible(vdev->lock); + + if (res) + return res; + } if (video_is_registered(vdev)) ret = vdev->fops->mmap(filp, vm); if (vdev->lock) @@ -291,8 +307,11 @@ static int v4l2_open(struct inode *inode, struct file *filp) video_get(vdev); mutex_unlock(&videodev_lock); if (vdev->fops->open) { - if (vdev->lock) - mutex_lock(vdev->lock); + if (vdev->lock) { + ret = mutex_lock_interruptible(vdev->lock); + if (ret) + goto err; + } if (video_is_registered(vdev)) ret = vdev->fops->open(filp); else @@ -301,6 +320,7 @@ static int v4l2_open(struct inode *inode, struct file *filp) mutex_unlock(vdev->lock); } +err: /* decrease the refcount in case of an error */ if (ret) video_put(vdev);