提交 24e45bbe 编写于 作者: H Henrique de Moraes Holschuh 提交者: Len Brown

thinkpad-acpi: fix LED handling on older ThinkPads

The less tested codepaths for LED handling, used on ThinkPads 570, 600e/x,
770e, 770x, A21e, A2xm/p, T20-22, X20 and maybe a few others, would write
data to kernel memory it had no business touching, for leds number 3 and
above.  If one is lucky, that illegal write would cause an OOPS, but
chances are it would silently corrupt a byte.

The problem was introduced in commit af116101, "ACPI: thinkpad-acpi: add
sysfs led class support to thinkpad leds (v3.2)".

Fix the bug by refactoring the entire code to be far more obvious on what
it wants to do.  Also do some defensive "constification".

Issue reported by Karol Lewandowski <lmctlx@gmail.com> (he's an lucky guy
and got an OOPS instead of silent corruption :-) ).

Root cause of the OOPS identified by Adrian Bunk <bunk@kernel.org>.
Thanks, Adrian!
Signed-off-by: NHenrique de Moraes Holschuh <hmh@hmh.eng.br>
Tested-by: NKarol Lewandowski <lmctlx@gmail.com>
Signed-off-by: NLen Brown <len.brown@intel.com>
上级 9c0a76e1
...@@ -3853,7 +3853,7 @@ static const char * const tpacpi_led_names[TPACPI_LED_NUMLEDS] = { ...@@ -3853,7 +3853,7 @@ static const char * const tpacpi_led_names[TPACPI_LED_NUMLEDS] = {
"tpacpi::standby", "tpacpi::standby",
}; };
static int led_get_status(unsigned int led) static int led_get_status(const unsigned int led)
{ {
int status; int status;
enum led_status_t led_s; enum led_status_t led_s;
...@@ -3877,41 +3877,42 @@ static int led_get_status(unsigned int led) ...@@ -3877,41 +3877,42 @@ static int led_get_status(unsigned int led)
/* not reached */ /* not reached */
} }
static int led_set_status(unsigned int led, enum led_status_t ledstatus) static int led_set_status(const unsigned int led,
const enum led_status_t ledstatus)
{ {
/* off, on, blink. Index is led_status_t */ /* off, on, blink. Index is led_status_t */
static const int led_sled_arg1[] = { 0, 1, 3 }; static const unsigned int led_sled_arg1[] = { 0, 1, 3 };
static const int led_exp_hlbl[] = { 0, 0, 1 }; /* led# * */ static const unsigned int led_led_arg1[] = { 0, 0x80, 0xc0 };
static const int led_exp_hlcl[] = { 0, 1, 1 }; /* led# * */
static const int led_led_arg1[] = { 0, 0x80, 0xc0 };
int rc = 0; int rc = 0;
switch (led_supported) { switch (led_supported) {
case TPACPI_LED_570: case TPACPI_LED_570:
/* 570 */ /* 570 */
led = 1 << led; if (led > 7)
if (!acpi_evalf(led_handle, NULL, NULL, "vdd", return -EINVAL;
led, led_sled_arg1[ledstatus])) if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
rc = -EIO; (1 << led), led_sled_arg1[ledstatus]))
break; rc = -EIO;
break;
case TPACPI_LED_OLD: case TPACPI_LED_OLD:
/* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */ /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
led = 1 << led; if (led > 7)
rc = ec_write(TPACPI_LED_EC_HLMS, led); return -EINVAL;
if (rc >= 0) rc = ec_write(TPACPI_LED_EC_HLMS, (1 << led));
rc = ec_write(TPACPI_LED_EC_HLBL, if (rc >= 0)
led * led_exp_hlbl[ledstatus]); rc = ec_write(TPACPI_LED_EC_HLBL,
if (rc >= 0) (ledstatus == TPACPI_LED_BLINK) << led);
rc = ec_write(TPACPI_LED_EC_HLCL, if (rc >= 0)
led * led_exp_hlcl[ledstatus]); rc = ec_write(TPACPI_LED_EC_HLCL,
break; (ledstatus != TPACPI_LED_OFF) << led);
break;
case TPACPI_LED_NEW: case TPACPI_LED_NEW:
/* all others */ /* all others */
if (!acpi_evalf(led_handle, NULL, NULL, "vdd", if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
led, led_led_arg1[ledstatus])) led, led_led_arg1[ledstatus]))
rc = -EIO; rc = -EIO;
break; break;
default: default:
rc = -ENXIO; rc = -ENXIO;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册