From patchwork Fri Jan 22 00:56:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 8086191 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Original-To: patchwork-linux-renesas-soc@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 BDFBBBEEED for ; Fri, 22 Jan 2016 00:57:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 21BB62034C for ; Fri, 22 Jan 2016 00:57:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6AC4720443 for ; Fri, 22 Jan 2016 00:57:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751273AbcAVA5f (ORCPT ); Thu, 21 Jan 2016 19:57:35 -0500 Received: from galahad.ideasonboard.com ([185.26.127.97]:58715 "EHLO galahad.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751263AbcAVA5f (ORCPT ); Thu, 21 Jan 2016 19:57:35 -0500 Received: from avalon.access.network (nblzone-211-213.nblnetworks.fi [83.145.211.213]) by galahad.ideasonboard.com (Postfix) with ESMTPSA id 6C2EF2005A for ; Fri, 22 Jan 2016 01:56:30 +0100 (CET) From: Laurent Pinchart To: linux-renesas-soc@vger.kernel.org Subject: [PATCH/RFC v2 25/56] media: Move graph mutex locking into media_device_setup_link() Date: Fri, 22 Jan 2016 02:56:54 +0200 Message-Id: <1453424245-18782-26-git-send-email-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.4.10 In-Reply-To: <1453424245-18782-1-git-send-email-laurent.pinchart+renesas@ideasonboard.com> References: <1453424245-18782-1-git-send-email-laurent.pinchart+renesas@ideasonboard.com> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Sakari Ailus This helps not acquiring the mutex during copying of the IOCTL argument from or to user space. Signed-off-by: Sakari Ailus Signed-off-by: Laurent Pinchart --- drivers/media/media-device.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c index c8d104d935da..3850775cc127 100644 --- a/drivers/media/media-device.c +++ b/drivers/media/media-device.c @@ -465,33 +465,38 @@ static long media_device_setup_link(struct media_device *mdev, struct media_link_desc ulink; struct media_entity *source; struct media_entity *sink; - int ret; + int ret = -EINVAL; if (copy_from_user(&ulink, _ulink, sizeof(ulink))) return -EFAULT; + mutex_lock(&dev->graph_mutex); + /* Find the source and sink entities and link. */ source = find_entity(mdev, ulink.source.entity); sink = find_entity(mdev, ulink.sink.entity); if (source == NULL || sink == NULL) - return -EINVAL; + goto out; if (ulink.source.index >= source->num_pads || ulink.sink.index >= sink->num_pads) - return -EINVAL; + goto out; link = media_entity_find_link(&source->pads[ulink.source.index], &sink->pads[ulink.sink.index]); if (link == NULL) - return -EINVAL; + goto out; /* Setup the link on both entities. */ ret = __media_entity_setup_link(link, ulink.flags); - if (copy_to_user(_ulink, &ulink, sizeof(ulink))) - return -EFAULT; +out: + mutex_unlock(&dev->graph_mutex); + + if (!ret && copy_to_user(_ulink, &ulink, sizeof(ulink))) + ret = -EFAULT; return ret; } @@ -523,10 +528,8 @@ static long media_device_ioctl(struct file *filp, unsigned int cmd, break; case MEDIA_IOC_SETUP_LINK: - mutex_lock(&dev->graph_mutex); ret = media_device_setup_link(dev, (struct media_link_desc __user *)arg); - mutex_unlock(&dev->graph_mutex); break; case MEDIA_IOC_REQUEST_CMD: