From patchwork Thu Nov 17 09:27:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 82687 Delivered-To: patch@linaro.org Received: by 10.182.1.168 with SMTP id 8csp767180obn; Thu, 17 Nov 2016 01:28:28 -0800 (PST) X-Received: by 10.98.7.83 with SMTP id b80mr3371422pfd.79.1479374908196; Thu, 17 Nov 2016 01:28:28 -0800 (PST) Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTPS id k71si2438996pfb.249.2016.11.17.01.28.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Nov 2016 01:28:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6C7FE6E2BC; Thu, 17 Nov 2016 09:27:47 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x241.google.com (mail-wm0-x241.google.com [IPv6:2a00:1450:400c:c09::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 94C6E6E2B4 for ; Thu, 17 Nov 2016 09:27:45 +0000 (UTC) Received: by mail-wm0-x241.google.com with SMTP id a20so19342748wme.2 for ; Thu, 17 Nov 2016 01:27:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=K5sppHkzf0WC2zuSt6aiGbvIB6J+LlAZA4/INK2Qd2Y=; b=gG+PxZPTIGAxhwrtPq4+hmnNHKEJ29CV/m/ODVTPJRsd/gnQENutcIHPqF3XXHLluu o3XcMtDR3if+fWl9VbKmsJXW6fp3oRJqctXCsaU3qoYCRUXZmS9dx3q58BgaaYvWwQLr JI+LKd56SGMuVRXOgFQ4cym+1lPjcnJLdSEeDd++5BxX+m00CYXH1kINlDTMK606xIgf JEZaKe4ORA3iBf7JErzH8Z8EnGTs2niPelewJ/saXUH/42ZqK9kjRi6GI/Eq+0Bwf31X QCmMDLZdePbsTVwloCsGWKWMWiS5jSMYs+ne9shpTWHK4rPNx/FsXcyrA+AmBp9IM1bo vpEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=K5sppHkzf0WC2zuSt6aiGbvIB6J+LlAZA4/INK2Qd2Y=; b=hCaPq3PxAU5ABXtRwUr2EXm9or9vkS2FR/gCk9XbPICvF3MStuvtZazsvotHY6w4VC QZGRrOKEyY7sM9XiTgLU5FKwYUMRKuG9kpUXaQyeoGSkDWG88kZL60+u8DgDR1JHLDUG 1y2EhWgIPHQaR7WsLBcdjscIjlZbbBOLycLrekbLgKlQxPB0OsbPNPgm/y/7VQbeJwY4 EjZ6M+zbFUP26Q/7OjNQj7ELnuXUuL2eGt+KxFFzqHpFYIvnw8u3bW6nE1PbtcQm8I06 q78oYrZt63L4i1Se+SJ3AHS3vePUmiSalKlxOMQsm85LG381BV6INjES1jayLtLby724 8qVA== X-Gm-Message-State: ABUngvfpU7j2QmOfrHXWojNuGMU1zPUyamc88Am81iuu7DIOU4J6rD9I7mDUy/W7SHYVDQ== X-Received: by 10.28.92.21 with SMTP id q21mr3122747wmb.71.1479374864129; Thu, 17 Nov 2016 01:27:44 -0800 (PST) Received: from cizrna.lan ([109.72.12.131]) by smtp.gmail.com with ESMTPSA id t84sm14534370wmt.7.2016.11.17.01.27.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Nov 2016 01:27:43 -0800 (PST) From: Tomeu Vizoso To: linux-kernel@vger.kernel.org Subject: [PATCH v12 2/4] drm: Move locking into drm_debugfs_crtc_crc_add Date: Thu, 17 Nov 2016 10:27:05 +0100 Message-Id: <1479374827-10642-3-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1479374827-10642-1-git-send-email-tomeu.vizoso@collabora.com> References: <1479374827-10642-1-git-send-email-tomeu.vizoso@collabora.com> Cc: Tomeu Vizoso , Emil Velikov , dri-devel@lists.freedesktop.org, Daniel Vetter 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" There's no reason any more for callers of this function to take the lock themselves, so just move the lock to the function to avoid confusion and bugs when more callers are contributed. Signed-off-by: Tomeu Vizoso --- drivers/gpu/drm/drm_debugfs_crc.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/drm_debugfs_crc.c b/drivers/gpu/drm/drm_debugfs_crc.c index 00e771fb7df2..68b171af237b 100644 --- a/drivers/gpu/drm/drm_debugfs_crc.c +++ b/drivers/gpu/drm/drm_debugfs_crc.c @@ -325,16 +325,19 @@ int drm_crtc_add_crc_entry(struct drm_crtc *crtc, bool has_frame, struct drm_crtc_crc_entry *entry; int head, tail; - assert_spin_locked(&crc->lock); + spin_lock(&crc->lock); /* Caller may not have noticed yet that userspace has stopped reading */ - if (!crc->opened) + if (!crc->opened) { + spin_unlock(&crc->lock); return -EINVAL; + } head = crc->head; tail = crc->tail; if (CIRC_SPACE(head, tail, DRM_CRC_ENTRIES_NR) < 1) { + spin_unlock(&crc->lock); DRM_ERROR("Overflow of CRC buffer, userspace reads too slow.\n"); return -ENOBUFS; } @@ -347,6 +350,8 @@ int drm_crtc_add_crc_entry(struct drm_crtc *crtc, bool has_frame, head = (head + 1) & (DRM_CRC_ENTRIES_NR - 1); crc->head = head; + spin_unlock(&crc->lock); + return 0; } EXPORT_SYMBOL_GPL(drm_crtc_add_crc_entry);