180bee96128a5deca26ec0c5a277cbe6e4b682c8
[openwrt/staging/neocturne.git] /
1 From d1b9e1391ab2dc80e9db87fe8b2de015c651e4c9 Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Wed, 19 Apr 2023 23:07:43 +0200
4 Subject: [PATCH 5/5] leds: trigger: netdev: Use mutex instead of spinlocks
5
6 Some LEDs may require to sleep while doing some operation like setting
7 brightness and other cleanup.
8
9 For this reason, using a spinlock will cause a sleep under spinlock
10 warning.
11
12 It should be safe to convert this to a sleepable lock since:
13 - sysfs read/write can sleep
14 - netdev_trig_work is a work queue and can sleep
15 - netdev _trig_notify can sleep
16
17 The spinlock was used when brightness didn't support sleeping, but this
18 changed and now it supported with brightness_set_blocking().
19
20 Convert to mutex lock to permit sleeping using brightness_set_blocking().
21
22 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
23 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
24 Signed-off-by: Lee Jones <lee@kernel.org>
25 Link: https://lore.kernel.org/r/20230419210743.3594-6-ansuelsmth@gmail.com
26 ---
27 drivers/leds/trigger/ledtrig-netdev.c | 18 +++++++++---------
28 1 file changed, 9 insertions(+), 9 deletions(-)
29
30 --- a/drivers/leds/trigger/ledtrig-netdev.c
31 +++ b/drivers/leds/trigger/ledtrig-netdev.c
32 @@ -20,7 +20,7 @@
33 #include <linux/list.h>
34 #include <linux/module.h>
35 #include <linux/netdevice.h>
36 -#include <linux/spinlock.h>
37 +#include <linux/mutex.h>
38 #include <linux/timer.h>
39 #include "../leds.h"
40
41 @@ -37,7 +37,7 @@
42 */
43
44 struct led_netdev_data {
45 - spinlock_t lock;
46 + struct mutex lock;
47
48 struct delayed_work work;
49 struct notifier_block notifier;
50 @@ -97,9 +97,9 @@ static ssize_t device_name_show(struct d
51 struct led_netdev_data *trigger_data = led_trigger_get_drvdata(dev);
52 ssize_t len;
53
54 - spin_lock_bh(&trigger_data->lock);
55 + mutex_lock(&trigger_data->lock);
56 len = sprintf(buf, "%s\n", trigger_data->device_name);
57 - spin_unlock_bh(&trigger_data->lock);
58 + mutex_unlock(&trigger_data->lock);
59
60 return len;
61 }
62 @@ -115,7 +115,7 @@ static ssize_t device_name_store(struct
63
64 cancel_delayed_work_sync(&trigger_data->work);
65
66 - spin_lock_bh(&trigger_data->lock);
67 + mutex_lock(&trigger_data->lock);
68
69 if (trigger_data->net_dev) {
70 dev_put(trigger_data->net_dev);
71 @@ -138,7 +138,7 @@ static ssize_t device_name_store(struct
72 trigger_data->last_activity = 0;
73
74 set_baseline_state(trigger_data);
75 - spin_unlock_bh(&trigger_data->lock);
76 + mutex_unlock(&trigger_data->lock);
77
78 return size;
79 }
80 @@ -279,7 +279,7 @@ static int netdev_trig_notify(struct not
81
82 cancel_delayed_work_sync(&trigger_data->work);
83
84 - spin_lock_bh(&trigger_data->lock);
85 + mutex_lock(&trigger_data->lock);
86
87 trigger_data->carrier_link_up = false;
88 switch (evt) {
89 @@ -304,7 +304,7 @@ static int netdev_trig_notify(struct not
90
91 set_baseline_state(trigger_data);
92
93 - spin_unlock_bh(&trigger_data->lock);
94 + mutex_unlock(&trigger_data->lock);
95
96 return NOTIFY_DONE;
97 }
98 @@ -365,7 +365,7 @@ static int netdev_trig_activate(struct l
99 if (!trigger_data)
100 return -ENOMEM;
101
102 - spin_lock_init(&trigger_data->lock);
103 + mutex_init(&trigger_data->lock);
104
105 trigger_data->notifier.notifier_call = netdev_trig_notify;
106 trigger_data->notifier.priority = 10;