From patchwork Wed Apr 20 20:48:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuah Khan X-Patchwork-Id: 8895051 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A9C30BF29F for ; Wed, 20 Apr 2016 20:48:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DA999202E5 for ; Wed, 20 Apr 2016 20:48:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0E2A7202C8 for ; Wed, 20 Apr 2016 20:48:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751096AbcDTUsO (ORCPT ); Wed, 20 Apr 2016 16:48:14 -0400 Received: from mailout.easymail.ca ([64.68.201.169]:42718 "EHLO mailout.easymail.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750998AbcDTUsO (ORCPT ); Wed, 20 Apr 2016 16:48:14 -0400 Received: from localhost (localhost [127.0.0.1]) by mailout.easymail.ca (Postfix) with ESMTP id 93BBEF5DB; Wed, 20 Apr 2016 16:48:12 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at mailout.easymail.ca X-Spam-Score: -3.695 X-Spam-Level: X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from mailout.easymail.ca ([127.0.0.1]) by localhost (easymail-mailout.easydns.vpn [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8uR+7PUlz2fl; Wed, 20 Apr 2016 16:48:12 -0400 (EDT) Received: from mail.gonehiking.org (c-73-181-52-62.hsd1.co.comcast.net [73.181.52.62]) by mailout.easymail.ca (Postfix) with ESMTPA id 1C369ED0C; Wed, 20 Apr 2016 16:48:12 -0400 (EDT) Received: from shuah-XPS-13-9350.sisa.samsung.com (shuah-xps.internal [192.168.1.87]) by mail.gonehiking.org (Postfix) with ESMTP id 6C7069F373; Wed, 20 Apr 2016 14:48:11 -0600 (MDT) From: Shuah Khan To: mchehab@osg.samsung.com, laurent.pinchart@ideasonboard.com, sakari.ailus@iki.fi Cc: Shuah Khan , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] media: fix media_open() to not release lock too soon Date: Wed, 20 Apr 2016 14:48:10 -0600 Message-Id: <1461185290-6540-1-git-send-email-shuahkh@osg.samsung.com> X-Mailer: git-send-email 2.5.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP media_open() releases media_devnode_lock before open is complete. Hold the lock to call mdev->fops->open and release at the end. Signed-off-by: Shuah Khan --- drivers/media/media-devnode.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/media/media-devnode.c b/drivers/media/media-devnode.c index 29409f4..0934789 100644 --- a/drivers/media/media-devnode.c +++ b/drivers/media/media-devnode.c @@ -155,7 +155,7 @@ static long media_compat_ioctl(struct file *filp, unsigned int cmd, static int media_open(struct inode *inode, struct file *filp) { struct media_devnode *mdev; - int ret; + int ret = 0; /* Check if the media device is available. This needs to be done with * the media_devnode_lock held to prevent an open/unregister race: @@ -173,7 +173,6 @@ static int media_open(struct inode *inode, struct file *filp) } /* and increase the device refcount */ get_device(&mdev->dev); - mutex_unlock(&media_devnode_lock); filp->private_data = mdev; @@ -182,11 +181,12 @@ static int media_open(struct inode *inode, struct file *filp) if (ret) { put_device(&mdev->dev); filp->private_data = NULL; - return ret; + goto done; } } - - return 0; +done: + mutex_unlock(&media_devnode_lock); + return ret; } /* Override for the release function */