Re: [PATCH V2 6/7] platform/x86: lg-laptop.c: Expose reader mode as a LED, rather than a sysfs file for 2018 and newer models

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Nov 30, 2019 at 10:53 AM Matan Ziv-Av <matan@xxxxxxxxxxx> wrote:
>
> On 2018 and newer models, setting reader mode does not change display
> Gamma, so treat reader mode as a LED, instead of a switch.

> +static void reader_mode_led_set(struct led_classdev *cdev,
> +                               enum led_brightness brightness)
> +{
> +       reader_mode_store(NULL, NULL, brightness == LED_OFF ? "0" : "1", 1);
> +}
> +
> +static enum led_brightness reader_mode_led_get(struct led_classdev *cdev)
> +{
> +       char buf[BUFFER_SIZE];
> +
> +       reader_mode_show(NULL, NULL, buf);
> +       return buf[0] != '0';
> +}

Ah, I see not. No, this is abusing the API. Please, don't do like this.
If you need a common code, split it out to a helper function(s) and
re-use in both.

>         if (inited & INIT_TPAD_LED)
>                 led_classdev_unregister(&tpad_led);
>
> +       if (inited & INIT_RDMODE_LED)
> +               led_classdev_unregister(&reader_mode_led);

LED framework is protected against NULL or ERR pointer values in the
device, so this and actually above check are not needed anymore.

See the commit 1dbb9fb4082c for the details.

-- 
With Best Regards,
Andy Shevchenko



[Index of Archives]     [Linux Kernel Development]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux