• Richard Kjerstadius's avatar
    Input: cyttsp5 - fix bitmask for touch buttons · 04249314
    Richard Kjerstadius authored
    Prior to this patch, the bitmask ends up being 0x3, as opposed to 0x1
    which likely was the intention. The erroneous bit results in the driver
    reporting 2 different button activations in designs with 2 or more
    buttons.
    
    To detect which button has been pressed, cyttsp5_btn_attention() uses a
    for loop to iterate through the input buffer, while shifting and
    applying a bitmask to determine the state for each button.
    Unfortunately, when the bitmask is 0x3 and there are multiple buttons,
    this procedure falls apart.
    
    Consider a design with 3 buttons. Pressing the third button will result
    in a call to cyttsp5_btn_attention() with the input buffer containing
    0x4 (binary 0100). In the first iteration of the for loop cur_btn_state
    will be:
    
    (0x4 >> 0 * 1) & 0x3 = 0x4 & 0x3 = 0x0
    
    This is correct. However, in the next iteration this happens:
    
    (0x4 >> 1 * 1) & 0x3 = 0x2 & 0x3 = 0x2
    
    Which means that a key event for key 1 is generated, even though it's
    not really active. In the third iteration, the loop detects the button
    that was actually pressed:
    
    (0x4 >> 2 * 1) & 0x3 = 0x1 & 0x3 = 0x1
    
    This key event is the only one that should have been detected, but it is
    accompanied by the preceding key. Ensuring the applied mask is 0x1
    solves this problem.
    Signed-off-by: default avatarRichard Kjerstadius <richard.kjerstadius@teledyne.com>
    Reviewed-by: default avatarAlistair Francis <alistair@alistair23.me>
    Link: https://lore.kernel.org/r/20230127102903.3317089-1-richard.kjerstadius@teledyne.comSigned-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
    04249314
cyttsp5.c 22.3 KB