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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <152d15c4-10bb-45fe-9b9c-b323535a921f@gmail.com>
Date:   Wed, 1 Nov 2023 09:50:36 +0530
From:   Anshul Dalal <anshulusr@...il.com>
To:     Thomas Weißschuh <thomas@...ch.de>
Cc:     Thomas Weißschuh <linux@...ssschuh.net>,
        linux-input@...r.kernel.org, devicetree@...r.kernel.org,
        Dmitry Torokhov <dmitry.torokhov@...il.com>,
        Rob Herring <robh+dt@...nel.org>,
        Krzysztof Kozlowski <krzysztof.kozlowski+dt@...aro.org>,
        Conor Dooley <conor+dt@...nel.org>,
        Jeff LaBundy <jeff@...undy.com>,
        Shuah Khan <skhan@...uxfoundation.org>,
        linux-kernel-mentees@...ts.linuxfoundation.org,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH v6 2/2] input: joystick: driver for Adafruit Seesaw
 Gamepad

On 10/31/23 07:53, Thomas Weißschuh wrote:
> Oct 31, 2023 03:10:50 Anshul Dalal <anshulusr@...il.com>:
> 
>> Hello Thomas,
>>
>> Thanks for the review! The requested changes will be addressed in the
>> next patch version though I had a few comments below:
>>
>> On 10/27/23 11:44, Thomas Weißschuh wrote:
>>> Hi Anshul,
>>>
>>> thanks for the reworks!
>>>
>>> Some more comments inline.
>>>
>>> On 2023-10-27 10:48:11+0530, Anshul Dalal wrote:
> 
> [..]
> 
>>>> +struct seesaw_button_description {
>>>> +   unsigned int code;
>>>> +   unsigned int bit;
>>>> +};
>>>> +
>>>> +static const struct seesaw_button_description seesaw_buttons[] = {
>>>> +   {
>>>> +       .code = BTN_EAST,
>>>> +       .bit = SEESAW_BUTTON_A,
>>>> +   },
>>>> +   {
>>>> +       .code = BTN_SOUTH,
>>>> +       .bit = SEESAW_BUTTON_B,
>>>> +   },
>>>> +   {
>>>> +       .code = BTN_NORTH,
>>>> +       .bit = SEESAW_BUTTON_X,
>>>> +   },
>>>> +   {
>>>> +       .code = BTN_WEST,
>>>> +       .bit = SEESAW_BUTTON_Y,
>>>> +   },
>>>> +   {
>>>> +       .code = BTN_START,
>>>> +       .bit = SEESAW_BUTTON_START,
>>>> +   },
>>>> +   {
>>>> +       .code = BTN_SELECT,
>>>> +       .bit = SEESAW_BUTTON_SELECT,
>>>> +   },
>>>> +};
>>>
>>> This looks very much like a sparse keymap which can be implemented with
>>> the helpers from <linux/input/sparse-keymap.h>.
>>>
>>
>> When going through the API provided by sparse-keymap, I could only see
>> the use for sparse_keymap_report_entry here. Which leads to the
>> following refactored code:
>>
>> static const struct key_entry seesaw_buttons_new[] = {
>>     {KE_KEY, SEESAW_BUTTON_A, {BTN_SOUTH}},
>>     {KE_KEY, SEESAW_BUTTON_B, {BTN_EAST}},
> 
> No braces I think.
> 

Since the last field in key_entry is a union, the braces seem to be
required.

>>     ...
>> };
>>
>> for (i = 0; i < ARRAY_SIZE(seesaw_buttons_new); i++) {
>>     sparse_keymap_report_entry(input, &seesaw_buttons_new[i],
>>         data.button_state & BIT(seesaw_buttons_new[i].code),
>>         false);
>> }
>>
>> I don't think this significantly improves the code unless you had some
>> other way to use the API in mind.
> 
> I thought about sparse_keymap_setup() and sparse_keymap_report_event().
> 
> It does not significantly change the code but would be a standard API.
> 

Thanks for pointing me in the right direction, do you think the
following implementation of the API is acceptable for the driver. Since
I couldn't find a driver for any similar device using the API in this
manner.

inside seesaw_probe():

err = sparse_keymap_setup(seesaw->input_dev, seesaw_buttons_new, NULL);
if (err) {
	dev_err(&client->dev,
		"failed to set up input device keymap: %d\n", err);
	return err;
}

inside seesaw_poll():

for (i = 0; i < ARRAY_SIZE(seesaw_buttons_new); i++) {
	if (!sparse_keymap_report_event(
		input, seesaw_buttons_new[i].code,
		data.button_state & BIT(seesaw_buttons_new[i].code),
		false)) {
		dev_err_ratelimited(
			&input->dev,
			"failed to report event for keycode: %d",
			seesaw_buttons_new[i].keycode);
		return;
	}
}

> Thomas

Best regards,
Anshul

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ