public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Herrmann <dh.herrmann@gmail.com>
To: dri-devel@lists.freedesktop.org
Cc: Dave Airlie <airlied@gmail.com>,
	Daniel Vetter <daniel.vetter@ffwll.ch>,
	Jingoo Han <jg1.han@samsung.com>, Bryan Wu <cooloney@gmail.com>,
	Lee Jones <lee.jones@linaro.org>,
	Matthew Garrett <matthew.garrett@nebula.com>,
	Adam Jackson <ajax@redhat.com>,
	linux-kernel@vger.kernel.org,
	David Herrmann <dh.herrmann@gmail.com>
Subject: [PATCH RFC 2/4] backlight: use spin-lock to protect device list
Date: Wed, 10 Sep 2014 17:54:21 +0200	[thread overview]
Message-ID: <1410364463-12692-3-git-send-email-dh.herrmann@gmail.com> (raw)
In-Reply-To: <1410364463-12692-1-git-send-email-dh.herrmann@gmail.com>

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 <dh.herrmann@gmail.com>
---
 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 <linux/err.h>
 #include <linux/fb.h>
 #include <linux/slab.h>
+#include <linux/spinlock.h>
 
 #ifdef CONFIG_PMAC_BACKLIGHT
 #include <asm/backlight.h>
 #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);
-- 
2.1.0


  parent reply	other threads:[~2014-09-10 15:56 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-10 15:54 [PATCH RFC 0/4] Linking DRM Connectors to Backlight Devices David Herrmann
2014-09-10 15:54 ` [PATCH RFC 1/4] backlight: use static initializers David Herrmann
2014-09-11  8:59   ` Jani Nikula
2014-09-10 15:54 ` David Herrmann [this message]
2014-09-11  9:00   ` [PATCH RFC 2/4] backlight: use spin-lock to protect device list Jani Nikula
2014-09-10 15:54 ` [PATCH RFC 3/4] backlight: add kernel-internal backlight API David Herrmann
2014-09-11 11:10   ` Thierry Reding
2014-09-11 11:14     ` David Herrmann
2014-09-11 11:21       ` Thierry Reding
2014-09-10 15:54 ` [PATCH RFC 4/4] drm: link connectors to backlight devices David Herrmann
2014-09-11  6:48   ` Daniel Vetter
2014-09-11 12:22     ` David Herrmann
2014-09-11 13:06       ` Daniel Vetter
2014-09-11 16:07         ` David Herrmann
2014-09-11 12:46     ` Jani Nikula
2014-09-10 20:40 ` [PATCH RFC 0/4] Linking DRM Connectors to Backlight Devices Matthew Garrett
2014-09-11 12:48   ` David Herrmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1410364463-12692-3-git-send-email-dh.herrmann@gmail.com \
    --to=dh.herrmann@gmail.com \
    --cc=airlied@gmail.com \
    --cc=ajax@redhat.com \
    --cc=cooloney@gmail.com \
    --cc=daniel.vetter@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jg1.han@samsung.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthew.garrett@nebula.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox