From: "Marek Behún" <kabel@kernel.org>
To: linux-leds@vger.kernel.org
Cc: netdev@vger.kernel.org, "Pavel Machek" <pavel@ucw.cz>,
"Dan Murphy" <dmurphy@ti.com>,
"Russell King" <linux@armlinux.org.uk>,
"Andrew Lunn" <andrew@lunn.ch>,
"Matthias Schiffer" <matthias.schiffer@ew.tq-group.com>,
"Jacek Anaszewski" <jacek.anaszewski@gmail.com>,
"Mauro Carvalho Chehab" <mchehab+huawei@kernel.org>,
"Marek Behún" <kabel@kernel.org>
Subject: [PATCH leds v1 5/5] leds: trigger: netdev: change spinlock to mutex
Date: Wed, 26 May 2021 20:00:20 +0200 [thread overview]
Message-ID: <20210526180020.13557-6-kabel@kernel.org> (raw)
In-Reply-To: <20210526180020.13557-1-kabel@kernel.org>
Using spinlocks requires that the trigger_offload() method cannot sleep.
This can be problematic for some hardware, since access to registers may
sleep.
We can change the spinlock to mutex because, according to Jacek:
register_netdevice_notifier() registers raw notifier chain,
whose callbacks are not called from atomic context and there are
no restrictions on callbacks. See include/linux/notifier.h.
Signed-off-by: Marek Behún <kabel@kernel.org>
---
drivers/leds/trigger/ledtrig-netdev.c | 14 +++++++-------
include/linux/ledtrig.h | 4 ++--
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c
index b6d51b24c213..7073cc6b8ca2 100644
--- a/drivers/leds/trigger/ledtrig-netdev.c
+++ b/drivers/leds/trigger/ledtrig-netdev.c
@@ -79,9 +79,9 @@ static ssize_t device_name_show(struct device *dev,
struct led_netdev_data *trigger_data = led_trigger_get_drvdata(dev);
ssize_t len;
- spin_lock_bh(&trigger_data->lock);
+ mutex_lock(&trigger_data->lock);
len = sprintf(buf, "%s\n", trigger_data->device_name);
- spin_unlock_bh(&trigger_data->lock);
+ mutex_unlock(&trigger_data->lock);
return len;
}
@@ -97,7 +97,7 @@ static ssize_t device_name_store(struct device *dev,
cancel_delayed_work_sync(&trigger_data->work);
- spin_lock_bh(&trigger_data->lock);
+ mutex_lock(&trigger_data->lock);
if (trigger_data->net_dev) {
dev_put(trigger_data->net_dev);
@@ -121,7 +121,7 @@ static ssize_t device_name_store(struct device *dev,
trigger_data->last_activity = 0;
set_baseline_state(trigger_data);
- spin_unlock_bh(&trigger_data->lock);
+ mutex_unlock(&trigger_data->lock);
return size;
}
@@ -295,7 +295,7 @@ static int netdev_trig_notify(struct notifier_block *nb,
cancel_delayed_work_sync(&trigger_data->work);
- spin_lock_bh(&trigger_data->lock);
+ mutex_lock(&trigger_data->lock);
clear_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode);
switch (evt) {
@@ -319,7 +319,7 @@ static int netdev_trig_notify(struct notifier_block *nb,
set_baseline_state(trigger_data);
- spin_unlock_bh(&trigger_data->lock);
+ mutex_unlock(&trigger_data->lock);
return NOTIFY_DONE;
}
@@ -380,7 +380,7 @@ static int netdev_trig_activate(struct led_classdev *led_cdev)
if (!trigger_data)
return -ENOMEM;
- spin_lock_init(&trigger_data->lock);
+ mutex_init(&trigger_data->lock);
trigger_data->notifier.notifier_call = netdev_trig_notify;
trigger_data->notifier.priority = 10;
diff --git a/include/linux/ledtrig.h b/include/linux/ledtrig.h
index a6a813bb154a..bd8cdcfaf232 100644
--- a/include/linux/ledtrig.h
+++ b/include/linux/ledtrig.h
@@ -8,13 +8,13 @@
#include <linux/atomic.h>
#include <linux/leds.h>
+#include <linux/mutex.h>
#include <linux/netdevice.h>
-#include <linux/spinlock.h>
#if IS_ENABLED(CONFIG_LEDS_TRIGGER_NETDEV)
struct led_netdev_data {
- spinlock_t lock;
+ struct mutex lock;
struct delayed_work work;
struct notifier_block notifier;
--
2.26.3
prev parent reply other threads:[~2021-05-26 18:01 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-26 18:00 [PATCH leds v1 0/5] Add support for offloading netdev trigger to HW Marek Behún
2021-05-26 18:00 ` [PATCH leds v1 1/5] leds: trigger: netdev: don't explicitly zero kzalloced data Marek Behún
2021-05-27 16:38 ` Andrew Lunn
2021-05-26 18:00 ` [PATCH leds v1 2/5] leds: trigger: add API for HW offloading of triggers Marek Behún
2021-05-26 18:00 ` [PATCH leds v1 3/5] leds: trigger: netdev: move trigger data structure to global include dir Marek Behún
2021-05-27 16:48 ` Andrew Lunn
2021-05-28 6:28 ` Marek Behún
2021-05-26 18:00 ` [PATCH leds v1 4/5] leds: trigger: netdev: support HW offloading Marek Behún
2021-05-27 16:57 ` Andrew Lunn
2021-05-28 6:45 ` Marek Behún
2021-05-28 13:50 ` Andrew Lunn
2021-05-28 13:57 ` Marek Behún
2021-05-26 18:00 ` Marek Behún [this message]
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=20210526180020.13557-6-kabel@kernel.org \
--to=kabel@kernel.org \
--cc=andrew@lunn.ch \
--cc=dmurphy@ti.com \
--cc=jacek.anaszewski@gmail.com \
--cc=linux-leds@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=matthias.schiffer@ew.tq-group.com \
--cc=mchehab+huawei@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pavel@ucw.cz \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.