From patchwork Wed Dec 14 13:34:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 9474169 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 119BB60823 for ; Wed, 14 Dec 2016 13:35:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 06B00286B1 for ; Wed, 14 Dec 2016 13:35:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EFA3428728; Wed, 14 Dec 2016 13:35:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A890E286B1 for ; Wed, 14 Dec 2016 13:35:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id ED96A6E80E; Wed, 14 Dec 2016 13:35:28 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qk0-x244.google.com (mail-qk0-x244.google.com [IPv6:2607:f8b0:400d:c09::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id 106216E805 for ; Wed, 14 Dec 2016 13:35:17 +0000 (UTC) Received: by mail-qk0-x244.google.com with SMTP id x190so2898406qkb.0 for ; Wed, 14 Dec 2016 05:35:17 -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=IkjfQddlhweDh3TxwXQ2en8nFuPwCzzJ+G8/NHPBoCEnIDYOaufW/Ay+9eS+gqi1BP kjyslylDGMGtzfUzSb4DghZUby1itkXYPuPatEGFEIz7wNXJv29+mbRkpnF/oPZzrZrf 3UP+ThSmFpPflrkE/HDsM/DYeB1+Z+mmM5D5QM5Q+icmRB3fYJMY8ATNdLxGvVr1eFz8 SxcXNr2q7DcnDtiknJWJqPVCzf73E6FPZ09+wo/m8xwM6KuCQ/0rmrunjW5v9hhwHSeP dI9U+Ht1tWz6F4EP5PFeGFkQD4iJMiBuFqVGni2A3G5QYrEpvglZz96EU6qJuIKC71px LBnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=K5sppHkzf0WC2zuSt6aiGbvIB6J+LlAZA4/INK2Qd2Y=; b=BOmsIgEhiKTqObtRQ4AIUMOnc8PZrHLfv0Qei+ea0WI/ryp+3gUW+7KbYkLZOkniXJ R3L4Vr7qEAFKxb3lM2vwUPA3+WqzxY0MIYgvyYhj25OZ7rafsdyM9Ys8jciFNC8GtV4b 8d+we27tvPWwJNckKAOGuaWXfP88C5u36AkI5eVtUUXrxhKq1+cAkFf/uQSLIP6tle8b UKyyYy5lespGMChLRKYdPTlVx62q+CY97mW7wg6OapcedzoW4283/T7dTBfoRZhexKvQ 2xduZpnuXSPQak64wezsvQoheBdJK1NBNderqf0BfBetO1EgrryRw98PEl2qyLCI+z37 7GCg== X-Gm-Message-State: AKaTC02dWjhIfhDfJDqSn9eHp7SHGMitLS3WBsROCajb0Uuy7eAtFewXlil0XmzzC3Gz5w== X-Received: by 10.28.63.150 with SMTP id m144mr7331407wma.96.1481722514283; Wed, 14 Dec 2016 05:35:14 -0800 (PST) Received: from cizrna.lan ([109.72.12.226]) by smtp.gmail.com with ESMTPSA id 63sm7692000wmg.2.2016.12.14.05.35.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Dec 2016 05:35:13 -0800 (PST) From: Tomeu Vizoso To: linux-kernel@vger.kernel.org Subject: [PATCH v13 1/3] drm: Move locking into drm_debugfs_crtc_crc_add Date: Wed, 14 Dec 2016 14:34:34 +0100 Message-Id: <1481722476-29964-2-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1481722476-29964-1-git-send-email-tomeu.vizoso@collabora.com> References: <1481722476-29964-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" X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Emil Velikov --- 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);