From: Anisse Astier <anisse@astier.eu>
To: Maxim Mikityanskiy <maxtram95@gmail.com>
Cc: "platform-driver-x86@vger.kernel.org"
<platform-driver-x86@vger.kernel.org>, joeyli <jlee@suse.com>,
Dmitry Torokhov <dmitry.torokhov@gmail.com>
Subject: Re: [PATCH v3 11/12] msi-wmi: Introduced quirk_last_pressed
Date: Wed, 12 Dec 2012 10:58:29 +0100 [thread overview]
Message-ID: <20121212105829.15819617@destiny.ordissimo> (raw)
In-Reply-To: <CAKErNvqxMiKQaXmLhKt4HOMnLNic_LHayaQKrsnyKH6WZ45Siw@mail.gmail.com>
On Tue, 11 Dec 2012 20:27:26 +0200, Maxim Mikityanskiy <maxtram95@gmail.com> wrote :
> 2012/12/11 Anisse Astier <anisse@astier.eu>:
> > On Tue, 11 Dec 2012 19:07:51 +0200, Maxim Mikityanskiy <maxtram95@gmail.com> wrote :
> >
> >> >> @@ -169,11 +169,15 @@ static void msi_wmi_notify(u32 value, void *context)
> >> >> pr_debug("Eventcode: 0x%x\n", eventcode);
> >> >> key = sparse_keymap_entry_from_scancode(msi_wmi_input_dev,
> >> >> eventcode);
> >> >> - if (key) {
> >> >> + if (!key) {
> >> >> + pr_info("Unknown key pressed - %x\n", eventcode);
> >> >> + goto msi_wmi_notify_exit;
> >> >> + }
> >> >> + if (quirk_last_pressed) {
> >> >> + size_t key_index = key - msi_wmi_keymap;
> >> > Do you mean key->code - MSI_SCANCODE_BASE ? I'm not sure I understand the
> >> > intent here otherwise.
> >>
> >> msi_wmi_keymap is array of 'struct key_entry', i.e. pointer to array's
> >> first item. key is a pointer to some array's item. So 'key -
> >> msi_wmi_keymap' is a difference between pointers, i.e. index of key in
> >> msi_wmi_keymap.
> >>
> >> I do pointer arithmetic here because in patch 12 I add some new
> >> scancodes, and holes appear in scancode sequence, so we can't just use
> >> 'key->code - MSI_SCANCODE_BASE' to get item index in array.
> >
> > Oh, I see. This is very clever, but a bit too clever. You have no
> > guarantee, that sparse_keymap_entry_from_scancode will give you a pointer
> > to *your* key_entry. In fact, it doesn't.
> >
> > In sparse_keymap_setup (drivers/input/sparse-keymap.c), the keymap
> > array(msi_wmi_keymap) is mempcy-ed, at line 187 (kernel ~3.7). So if you
> > want to use this method, you might need to re-compute the index by
> > iterating over the elements and comparing key->code for each.
>
> Oops, I'm sorry, I was looking only into
> sparse_keymap_entry_from_scancode() and I didn't discover the fact
> that dev->keycode is not equal to msi_wmi_keymap. I just wanted to
> avoid iterating through the array second time. Also, can I use
> msi_wmi_input_dev->keycode instead of msi_wmi_keymap as array base?
> input_dev::keycode field is documented at include/linux/input.h:62.
As I said, you could iterate over msi_wmi_keymap and compare key->code to
each keycode to compute key_index each time.
>
> It's strange that I didn't get a crash or data corruption on my system
> when I forced usage of last_pressed for my laptop, loaded this module
> and tried to press keys.
>
> It's very unconvenient that struct key_entry does not have some field
> for driver-specific extra data. In such field we could store index in
> last_pressed or event last press time. But we haven't such field.
If that's really needed, such field could be added. Cc-ing Dmitry
Torokhov to ask what he thinks about altering the sparse keymap API for
this use case, ie having per key_entry variables to store information,
here used for debouncing.
Previously the keymap was contiguous, but we're adding new keys, so it'll
really be sparse, so we can't use the same trick substraction trick.
Regards,
Anisse
next prev parent reply other threads:[~2012-12-12 9:58 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-07 13:49 [PATCH v3 00/12] Add MSI Wind U90/U100 support Maxim Mikityanskiy
2012-12-07 13:49 ` [PATCH v3 01/12] msi-laptop: Use proper return codes instead of -1 Maxim Mikityanskiy
2012-12-07 13:49 ` [PATCH v3 02/12] msi-laptop: Work around gcc warning Maxim Mikityanskiy
2012-12-07 13:49 ` [PATCH v3 03/12] msi-laptop: merge quirk tables to one Maxim Mikityanskiy
2012-12-07 13:49 ` [PATCH v3 04/12] msi-laptop: Add MSI Wind U90/U100 support Maxim Mikityanskiy
2012-12-07 13:49 ` [PATCH v3 05/12] msi-laptop: Add missing ABI documentation Maxim Mikityanskiy
2012-12-07 13:49 ` [PATCH v3 06/12] msi-laptop: Disable brightness control for new EC Maxim Mikityanskiy
2012-12-07 13:49 ` [PATCH v3 07/12] msi-wmi: Fix memory leak Maxim Mikityanskiy
2012-12-07 13:49 ` [PATCH v3 08/12] msi-wmi: Avoid repeating constants Maxim Mikityanskiy
2012-12-10 5:52 ` joeyli
2012-12-07 13:49 ` [PATCH v3 09/12] msi-wmi: Use enums for scancodes Maxim Mikityanskiy
2012-12-10 6:01 ` joeyli
2012-12-07 13:49 ` [PATCH v3 10/12] msi-wmi: Make keys and backlight independent Maxim Mikityanskiy
2012-12-07 13:49 ` [PATCH v3 11/12] msi-wmi: Introduced quirk_last_pressed Maxim Mikityanskiy
2012-12-11 16:29 ` Anisse Astier
2012-12-11 17:07 ` Maxim Mikityanskiy
2012-12-11 17:39 ` Anisse Astier
2012-12-11 18:27 ` Maxim Mikityanskiy
2012-12-12 9:58 ` Anisse Astier [this message]
2012-12-12 18:58 ` Dmitry Torokhov
2012-12-13 17:10 ` Anisse Astier
2012-12-13 18:06 ` Maxim Mikityanskiy
2012-12-13 18:18 ` Dmitry Torokhov
2012-12-13 18:30 ` Maxim Mikityanskiy
2012-12-14 10:37 ` joeyli
2012-12-14 11:13 ` Thomas Renninger
2012-12-07 13:49 ` [PATCH v3 12/12] msi-wmi: Add MSI Wind support Maxim Mikityanskiy
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=20121212105829.15819617@destiny.ordissimo \
--to=anisse@astier.eu \
--cc=dmitry.torokhov@gmail.com \
--cc=jlee@suse.com \
--cc=maxtram95@gmail.com \
--cc=platform-driver-x86@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.