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]
Message-ID: <20230211022342.7xyvd3qsa42lwrkq@t-8ch.de>
Date:   Sat, 11 Feb 2023 02:23:42 +0000
From:   Thomas Weißschuh <thomas@...ch.de>
To:     Orlando Chamberlain <orlandoch.dev@...il.com>
Cc:     Aditya Garg <gargaditya08@...e.com>,
        Jiri Kosina <jikos@...nel.org>,
        "jkosina@...e.cz" <jkosina@...e.cz>,
        "benjamin.tissoires@...hat.com" <benjamin.tissoires@...hat.com>,
        Andy Shevchenko <andy@...radead.org>,
        "andy.shevchenko@...il.com" <andy.shevchenko@...il.com>,
        LKML <linux-kernel@...r.kernel.org>,
        "linux-input@...r.kernel.org" <linux-input@...r.kernel.org>,
        "ronald@...ovation.ch" <ronald@...ovation.ch>,
        "kekrby@...il.com" <kekrby@...il.com>
Subject: Re: [PATCH 3/3] HID: apple-magic-backlight: Add driver for keyboard
 backlight on internal Magic Keyboards

On Sat, Feb 11, 2023 at 10:24:25AM +1100, Orlando Chamberlain wrote:
> On Fri, 10 Feb 2023 16:25:18 +0000
> Thomas Weißschuh <thomas@...ch.de> wrote:
> 
> > On Fri, Feb 10, 2023 at 03:45:15AM +0000, Aditya Garg wrote:
> > > From: Orlando Chamberlain <orlandoch.dev@...il.com>
> > > +static void apple_magic_backlight_power_set(struct
> > > apple_magic_backlight *backlight,
> > > +					   char power, char rate)
> > > +{
> > > +	struct hid_report *rep = backlight->power;
> > > +
> > > +	rep->field[0]->value[0] = power ? 1 : 0;
> > > +	rep->field[1]->value[0] = 0x5e; /* Mimic Windows */
> > > +	rep->field[1]->value[0] |= rate << 8;
> > > +
> > > +	hid_hw_request(backlight->hdev, backlight->power,
> > > HID_REQ_SET_REPORT); +}
> > > +
> > > +static void apple_magic_backlight_brightness_set(struct
> > > apple_magic_backlight *backlight,
> > > +						int brightness,
> > > char rate) +{
> > > +	struct hid_report *rep = backlight->brightness;
> > > +
> > > +	rep->field[0]->value[0] = brightness;
> > > +	rep->field[1]->value[0] = 0x5e; /* Mimic Windows */
> > > +	rep->field[1]->value[0] |= rate << 8;
> > > +
> > > +	hid_hw_request(backlight->hdev, backlight->brightness,
> > > HID_REQ_SET_REPORT);
> > > +  
> > 
> > The two functions above are nearly identical.
> 
> They are indeed quite similar, and I can turn the backlight off with the
> brightness one, but when I logged the usb packets Windows used, it used
> both so I've done the same in the Linux driver to (hopefully) ensure it
> works with any other models or firmware updates that the Windows driver
> works on.

I didn't mean to suggest changing the logic, just the way the code is
organized:

static void apple_magic_backlight_report_set(struct apple_magic_backlight *backlight,
                                             struct hid_report *rep, char value, char rate)
{
	rep->field[0]->value[0] = value;
	rep->field[1]->value[0] = 0x5e; /* Mimic Windows */
	rep->field[1]->value[0] |= rate << 8;

	hid_hw_request(backlight->hdev, rep, HID_REQ_SET_REPORT);
}

static void apple_magic_backlight_set(struct apple_magic_backlight *backlight,
				     int brightness, char rate)
{
	apple_magic_backlight_report_set(backlight, backlight->power, !!brightness, rate);
	if (brightness)
		apple_magic_backlight_report_set(backlight, backlight->brightness, brightness, rate);
}

This way you can get rid of the duplicated code.

> > 
> > > +
> > > +static void apple_magic_backlight_set(struct apple_magic_backlight
> > > *backlight,
> > > +				     int brightness, char rate)
> > > +{
> > > +	apple_magic_backlight_power_set(backlight, brightness,
> > > rate);
> > > +	if (brightness)
> > > +		apple_magic_backlight_brightness_set(backlight,
> > > brightness, rate); +}
> > > +

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ