linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: Paul Cercueil <paul@crapouillou.net>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Peter Hutterer <peter.hutterer@who-t.net>,
	Chris Morgan <macroalpha82@gmail.com>,
	linux-input@vger.kernel.org, svv@google.com,
	biswarupp@google.com, contact@artur-rojek.eu,
	Chris Morgan <macromorgan@hotmail.com>
Subject: Re: [PATCH] input: uinput: Drop checks for abs_min > abs_max
Date: Sat, 23 Dec 2023 15:29:09 +0100	[thread overview]
Message-ID: <954f6537-15d5-42db-94b5-d148d4942870@redhat.com> (raw)
In-Reply-To: <4e902e8ff60e21a74a87887e272f6751d3837c71.camel@crapouillou.net>

Hi Paul,

On 12/20/23 14:39, Paul Cercueil wrote:
> Hi Dmitry,
> 
> Le mardi 19 décembre 2023 à 17:53 -0800, Dmitry Torokhov a écrit :
>> Hi Paul,
>>
>> On Wed, Dec 20, 2023 at 01:38:39AM +0100, Paul Cercueil wrote:
>>> Hi Peter,
>>>
>>> Le mercredi 20 décembre 2023 à 09:51 +1000, Peter Hutterer a
>>> écrit :
>>>> On Mon, Dec 18, 2023 at 11:16:53AM -0600, Chris Morgan wrote:
>>>>> From: Chris Morgan <macromorgan@hotmail.com>
>>>>>
>>>>> Stop checking if the minimum abs value is greater than the
>>>>> maximum
>>>>> abs
>>>>> value. When the axis is inverted this condition is allowed.
>>>>> Without
>>>>> relaxing this check, it is not possible to use uinput on
>>>>> devices in
>>>>> userspace with an inverted axis, such as the adc-joystick found
>>>>> on
>>>>> many handheld gaming devices.
>>>>
>>>> As mentioned in the other thread [1] a fair bit of userspace
>>>> relies
>>>> on
>>>> that general assumption so removing it will likely cause all
>>>> sorts of
>>>> issues.
>>>
>>> There is some userspace that works with it though, so why restrict
>>> it
>>> artificially?
>>>
>>> The fact that some other userspace code wouldn't work with it
>>> sounds a
>>> bit irrelevant. They just never encountered that min>max usage
>>> before.
>>>
>>> And removing this check won't cause all sort of issues, why would
>>> it?
>>> It's not like the current software actively probes min>max and
>>> crash
>>> badly if it doesn't return -EINVAL...
>>
>> It will cause weird movements because calculations expect min be the
>> minimum, and max the maximum, and not encode left/right or up/down.
>> Putting this into adc joystick binding was a mistake.
> 
> I don't see why it was a mistake, it's only one of the ways to specify
> that the axis is inverted. This information is between the firmware
> (DT) and the kernel, that doesn't mean the information has to be
> relayed as-is to the userspace.
> 
> Unlike what you wrote in your other answer, when talking about input
> the kernel doesn't really normalize anything - it gives you the min/max
> values, and the raw samples, not normalized samples (they don't get
> translated to a pre-specified range, or even clamped).
> 
> I don't really like the idea of having the driver tamper with the
> samples, but if the specification really is that max>min, then it would
> be up to evdev/joydev (if the individual drivers are allowed min>max)
> or adc-joystick (if they are not) to process the samples.

I don't see why a driver, especially a userspace driver which
then injects things back into the kernel using uinput, would
not take care of inverting the samples itself and then just
present userspace with normalized data where min is simply 0
(as result of normalization as part of inversion) and
max is (original_max - original_min).

Note that this is exactly what is being done for touchscreens,
where having the touchscreen mounted e.g. upside-down is
a long standing issue and this is thus also a long solved issue,
see: drivers/input/touchscreen.c which contains generic
code for parsing device-properties including swapped / inverted
axis as well as generic code for reporting the position to the
input core, where the helpers from drivers/input/touchscreen.c
take care of the swap + invert including normalization when
doing inversion.

Specifically this contains in touchscreen_parse_properties() :

        prop->max_x = input_abs_get_max(input, axis_x);
        prop->max_y = input_abs_get_max(input, axis_y);

        if (prop->invert_x) {
                absinfo = &input->absinfo[axis_x];
                absinfo->maximum -= absinfo->minimum;
                absinfo->minimum = 0;
        }

        if (prop->invert_y) {
                absinfo = &input->absinfo[axis_y];
                absinfo->maximum -= absinfo->minimum;
                absinfo->minimum = 0;
        }

and then when reporting touches:

void touchscreen_report_pos(struct input_dev *input,
                            const struct touchscreen_properties *prop,
                            unsigned int x, unsigned int y,
                            bool multitouch)
{
        if (prop->invert_x)
                x = prop->max_x - x;

        if (prop->invert_y)
                y = prop->max_y - y;

        if (prop->swap_x_y)
                swap(x, y);

        input_report_abs(input, multitouch ? ABS_MT_POSITION_X : ABS_X, x);
        input_report_abs(input, multitouch ? ABS_MT_POSITION_Y : ABS_Y, y);
}

One of the tasks of a driver / the kernel is to provide some
level of hardware abstraction to isolate userspace from
hw details. IMHO taking care of the axis-inversion for userspace
with something like the above is part of the kernels' HAL task.

Regards,

Hans




  parent reply	other threads:[~2023-12-23 14:29 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-18 17:16 [PATCH] input: uinput: Drop checks for abs_min > abs_max Chris Morgan
2023-12-19 23:51 ` Peter Hutterer
2023-12-20  0:38   ` Paul Cercueil
2023-12-20  1:53     ` Dmitry Torokhov
2023-12-20 13:39       ` Paul Cercueil
2023-12-22 17:09         ` Chris Morgan
2024-01-03 23:22           ` Peter Hutterer
2023-12-23 14:29         ` Hans de Goede [this message]
2023-12-23 15:01           ` Paul Cercueil
2023-12-23 15:16             ` Hans de Goede
2023-12-24  8:03               ` Dmitry Torokhov
2023-12-30  5:32                 ` Chris Morgan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=954f6537-15d5-42db-94b5-d148d4942870@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=biswarupp@google.com \
    --cc=contact@artur-rojek.eu \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=macroalpha82@gmail.com \
    --cc=macromorgan@hotmail.com \
    --cc=paul@crapouillou.net \
    --cc=peter.hutterer@who-t.net \
    --cc=svv@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).