From patchwork Thu Nov 20 23:54:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Padovan X-Patchwork-Id: 5351421 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B3B6F9F2F1 for ; Thu, 20 Nov 2014 23:54:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EF1F720225 for ; Thu, 20 Nov 2014 23:54:34 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 2DA012021F for ; Thu, 20 Nov 2014 23:54:34 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2EF636E9F1; Thu, 20 Nov 2014 15:54:33 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qg0-f50.google.com (mail-qg0-f50.google.com [209.85.192.50]) by gabe.freedesktop.org (Postfix) with ESMTP id 9F2A26E9F1 for ; Thu, 20 Nov 2014 15:54:32 -0800 (PST) Received: by mail-qg0-f50.google.com with SMTP id e89so2898871qgf.37 for ; Thu, 20 Nov 2014 15:54:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ae6N2XDhssop8sWeq0Y5lOHAXg012/OFd/7/FuCmeRY=; b=W2fJy4RmUOsa56qZJfsBKjgAB40NLj8zYc6bk5Z84BCgXmmPAt4DhARpWEpvn/fH8K 8a8l5vnJODXOfIzNTIoOsXI/7FwF6YpXlXZpK+vkUc/XtJ5sjyDvXkrel1SM9NvuSsTP 2dWBt7H5pYoUaZJSLoJQNKm5QE38mWLGW/eH4ke0v1TIpi4PBDtDp1Fek58WC1bOkfB3 lvW9hsWKUrP+arATzXCozuJEzHjxkQ+b4gSYdd8QJCD0gLazL8hIp1YqZWEYyl6mBSNp ff82+SY8Du0ineDP+nmZR4MEUhJXfCFvZzjxiHTWjBgUYlcMQNierbsXgLvz6g1aKrBF iuGQ== X-Received: by 10.140.39.10 with SMTP id u10mr1794269qgu.28.1416527672227; Thu, 20 Nov 2014 15:54:32 -0800 (PST) Received: from localhost.localdomain ([187.34.44.229]) by mx.google.com with ESMTPSA id d2sm3294075qab.24.2014.11.20.15.54.29 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Nov 2014 15:54:31 -0800 (PST) From: Gustavo Padovan To: linux-samsung-soc@vger.kernel.org Subject: [PATCH 2/3] drm/exynos: avoid race condition when adding a drm component Date: Thu, 20 Nov 2014 21:54:23 -0200 Message-Id: <1416527664-10553-2-git-send-email-gustavo@padovan.org> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1416527664-10553-1-git-send-email-gustavo@padovan.org> References: <1416527664-10553-1-git-send-email-gustavo@padovan.org> Cc: Gustavo Padovan , dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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: Gustavo Padovan exynos_drm_component_add() correctly checks if a component is present on drm_component_list however it release the lock right after the check and before we add the new component to the list. That just creates room to add the same component more than once to the list. The lock should be held for the whole journey while adding a new component. Signed-off-by: Gustavo Padovan --- drivers/gpu/drm/exynos/exynos_drm_drv.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.c b/drivers/gpu/drm/exynos/exynos_drm_drv.c index cb3ed9b..230573d 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_drv.c +++ b/drivers/gpu/drm/exynos/exynos_drm_drv.c @@ -402,10 +402,8 @@ int exynos_drm_component_add(struct device *dev, * added already just return. */ if (cdev->dev_type_flag == (EXYNOS_DEVICE_TYPE_CRTC | - EXYNOS_DEVICE_TYPE_CONNECTOR)) { - mutex_unlock(&drm_component_lock); - return 0; - } + EXYNOS_DEVICE_TYPE_CONNECTOR)) + goto unlock; if (dev_type == EXYNOS_DEVICE_TYPE_CRTC) { cdev->crtc_dev = dev; @@ -417,14 +415,11 @@ int exynos_drm_component_add(struct device *dev, cdev->dev_type_flag |= dev_type; } - mutex_unlock(&drm_component_lock); - return 0; + goto unlock; } } - mutex_unlock(&drm_component_lock); - - cdev = kzalloc(sizeof(*cdev), GFP_KERNEL); + cdev = kzalloc(sizeof(*cdev), GFP_ATOMIC); if (!cdev) return -ENOMEM; @@ -436,10 +431,9 @@ int exynos_drm_component_add(struct device *dev, cdev->out_type = out_type; cdev->dev_type_flag = dev_type; - mutex_lock(&drm_component_lock); list_add_tail(&cdev->list, &drm_component_list); +unlock: mutex_unlock(&drm_component_lock); - return 0; }