summaryrefslogtreecommitdiffstats
path: root/drivers/leds
diff options
context:
space:
mode:
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>2018-07-02 16:05:21 -0400
committerJacek Anaszewski <jacek.anaszewski@gmail.com>2018-07-05 17:21:10 -0400
commit2282e125a406e09331c5a785e3df29035c99a607 (patch)
treeb5936ee2bde7c85bf71aaff259026857b2bda6d9 /drivers/leds
parent033692eb3ec8305f6e9998b297aaec6899680637 (diff)
leds: triggers: let struct led_trigger::activate() return an error code
Given that activating a trigger can fail, let the callback return an indication. This prevents to have a trigger active according to the "trigger" sysfs attribute but not functional. All users are changed accordingly to return 0 for now. There is no intended change in behaviour. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Acked-by: Pavel Machek <pavel@ucw.cz> Signed-off-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
Diffstat (limited to 'drivers/leds')
-rw-r--r--drivers/leds/led-triggers.c24
-rw-r--r--drivers/leds/trigger/ledtrig-activity.c8
-rw-r--r--drivers/leds/trigger/ledtrig-backlight.c8
-rw-r--r--drivers/leds/trigger/ledtrig-default-on.c3
-rw-r--r--drivers/leds/trigger/ledtrig-gpio.c8
-rw-r--r--drivers/leds/trigger/ledtrig-heartbeat.c8
-rw-r--r--drivers/leds/trigger/ledtrig-netdev.c8
-rw-r--r--drivers/leds/trigger/ledtrig-oneshot.c8
-rw-r--r--drivers/leds/trigger/ledtrig-timer.c8
-rw-r--r--drivers/leds/trigger/ledtrig-transient.c8
10 files changed, 63 insertions, 28 deletions
diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c
index 431123b048a2..a8786f4b3453 100644
--- a/drivers/leds/led-triggers.c
+++ b/drivers/leds/led-triggers.c
@@ -103,15 +103,16 @@ ssize_t led_trigger_show(struct device *dev, struct device_attribute *attr,
103EXPORT_SYMBOL_GPL(led_trigger_show); 103EXPORT_SYMBOL_GPL(led_trigger_show);
104 104
105/* Caller must ensure led_cdev->trigger_lock held */ 105/* Caller must ensure led_cdev->trigger_lock held */
106void led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig) 106int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)
107{ 107{
108 unsigned long flags; 108 unsigned long flags;
109 char *event = NULL; 109 char *event = NULL;
110 char *envp[2]; 110 char *envp[2];
111 const char *name; 111 const char *name;
112 int ret;
112 113
113 if (!led_cdev->trigger && !trig) 114 if (!led_cdev->trigger && !trig)
114 return; 115 return 0;
115 116
116 name = trig ? trig->name : "none"; 117 name = trig ? trig->name : "none";
117 event = kasprintf(GFP_KERNEL, "TRIGGER=%s", name); 118 event = kasprintf(GFP_KERNEL, "TRIGGER=%s", name);
@@ -134,8 +135,14 @@ void led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)
134 list_add_tail(&led_cdev->trig_list, &trig->led_cdevs); 135 list_add_tail(&led_cdev->trig_list, &trig->led_cdevs);
135 write_unlock_irqrestore(&trig->leddev_list_lock, flags); 136 write_unlock_irqrestore(&trig->leddev_list_lock, flags);
136 led_cdev->trigger = trig; 137 led_cdev->trigger = trig;
138
137 if (trig->activate) 139 if (trig->activate)
138 trig->activate(led_cdev); 140 ret = trig->activate(led_cdev);
141 else
142 ret = 0;
143
144 if (ret)
145 goto err_activate;
139 } 146 }
140 147
141 if (event) { 148 if (event) {
@@ -146,6 +153,17 @@ void led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)
146 "%s: Error sending uevent\n", __func__); 153 "%s: Error sending uevent\n", __func__);
147 kfree(event); 154 kfree(event);
148 } 155 }
156
157 return 0;
158
159err_activate:
160 led_cdev->trigger = NULL;
161 write_lock_irqsave(&led_cdev->trigger->leddev_list_lock, flags);
162 list_del(&led_cdev->trig_list);
163 write_unlock_irqrestore(&led_cdev->trigger->leddev_list_lock, flags);
164 led_set_brightness(led_cdev, LED_OFF);
165
166 return ret;
149} 167}
150EXPORT_SYMBOL_GPL(led_trigger_set); 168EXPORT_SYMBOL_GPL(led_trigger_set);
151 169
diff --git a/drivers/leds/trigger/ledtrig-activity.c b/drivers/leds/trigger/ledtrig-activity.c
index b39e1bb9a9ec..2fc065fb1754 100644
--- a/drivers/leds/trigger/ledtrig-activity.c
+++ b/drivers/leds/trigger/ledtrig-activity.c
@@ -178,20 +178,20 @@ static ssize_t led_invert_store(struct device *dev,
178 178
179static DEVICE_ATTR(invert, 0644, led_invert_show, led_invert_store); 179static DEVICE_ATTR(invert, 0644, led_invert_show, led_invert_store);
180 180
181static void activity_activate(struct led_classdev *led_cdev) 181static int activity_activate(struct led_classdev *led_cdev)
182{ 182{
183 struct activity_data *activity_data; 183 struct activity_data *activity_data;
184 int rc; 184 int rc;
185 185
186 activity_data = kzalloc(sizeof(*activity_data), GFP_KERNEL); 186 activity_data = kzalloc(sizeof(*activity_data), GFP_KERNEL);
187 if (!activity_data) 187 if (!activity_data)
188 return; 188 return 0;
189 189
190 led_cdev->trigger_data = activity_data; 190 led_cdev->trigger_data = activity_data;
191 rc = device_create_file(led_cdev->dev, &dev_attr_invert); 191 rc = device_create_file(led_cdev->dev, &dev_attr_invert);
192 if (rc) { 192 if (rc) {
193 kfree(led_cdev->trigger_data); 193 kfree(led_cdev->trigger_data);
194 return; 194 return 0;
195 } 195 }
196 196
197 activity_data->led_cdev = led_cdev; 197 activity_data->led_cdev = led_cdev;
@@ -201,6 +201,8 @@ static void activity_activate(struct led_classdev *led_cdev)
201 led_activity_function(&activity_data->timer); 201 led_activity_function(&activity_data->timer);
202 set_bit(LED_BLINK_SW, &led_cdev->work_flags); 202 set_bit(LED_BLINK_SW, &led_cdev->work_flags);
203 led_cdev->activated = true; 203 led_cdev->activated = true;
204
205 return 0;
204} 206}
205 207
206static void activity_deactivate(struct led_classdev *led_cdev) 208static void activity_deactivate(struct led_classdev *led_cdev)
diff --git a/drivers/leds/trigger/ledtrig-backlight.c b/drivers/leds/trigger/ledtrig-backlight.c
index 1ca1f1608f76..84512960d630 100644
--- a/drivers/leds/trigger/ledtrig-backlight.c
+++ b/drivers/leds/trigger/ledtrig-backlight.c
@@ -97,7 +97,7 @@ static ssize_t bl_trig_invert_store(struct device *dev,
97} 97}
98static DEVICE_ATTR(inverted, 0644, bl_trig_invert_show, bl_trig_invert_store); 98static DEVICE_ATTR(inverted, 0644, bl_trig_invert_show, bl_trig_invert_store);
99 99
100static void bl_trig_activate(struct led_classdev *led) 100static int bl_trig_activate(struct led_classdev *led)
101{ 101{
102 int ret; 102 int ret;
103 103
@@ -107,7 +107,7 @@ static void bl_trig_activate(struct led_classdev *led)
107 led->trigger_data = n; 107 led->trigger_data = n;
108 if (!n) { 108 if (!n) {
109 dev_err(led->dev, "unable to allocate backlight trigger\n"); 109 dev_err(led->dev, "unable to allocate backlight trigger\n");
110 return; 110 return 0;
111 } 111 }
112 112
113 ret = device_create_file(led->dev, &dev_attr_inverted); 113 ret = device_create_file(led->dev, &dev_attr_inverted);
@@ -124,11 +124,13 @@ static void bl_trig_activate(struct led_classdev *led)
124 dev_err(led->dev, "unable to register backlight trigger\n"); 124 dev_err(led->dev, "unable to register backlight trigger\n");
125 led->activated = true; 125 led->activated = true;
126 126
127 return; 127 return 0;
128 128
129err_invert: 129err_invert:
130 led->trigger_data = NULL; 130 led->trigger_data = NULL;
131 kfree(n); 131 kfree(n);
132
133 return 0;
132} 134}
133 135
134static void bl_trig_deactivate(struct led_classdev *led) 136static void bl_trig_deactivate(struct led_classdev *led)
diff --git a/drivers/leds/trigger/ledtrig-default-on.c b/drivers/leds/trigger/ledtrig-default-on.c
index 4ccea04b7a6b..2996fe672198 100644
--- a/drivers/leds/trigger/ledtrig-default-on.c
+++ b/drivers/leds/trigger/ledtrig-default-on.c
@@ -16,9 +16,10 @@
16#include <linux/leds.h> 16#include <linux/leds.h>
17#include "../leds.h" 17#include "../leds.h"
18 18
19static void defon_trig_activate(struct led_classdev *led_cdev) 19static int defon_trig_activate(struct led_classdev *led_cdev)
20{ 20{
21 led_set_brightness_nosleep(led_cdev, led_cdev->max_brightness); 21 led_set_brightness_nosleep(led_cdev, led_cdev->max_brightness);
22 return 0;
22} 23}
23 24
24static struct led_trigger defon_led_trigger = { 25static struct led_trigger defon_led_trigger = {
diff --git a/drivers/leds/trigger/ledtrig-gpio.c b/drivers/leds/trigger/ledtrig-gpio.c
index 93906a17a4b6..f5358c40d03f 100644
--- a/drivers/leds/trigger/ledtrig-gpio.c
+++ b/drivers/leds/trigger/ledtrig-gpio.c
@@ -162,14 +162,14 @@ static ssize_t gpio_trig_gpio_store(struct device *dev,
162} 162}
163static DEVICE_ATTR(gpio, 0644, gpio_trig_gpio_show, gpio_trig_gpio_store); 163static DEVICE_ATTR(gpio, 0644, gpio_trig_gpio_show, gpio_trig_gpio_store);
164 164
165static void gpio_trig_activate(struct led_classdev *led) 165static int gpio_trig_activate(struct led_classdev *led)
166{ 166{
167 struct gpio_trig_data *gpio_data; 167 struct gpio_trig_data *gpio_data;
168 int ret; 168 int ret;
169 169
170 gpio_data = kzalloc(sizeof(*gpio_data), GFP_KERNEL); 170 gpio_data = kzalloc(sizeof(*gpio_data), GFP_KERNEL);
171 if (!gpio_data) 171 if (!gpio_data)
172 return; 172 return 0;
173 173
174 ret = device_create_file(led->dev, &dev_attr_gpio); 174 ret = device_create_file(led->dev, &dev_attr_gpio);
175 if (ret) 175 if (ret)
@@ -187,7 +187,7 @@ static void gpio_trig_activate(struct led_classdev *led)
187 led->trigger_data = gpio_data; 187 led->trigger_data = gpio_data;
188 led->activated = true; 188 led->activated = true;
189 189
190 return; 190 return 0;
191 191
192err_brightness: 192err_brightness:
193 device_remove_file(led->dev, &dev_attr_inverted); 193 device_remove_file(led->dev, &dev_attr_inverted);
@@ -197,6 +197,8 @@ err_inverted:
197 197
198err_gpio: 198err_gpio:
199 kfree(gpio_data); 199 kfree(gpio_data);
200
201 return 0;
200} 202}
201 203
202static void gpio_trig_deactivate(struct led_classdev *led) 204static void gpio_trig_deactivate(struct led_classdev *led)
diff --git a/drivers/leds/trigger/ledtrig-heartbeat.c b/drivers/leds/trigger/ledtrig-heartbeat.c
index 304b929edb8e..03a8dfce8fb9 100644
--- a/drivers/leds/trigger/ledtrig-heartbeat.c
+++ b/drivers/leds/trigger/ledtrig-heartbeat.c
@@ -121,21 +121,21 @@ static ssize_t led_invert_store(struct device *dev,
121 121
122static DEVICE_ATTR(invert, 0644, led_invert_show, led_invert_store); 122static DEVICE_ATTR(invert, 0644, led_invert_show, led_invert_store);
123 123
124static void heartbeat_trig_activate(struct led_classdev *led_cdev) 124static int heartbeat_trig_activate(struct led_classdev *led_cdev)
125{ 125{
126 struct heartbeat_trig_data *heartbeat_data; 126 struct heartbeat_trig_data *heartbeat_data;
127 int rc; 127 int rc;
128 128
129 heartbeat_data = kzalloc(sizeof(*heartbeat_data), GFP_KERNEL); 129 heartbeat_data = kzalloc(sizeof(*heartbeat_data), GFP_KERNEL);
130 if (!heartbeat_data) 130 if (!heartbeat_data)
131 return; 131 return 0;
132 132
133 led_cdev->trigger_data = heartbeat_data; 133 led_cdev->trigger_data = heartbeat_data;
134 heartbeat_data->led_cdev = led_cdev; 134 heartbeat_data->led_cdev = led_cdev;
135 rc = device_create_file(led_cdev->dev, &dev_attr_invert); 135 rc = device_create_file(led_cdev->dev, &dev_attr_invert);
136 if (rc) { 136 if (rc) {
137 kfree(led_cdev->trigger_data); 137 kfree(led_cdev->trigger_data);
138 return; 138 return 0;
139 } 139 }
140 140
141 timer_setup(&heartbeat_data->timer, led_heartbeat_function, 0); 141 timer_setup(&heartbeat_data->timer, led_heartbeat_function, 0);
@@ -145,6 +145,8 @@ static void heartbeat_trig_activate(struct led_classdev *led_cdev)
145 led_heartbeat_function(&heartbeat_data->timer); 145 led_heartbeat_function(&heartbeat_data->timer);
146 set_bit(LED_BLINK_SW, &led_cdev->work_flags); 146 set_bit(LED_BLINK_SW, &led_cdev->work_flags);
147 led_cdev->activated = true; 147 led_cdev->activated = true;
148
149 return 0;
148} 150}
149 151
150static void heartbeat_trig_deactivate(struct led_classdev *led_cdev) 152static void heartbeat_trig_deactivate(struct led_classdev *led_cdev)
diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c
index 6df4781a6308..bb05937255de 100644
--- a/drivers/leds/trigger/ledtrig-netdev.c
+++ b/drivers/leds/trigger/ledtrig-netdev.c
@@ -388,14 +388,14 @@ static void netdev_trig_work(struct work_struct *work)
388 (atomic_read(&trigger_data->interval)*2)); 388 (atomic_read(&trigger_data->interval)*2));
389} 389}
390 390
391static void netdev_trig_activate(struct led_classdev *led_cdev) 391static int netdev_trig_activate(struct led_classdev *led_cdev)
392{ 392{
393 struct led_netdev_data *trigger_data; 393 struct led_netdev_data *trigger_data;
394 int rc; 394 int rc;
395 395
396 trigger_data = kzalloc(sizeof(struct led_netdev_data), GFP_KERNEL); 396 trigger_data = kzalloc(sizeof(struct led_netdev_data), GFP_KERNEL);
397 if (!trigger_data) 397 if (!trigger_data)
398 return; 398 return 0;
399 399
400 spin_lock_init(&trigger_data->lock); 400 spin_lock_init(&trigger_data->lock);
401 401
@@ -432,7 +432,7 @@ static void netdev_trig_activate(struct led_classdev *led_cdev)
432 rc = register_netdevice_notifier(&trigger_data->notifier); 432 rc = register_netdevice_notifier(&trigger_data->notifier);
433 if (rc) 433 if (rc)
434 goto err_out_interval; 434 goto err_out_interval;
435 return; 435 return 0;
436 436
437err_out_interval: 437err_out_interval:
438 device_remove_file(led_cdev->dev, &dev_attr_interval); 438 device_remove_file(led_cdev->dev, &dev_attr_interval);
@@ -447,6 +447,8 @@ err_out_device_name:
447err_out: 447err_out:
448 led_cdev->trigger_data = NULL; 448 led_cdev->trigger_data = NULL;
449 kfree(trigger_data); 449 kfree(trigger_data);
450
451 return 0;
450} 452}
451 453
452static void netdev_trig_deactivate(struct led_classdev *led_cdev) 454static void netdev_trig_deactivate(struct led_classdev *led_cdev)
diff --git a/drivers/leds/trigger/ledtrig-oneshot.c b/drivers/leds/trigger/ledtrig-oneshot.c
index b8ea9f0f1e19..7bbf92bd7f80 100644
--- a/drivers/leds/trigger/ledtrig-oneshot.c
+++ b/drivers/leds/trigger/ledtrig-oneshot.c
@@ -122,14 +122,14 @@ static DEVICE_ATTR(delay_off, 0644, led_delay_off_show, led_delay_off_store);
122static DEVICE_ATTR(invert, 0644, led_invert_show, led_invert_store); 122static DEVICE_ATTR(invert, 0644, led_invert_show, led_invert_store);
123static DEVICE_ATTR(shot, 0200, NULL, led_shot); 123static DEVICE_ATTR(shot, 0200, NULL, led_shot);
124 124
125static void oneshot_trig_activate(struct led_classdev *led_cdev) 125static int oneshot_trig_activate(struct led_classdev *led_cdev)
126{ 126{
127 struct oneshot_trig_data *oneshot_data; 127 struct oneshot_trig_data *oneshot_data;
128 int rc; 128 int rc;
129 129
130 oneshot_data = kzalloc(sizeof(*oneshot_data), GFP_KERNEL); 130 oneshot_data = kzalloc(sizeof(*oneshot_data), GFP_KERNEL);
131 if (!oneshot_data) 131 if (!oneshot_data)
132 return; 132 return 0;
133 133
134 led_cdev->trigger_data = oneshot_data; 134 led_cdev->trigger_data = oneshot_data;
135 135
@@ -151,7 +151,7 @@ static void oneshot_trig_activate(struct led_classdev *led_cdev)
151 151
152 led_cdev->activated = true; 152 led_cdev->activated = true;
153 153
154 return; 154 return 0;
155 155
156err_out_invert: 156err_out_invert:
157 device_remove_file(led_cdev->dev, &dev_attr_invert); 157 device_remove_file(led_cdev->dev, &dev_attr_invert);
@@ -161,6 +161,8 @@ err_out_delayon:
161 device_remove_file(led_cdev->dev, &dev_attr_delay_on); 161 device_remove_file(led_cdev->dev, &dev_attr_delay_on);
162err_out_trig_data: 162err_out_trig_data:
163 kfree(led_cdev->trigger_data); 163 kfree(led_cdev->trigger_data);
164
165 return 0;
164} 166}
165 167
166static void oneshot_trig_deactivate(struct led_classdev *led_cdev) 168static void oneshot_trig_deactivate(struct led_classdev *led_cdev)
diff --git a/drivers/leds/trigger/ledtrig-timer.c b/drivers/leds/trigger/ledtrig-timer.c
index 10fc0966b0e3..527055d815ad 100644
--- a/drivers/leds/trigger/ledtrig-timer.c
+++ b/drivers/leds/trigger/ledtrig-timer.c
@@ -70,7 +70,7 @@ static ssize_t led_delay_off_store(struct device *dev,
70static DEVICE_ATTR(delay_on, 0644, led_delay_on_show, led_delay_on_store); 70static DEVICE_ATTR(delay_on, 0644, led_delay_on_show, led_delay_on_store);
71static DEVICE_ATTR(delay_off, 0644, led_delay_off_show, led_delay_off_store); 71static DEVICE_ATTR(delay_off, 0644, led_delay_off_show, led_delay_off_store);
72 72
73static void timer_trig_activate(struct led_classdev *led_cdev) 73static int timer_trig_activate(struct led_classdev *led_cdev)
74{ 74{
75 int rc; 75 int rc;
76 76
@@ -78,7 +78,7 @@ static void timer_trig_activate(struct led_classdev *led_cdev)
78 78
79 rc = device_create_file(led_cdev->dev, &dev_attr_delay_on); 79 rc = device_create_file(led_cdev->dev, &dev_attr_delay_on);
80 if (rc) 80 if (rc)
81 return; 81 return 0;
82 rc = device_create_file(led_cdev->dev, &dev_attr_delay_off); 82 rc = device_create_file(led_cdev->dev, &dev_attr_delay_off);
83 if (rc) 83 if (rc)
84 goto err_out_delayon; 84 goto err_out_delayon;
@@ -87,10 +87,12 @@ static void timer_trig_activate(struct led_classdev *led_cdev)
87 &led_cdev->blink_delay_off); 87 &led_cdev->blink_delay_off);
88 led_cdev->activated = true; 88 led_cdev->activated = true;
89 89
90 return; 90 return 0;
91 91
92err_out_delayon: 92err_out_delayon:
93 device_remove_file(led_cdev->dev, &dev_attr_delay_on); 93 device_remove_file(led_cdev->dev, &dev_attr_delay_on);
94
95 return 0;
94} 96}
95 97
96static void timer_trig_deactivate(struct led_classdev *led_cdev) 98static void timer_trig_deactivate(struct led_classdev *led_cdev)
diff --git a/drivers/leds/trigger/ledtrig-transient.c b/drivers/leds/trigger/ledtrig-transient.c
index 9d1769073562..a55fc58179a9 100644
--- a/drivers/leds/trigger/ledtrig-transient.c
+++ b/drivers/leds/trigger/ledtrig-transient.c
@@ -152,7 +152,7 @@ static DEVICE_ATTR(duration, 0644, transient_duration_show,
152 transient_duration_store); 152 transient_duration_store);
153static DEVICE_ATTR(state, 0644, transient_state_show, transient_state_store); 153static DEVICE_ATTR(state, 0644, transient_state_show, transient_state_store);
154 154
155static void transient_trig_activate(struct led_classdev *led_cdev) 155static int transient_trig_activate(struct led_classdev *led_cdev)
156{ 156{
157 int rc; 157 int rc;
158 struct transient_trig_data *tdata; 158 struct transient_trig_data *tdata;
@@ -161,7 +161,7 @@ static void transient_trig_activate(struct led_classdev *led_cdev)
161 if (!tdata) { 161 if (!tdata) {
162 dev_err(led_cdev->dev, 162 dev_err(led_cdev->dev,
163 "unable to allocate transient trigger\n"); 163 "unable to allocate transient trigger\n");
164 return; 164 return 0;
165 } 165 }
166 led_cdev->trigger_data = tdata; 166 led_cdev->trigger_data = tdata;
167 tdata->led_cdev = led_cdev; 167 tdata->led_cdev = led_cdev;
@@ -181,7 +181,7 @@ static void transient_trig_activate(struct led_classdev *led_cdev)
181 timer_setup(&tdata->timer, transient_timer_function, 0); 181 timer_setup(&tdata->timer, transient_timer_function, 0);
182 led_cdev->activated = true; 182 led_cdev->activated = true;
183 183
184 return; 184 return 0;
185 185
186err_out_state: 186err_out_state:
187 device_remove_file(led_cdev->dev, &dev_attr_duration); 187 device_remove_file(led_cdev->dev, &dev_attr_duration);
@@ -191,6 +191,8 @@ err_out:
191 dev_err(led_cdev->dev, "unable to register transient trigger\n"); 191 dev_err(led_cdev->dev, "unable to register transient trigger\n");
192 led_cdev->trigger_data = NULL; 192 led_cdev->trigger_data = NULL;
193 kfree(tdata); 193 kfree(tdata);
194
195 return 0;
194} 196}
195 197
196static void transient_trig_deactivate(struct led_classdev *led_cdev) 198static void transient_trig_deactivate(struct led_classdev *led_cdev)