From patchwork Sun Sep 19 10:29:35 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 193482 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 o8JATfBF002537 for ; Sun, 19 Sep 2010 10:29:41 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752706Ab0ISK3j (ORCPT ); Sun, 19 Sep 2010 06:29:39 -0400 Received: from smtp-vbr13.xs4all.nl ([194.109.24.33]:2938 "EHLO smtp-vbr13.xs4all.nl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752132Ab0ISK3i (ORCPT ); Sun, 19 Sep 2010 06:29:38 -0400 Received: from tschai.localnet (186.84-48-119.nextgentel.com [84.48.119.186]) (authenticated bits=0) by smtp-vbr13.xs4all.nl (8.13.8/8.13.8) with ESMTP id o8JATaJs029630 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sun, 19 Sep 2010 12:29:37 +0200 (CEST) (envelope-from hverkuil@xs4all.nl) From: Hans Verkuil To: linux-media@vger.kernel.org Subject: RFC: BKL, locking and ioctls Date: Sun, 19 Sep 2010 12:29:35 +0200 User-Agent: KMail/1.13.5 (Linux/2.6.35-tschai; KDE/4.4.5; x86_64; ; ) MIME-Version: 1.0 Message-Id: <201009191229.35800.hverkuil@xs4all.nl> 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]); Sun, 19 Sep 2010 10:29:41 +0000 (UTC) diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c index 30461cf..44c37e5 100644 --- a/drivers/media/video/v4l2-dev.c +++ b/drivers/media/video/v4l2-dev.c @@ -236,12 +236,18 @@ static long v4l2_unlocked_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { struct video_device *vdev = video_devdata(filp); + int ret; if (!vdev->fops->unlocked_ioctl) return -ENOTTY; + if (vdev->ioctl_lock) + mutex_lock(vdev->ioctl_lock); /* Allow ioctl to continue even if the device was unregistered. Things like dequeueing buffers might still be useful. */ - return vdev->fops->unlocked_ioctl(filp, cmd, arg); + ret = vdev->fops->unlocked_ioctl(filp, cmd, arg); + if (vdev->ioctl_lock) + mutex_unlock(vdev->ioctl_lock); + return ret; } #ifdef CONFIG_MMU diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h index 1efcacb..e1ad38a 100644 --- a/include/media/v4l2-dev.h +++ b/include/media/v4l2-dev.h @@ -97,6 +97,8 @@ struct video_device /* ioctl callbacks */ const struct v4l2_ioctl_ops *ioctl_ops; + + struct mutex *ioctl_lock; }; /* dev to video-device */