Re: [PATCH 1/3] thinkpad_acpi: return -NODEV while operating uninitialized LEDs

Bjørn Mork
2013-06-07T08:54:25Z

Adam Lee <adam.lee@canonical.com> writes:

> --- a/drivers/platform/x86/thinkpad_acpi.c
> +++ b/drivers/platform/x86/thinkpad_acpi.c
> @@ -5401,9 +5401,12 @@ static int led_write(char *buf)
> return -ENODEV;
>
> while ((cmd = next_cmd(&buf))) {
> - if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 15)
> + if (sscanf(cmd, "%d", &led) != 1)
> return -EINVAL;
>
> + if (!tpacpi_leds[led].led)
> + return -ENODEV;

This looks risky. Why did you remove the index sanity check? What will
happen now if the input is e.g "-1" or "42"?

BTW, the magic number 15 should probably be (TPACPI_LED_NUMLEDS - 1)
instead.

Bjørn