lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Sat, 6 Aug 2022 11:56:58 +0200
From:   Andy Shevchenko <andy.shevchenko@...il.com>
To:     "Luke D. Jones" <luke@...nes.dev>
Cc:     Hans de Goede <hdegoede@...hat.com>,
        Mark Gross <markgross@...nel.org>,
        Platform Driver <platform-driver-x86@...r.kernel.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 2/5] asus-wmi: Add support for TUF laptop keyboard RGB
 mode control

On Fri, Aug 5, 2022 at 10:20 AM Luke D. Jones <luke@...nes.dev> wrote:
>
> Adds support for TUF laptop RGB mode control.
>
> Two paths are added:
> - /sys/devices/platform/asus-nb-wmi/kernel_rgb_mode
> - /sys/devices/platform/asus-nb-wmi/kernel_rgb_mode_index

...

> +static int keyboard_rgb_mode_check_present(struct asus_wmi *asus)
> +{
> +       u32 result;
> +       int err;
> +
> +       asus->keyboard_rgb_mode_available = false;
> +
> +       err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_TUF_RGB_MODE, &result);
> +       if (err) {
> +               if (err == -ENODEV)
> +                       return 0;
> +               return err;
> +       }

> +       if (result & ASUS_WMI_DSTS_PRESENCE_BIT) {
> +               asus->keyboard_rgb_mode_available = true;
> +       }

{} are not needed (except if they will be utilized in the next patches
in the series).

> +       return 0;
> +}

...

> +       if (sscanf(buf, "%hhd %hhd %hhd", &save, &mode, &speed) != 3)
> +               return -EINVAL;

Usually we have three separate nodes for that, but they are kinda
hidden in one driver, so I don't care much.

...

> +       asus->keyboard_rgb_mode.save = save > 0 ? 1 : 0;

So, it's actually boolean.

You may write it as

    ...save = !!save;

> +       /* These are the known usable modes across all TUF/ROG */
> +       asus->keyboard_rgb_mode.mode = mode < 12 && mode != 9 ? mode : 0x0a;
> +
> +       if (speed == 0)
> +               asus->keyboard_rgb_mode.speed = 0xe1;
> +       else if (speed == 1)
> +               asus->keyboard_rgb_mode.speed = 0xeb;
> +       else if (speed == 2)
> +               asus->keyboard_rgb_mode.speed = 0xf5;

> +       else
> +               asus->keyboard_rgb_mode.speed = 0xeb;

So the 1 is default then, why not use switch-case to show this explicitly?

switch (speed) {
  case 0:
    ...
  break;
  case 1:
  default:
    ...
  break;
  case 2:
    ...
  break;
}

Yes, it's longer, but I think it's cleaner.

> +       err = tuf_rgb_brightness_set(cdev, cdev->brightness);
> +       if (err)
> +               return err;
> +       return 0;

return tuf_rgb_brightness_set(...);

> +}

-- 
With Best Regards,
Andy Shevchenko

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ