Add patches accepted for 2.6.30-rc1
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / releases / upstream / 2.6.30-rc1 / 0010-thinkpad-acpi-restrict-access-to-some-firmware-LEDs.patch
blobeaa57811fda4a56f78db5f40e2685b767423a2c2
1 From a4d5effcc73749ee3ebbf578d162905e6fa4e07d Mon Sep 17 00:00:00 2001
2 From: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
3 Date: Sat, 4 Apr 2009 04:25:49 +0000
4 Subject: thinkpad-acpi: restrict access to some firmware LEDs
6 Some of the ThinkPad LEDs indicate critical conditions that can cause
7 data loss or cause hardware damage when ignored (e.g. force-ejecting
8 a powered up bay; ignoring a failing battery, or empty battery; force-
9 undocking with the dock buses still active, etc).
11 On almost all ThinkPads, LED access is write-only, and the firmware
12 usually does fire-and-forget signaling on them, so you effectively
13 lose whatever message the firmware was trying to convey to the user
14 when you override the LED state, without any chance to restore it.
16 Restrict access to all LEDs that can convey important alarms, or that
17 could mislead the user into incorrectly operating the hardware. This
18 will make the Lenovo engineers less unhappy about the whole issue.
20 Allow users that really want it to still control all LEDs, it is the
21 unaware user that we have to worry about.
23 Signed-off-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
24 Signed-off-by: Len Brown <len.brown@intel.com>
25 ---
26 Documentation/laptops/thinkpad-acpi.txt | 11 +++++
27 drivers/platform/x86/Kconfig | 24 ++++++++++
28 drivers/platform/x86/thinkpad_acpi.c | 76 +++++++++++++++++++++++--------
29 3 files changed, 91 insertions(+), 20 deletions(-)
31 diff --git a/Documentation/laptops/thinkpad-acpi.txt b/Documentation/laptops/thinkpad-acpi.txt
32 index de6f14c..bce1d95 100644
33 --- a/Documentation/laptops/thinkpad-acpi.txt
34 +++ b/Documentation/laptops/thinkpad-acpi.txt
35 @@ -901,6 +901,17 @@ some older ThinkPad models, it is possible to query the status of the
36 LED indicators as well. Newer ThinkPads cannot query the real status
37 of the LED indicators.
39 +Because misuse of the LEDs could induce an unaware user to perform
40 +dangerous actions (like undocking or ejecting a bay device while the
41 +buses are still active), or mask an important alarm (such as a nearly
42 +empty battery, or a broken battery), access to most LEDs is
43 +restricted.
45 +Unrestricted access to all LEDs requires that thinkpad-acpi be
46 +compiled with the CONFIG_THINKPAD_ACPI_UNSAFE_LEDS option enabled.
47 +Distributions must never enable this option. Individual users that
48 +are aware of the consequences are welcome to enabling it.
50 procfs notes:
52 The available commands are:
53 diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
54 index 3608081..d45c6ab 100644
55 --- a/drivers/platform/x86/Kconfig
56 +++ b/drivers/platform/x86/Kconfig
57 @@ -226,6 +226,30 @@ config THINKPAD_ACPI_DEBUG
59 If you are not sure, say N here.
61 +config THINKPAD_ACPI_UNSAFE_LEDS
62 + bool "Allow control of important LEDs (unsafe)"
63 + depends on THINKPAD_ACPI
64 + default n
65 + ---help---
66 + Overriding LED state on ThinkPads can mask important
67 + firmware alerts (like critical battery condition), or misled
68 + the user into damaging the hardware (undocking or ejecting
69 + the bay while buses are still active), etc.
71 + LED control on the ThinkPad is write-only (with very few
72 + exceptions on very ancient models), which makes it
73 + impossible to know beforehand if important information will
74 + be lost when one changes LED state.
76 + Users that know what they are doing can enable this option
77 + and the driver will allow control of every LED, including
78 + the ones on the dock stations.
80 + Never enable this option on a distribution kernel.
82 + Say N here, unless you are building a kernel for your own
83 + use, and need to control the important firmware LEDs.
85 config THINKPAD_ACPI_DOCK
86 bool "Legacy Docking Station Support"
87 depends on THINKPAD_ACPI
88 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
89 index f003fb7..38c34c7 100644
90 --- a/drivers/platform/x86/thinkpad_acpi.c
91 +++ b/drivers/platform/x86/thinkpad_acpi.c
92 @@ -4657,6 +4657,16 @@ static const char * const tpacpi_led_names[TPACPI_LED_NUMLEDS] = {
93 "tpacpi::unknown_led",
94 "tpacpi::standby",
96 +#define TPACPI_SAFE_LEDS 0x0081U
98 +static inline bool tpacpi_is_led_restricted(const unsigned int led)
100 +#ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
101 + return false;
102 +#else
103 + return (TPACPI_SAFE_LEDS & (1 << led)) == 0;
104 +#endif
107 static int led_get_status(const unsigned int led)
109 @@ -4694,16 +4704,20 @@ static int led_set_status(const unsigned int led,
110 switch (led_supported) {
111 case TPACPI_LED_570:
112 /* 570 */
113 - if (led > 7)
114 + if (unlikely(led > 7))
115 return -EINVAL;
116 + if (unlikely(tpacpi_is_led_restricted(led)))
117 + return -EPERM;
118 if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
119 (1 << led), led_sled_arg1[ledstatus]))
120 rc = -EIO;
121 break;
122 case TPACPI_LED_OLD:
123 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
124 - if (led > 7)
125 + if (unlikely(led > 7))
126 return -EINVAL;
127 + if (unlikely(tpacpi_is_led_restricted(led)))
128 + return -EPERM;
129 rc = ec_write(TPACPI_LED_EC_HLMS, (1 << led));
130 if (rc >= 0)
131 rc = ec_write(TPACPI_LED_EC_HLBL,
132 @@ -4714,6 +4728,10 @@ static int led_set_status(const unsigned int led,
133 break;
134 case TPACPI_LED_NEW:
135 /* all others */
136 + if (unlikely(led >= TPACPI_LED_NUMLEDS))
137 + return -EINVAL;
138 + if (unlikely(tpacpi_is_led_restricted(led)))
139 + return -EPERM;
140 if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
141 led, led_led_arg1[ledstatus]))
142 rc = -EIO;
143 @@ -4806,6 +4824,30 @@ static void led_exit(void)
144 kfree(tpacpi_leds);
147 +static int __init tpacpi_init_led(unsigned int led)
149 + int rc;
151 + tpacpi_leds[led].led = led;
153 + tpacpi_leds[led].led_classdev.brightness_set = &led_sysfs_set;
154 + tpacpi_leds[led].led_classdev.blink_set = &led_sysfs_blink_set;
155 + if (led_supported == TPACPI_LED_570)
156 + tpacpi_leds[led].led_classdev.brightness_get =
157 + &led_sysfs_get;
159 + tpacpi_leds[led].led_classdev.name = tpacpi_led_names[led];
161 + INIT_WORK(&tpacpi_leds[led].work, led_set_status_worker);
163 + rc = led_classdev_register(&tpacpi_pdev->dev,
164 + &tpacpi_leds[led].led_classdev);
165 + if (rc < 0)
166 + tpacpi_leds[led].led_classdev.name = NULL;
168 + return rc;
171 static int __init led_init(struct ibm_init_struct *iibm)
173 unsigned int i;
174 @@ -4839,27 +4881,21 @@ static int __init led_init(struct ibm_init_struct *iibm)
177 for (i = 0; i < TPACPI_LED_NUMLEDS; i++) {
178 - tpacpi_leds[i].led = i;
180 - tpacpi_leds[i].led_classdev.brightness_set = &led_sysfs_set;
181 - tpacpi_leds[i].led_classdev.blink_set = &led_sysfs_blink_set;
182 - if (led_supported == TPACPI_LED_570)
183 - tpacpi_leds[i].led_classdev.brightness_get =
184 - &led_sysfs_get;
186 - tpacpi_leds[i].led_classdev.name = tpacpi_led_names[i];
188 - INIT_WORK(&tpacpi_leds[i].work, led_set_status_worker);
190 - rc = led_classdev_register(&tpacpi_pdev->dev,
191 - &tpacpi_leds[i].led_classdev);
192 - if (rc < 0) {
193 - tpacpi_leds[i].led_classdev.name = NULL;
194 - led_exit();
195 - return rc;
196 + if (!tpacpi_is_led_restricted(i)) {
197 + rc = tpacpi_init_led(i);
198 + if (rc < 0) {
199 + led_exit();
200 + return rc;
205 +#ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
206 + if (led_supported != TPACPI_LED_NONE)
207 + printk(TPACPI_NOTICE
208 + "warning: userspace override of important "
209 + "firmware LEDs is enabled\n");
210 +#endif
211 return (led_supported != TPACPI_LED_NONE)? 0 : 1;
215 1.6.2.1