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: <YoHf6Z4HTfh4Y+bn@google.com>
Date:   Sun, 15 May 2022 22:23:53 -0700
From:   Dmitry Torokhov <dmitry.torokhov@...il.com>
To:     Mattijs Korpershoek <mkorpershoek@...libre.com>
Cc:     Matthias Brugger <matthias.bgg@...il.com>,
        AngeloGioacchino Del Regno 
        <angelogioacchino.delregno@...labora.com>,
        Kevin Hilman <khilman@...libre.com>,
        Fabien Parent <fparent@...libre.com>,
        linux-input@...r.kernel.org, linux-mediatek@...ts.infradead.org,
        linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org
Subject: Re: [RESEND PATCH 1/2] Input: mt6779-keypad - fix hardware code
 mapping

On Fri, May 13, 2022 at 05:18:44PM +0200, Mattijs Korpershoek wrote:
> In mt6779_keypad_irq_handler(), we
> 1. Read a hardware code from KPD_MEM1 -> KPD_MEM5
> 2. Use that hardware code to compute columns/rows for the standard
>    keyboard matrix.
> 
> According to the (non-public) datasheet, the
> map between the hardware code and the cols/rows is:
> 
>         |(0)  |(1)  |(2)
>     ----*-----*-----*-----
>         |     |     |
>         |(9)  |(10) |(11)
>     ----*-----*-----*-----
>         |     |     |
>         |(18) |(19) |(20)
>     ----*-----*-----*-----
>         |     |     |
> 
> This brings us to another formula:
> -> row = code / 9;
> -> col = code % 3;

What if there are more than 3 columns?

> 
> Implement this mapping in bitnr_to_col_row() to fetch the
> correct input event from keypad->input_dev->keycode and report that
> back to userspace.
> 
> Fixes: f28af984e771 ("Input: mt6779-keypad - add MediaTek keypad driver")
> Co-developed-by: Fabien Parent <fparent@...libre.com>
> Signed-off-by: Fabien Parent <fparent@...libre.com>
> Signed-off-by: Mattijs Korpershoek <mkorpershoek@...libre.com>
> ---
>  drivers/input/keyboard/mt6779-keypad.c | 16 ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/input/keyboard/mt6779-keypad.c b/drivers/input/keyboard/mt6779-keypad.c
> index 2e7c9187c10f..23360de20da5 100644
> --- a/drivers/input/keyboard/mt6779-keypad.c
> +++ b/drivers/input/keyboard/mt6779-keypad.c
> @@ -36,6 +36,19 @@ static const struct regmap_config mt6779_keypad_regmap_cfg = {
>  	.max_register = 36,
>  };
>  
> +/*
> + * | hardware key code | col0 | col1 | col2|
> + * | ----------------- | -----| ---- | --- |
> + * | row0              | 0    | 1    | 2   |
> + * | row1              | 9    | 10   | 11  |
> + * | row2              | 18   | 19   | 20  |
> + */
> +static void bitnr_to_col_row(int bit_nr, int *col, int *row)
> +{
> +	*row = bit_nr / 9;
> +	*col = bit_nr % 3;
> +}
> +
>  static irqreturn_t mt6779_keypad_irq_handler(int irq, void *dev_id)
>  {
>  	struct mt6779_keypad *keypad = dev_id;
> @@ -61,8 +74,7 @@ static irqreturn_t mt6779_keypad_irq_handler(int irq, void *dev_id)
>  		if (bit_nr % 32 >= 16)
>  			continue;
>  
> -		row = bit_nr / 32;
> -		col = bit_nr % 32;
> +		bitnr_to_col_row(bit_nr, &col, &row);
>  		scancode = MATRIX_SCAN_CODE(row, col, row_shift);
>  		/* 1: not pressed, 0: pressed */
>  		pressed = !test_bit(bit_nr, new_state);
> -- 
> 2.32.0
> 

-- 
Dmitry

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ