From patchwork Wed Sep 10 15:54:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 4879011 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 7F7B09F3AE for ; Wed, 10 Sep 2014 15:55:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DEA002018E for ; Wed, 10 Sep 2014 15:54:58 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 9EE29201CD for ; Wed, 10 Sep 2014 15:54:57 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EB7CE89FD4; Wed, 10 Sep 2014 08:54:56 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wi0-f179.google.com (mail-wi0-f179.google.com [209.85.212.179]) by gabe.freedesktop.org (Postfix) with ESMTP id C539F89FDE for ; Wed, 10 Sep 2014 08:54:55 -0700 (PDT) Received: by mail-wi0-f179.google.com with SMTP id q5so6559211wiv.0 for ; Wed, 10 Sep 2014 08:54:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bZ3M8xhqYGtA3wjOLHs0U5N0Ayt7NHDYXMdJNME0bII=; b=fWmSQJEPCwe/LIVVKj2ham0SNzxF1O6FwRXyLcyGzYjYgKZO61mVcgWlRQQkce492K zwfm+jN0gt2rLHG0WZV9Sy/iwMtTDL+2uixBgHYgb9/dS25qUdXhicAZetW1LRdypuhO sBulkRWuSK2gKCxx9OCRPgaK4pyqyBctvKEyh32OsSrkamgDFMY4pXciJfTsEzyned36 LWMfJEhTWHZXKSvpYw3yAs0J71zxwJ9EODuF56Mqc/oC9dhjL13AA3St2G2hDA8W1i+x vCsqQ6VR0ITjnrh7cJWTit0QHsIizUtCkZ/RcHcIJqWJoQXMJOwXCOlKHMjvZc2dYu/Z sbLA== X-Received: by 10.180.78.234 with SMTP id e10mr734245wix.7.1410364495101; Wed, 10 Sep 2014 08:54:55 -0700 (PDT) Received: from david-tp.localdomain (stgt-5f7015fa.pool.mediaWays.net. [95.112.21.250]) by mx.google.com with ESMTPSA id js2sm19046250wjc.9.2014.09.10.08.54.52 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 10 Sep 2014 08:54:54 -0700 (PDT) From: David Herrmann To: dri-devel@lists.freedesktop.org Subject: [PATCH RFC 2/4] backlight: use spin-lock to protect device list Date: Wed, 10 Sep 2014 17:54:21 +0200 Message-Id: <1410364463-12692-3-git-send-email-dh.herrmann@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1410364463-12692-1-git-send-email-dh.herrmann@gmail.com> References: <1410364463-12692-1-git-send-email-dh.herrmann@gmail.com> Cc: Matthew Garrett , Daniel Vetter , Bryan Wu , linux-kernel@vger.kernel.org, Lee Jones X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.15 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=-6.6 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 There is really no reason to use a mutex to protect a simple list. Convert the list-lock to a simple spinlock instead. The spin-locks prepare for a backlight_find() helper, which should preferably be usable from atomic context. A mutex would prevent that, so use an irq-save spinlock instead. Signed-off-by: David Herrmann Reviewed-by: Jani Nikula --- drivers/video/backlight/backlight.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c index 726c6c6..33b64be 100644 --- a/drivers/video/backlight/backlight.c +++ b/drivers/video/backlight/backlight.c @@ -16,13 +16,14 @@ #include #include #include +#include #ifdef CONFIG_PMAC_BACKLIGHT #include #endif static LIST_HEAD(backlight_dev_list); -static DEFINE_MUTEX(backlight_dev_list_mutex); +static DEFINE_SPINLOCK(backlight_dev_list_lock); static BLOCKING_NOTIFIER_HEAD(backlight_notifier); static const char *const backlight_types[] = { @@ -369,9 +370,9 @@ struct backlight_device *backlight_device_register(const char *name, mutex_unlock(&pmac_backlight_mutex); #endif - mutex_lock(&backlight_dev_list_mutex); + spin_lock_irq(&backlight_dev_list_lock); list_add(&new_bd->entry, &backlight_dev_list); - mutex_unlock(&backlight_dev_list_mutex); + spin_unlock_irq(&backlight_dev_list_lock); blocking_notifier_call_chain(&backlight_notifier, BACKLIGHT_REGISTERED, new_bd); @@ -384,15 +385,16 @@ bool backlight_device_registered(enum backlight_type type) { bool found = false; struct backlight_device *bd; + unsigned long flags; - mutex_lock(&backlight_dev_list_mutex); + spin_lock_irqsave(&backlight_dev_list_lock, flags); list_for_each_entry(bd, &backlight_dev_list, entry) { if (bd->props.type == type) { found = true; break; } } - mutex_unlock(&backlight_dev_list_mutex); + spin_unlock_irqrestore(&backlight_dev_list_lock, flags); return found; } @@ -409,9 +411,9 @@ void backlight_device_unregister(struct backlight_device *bd) if (!bd) return; - mutex_lock(&backlight_dev_list_mutex); + spin_lock_irq(&backlight_dev_list_lock); list_del(&bd->entry); - mutex_unlock(&backlight_dev_list_mutex); + spin_unlock_irq(&backlight_dev_list_lock); #ifdef CONFIG_PMAC_BACKLIGHT mutex_lock(&pmac_backlight_mutex);