All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Pali Rohár" <pali.rohar@gmail.com>
To: "Michał Kępień" <kernel@kempniu.pl>
Cc: Matthew Garrett <mjg59@srcf.ucam.org>,
	Darren Hart <dvhart@infradead.org>,
	Gabriele Mazzotta <gabriele.mzt@gmail.com>,
	Mario Limonciello <mario_limonciello@dell.com>,
	Andy Lutomirski <luto@kernel.org>,
	Alex Hung <alex.hung@canonical.com>,
	platform-driver-x86@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 4/4] dell-wmi: Rework code for generating sparse keymap and processing WMI events
Date: Wed, 8 Jun 2016 00:30:11 +0200	[thread overview]
Message-ID: <20160607223011.GP29844@pali> (raw)
In-Reply-To: <20160602104211.GC2456@eudyptula.hq.kempniu.pl>

On Thursday 02 June 2016 12:42:11 Michał Kępień wrote:
> > -static void dell_wmi_process_key(int reported_key)
> > +static void dell_wmi_process_key(int type, int code)
> >  {
> >  	const struct key_entry *key;
> >  
> >  	key = sparse_keymap_entry_from_scancode(dell_wmi_input_dev,
> > -						reported_key);
> > +						(type << 16) | code);
> >  	if (!key) {
> > -		pr_info("Unknown key with scancode 0x%x pressed\n",
> > -			reported_key);
> > +		pr_info("Unknown key with type 0x%x and code 0x%x pressed\n",
> > +			type, code);
> 
> Since you updated the switch cases below so that each of them now
> consists of four digits, maybe it's a good idea to change the format
> specifiers for type and code to %04x for coherency?

Ok.

> >  		return;
> >  	}
> >  
> > -	pr_debug("Key %x pressed\n", reported_key);
> > +	pr_debug("Key with type 0x%x and code 0x%x pressed\n", type, code);
> 
> The same applies here.

Ok.

> > +		case 0x0000:
> > +			/* One key pressed or event occurred */
> > +			if (len > 2)
> > +				dell_wmi_process_key(0x0000, buffer_entry[2]);
> 
> I am sure you spent way more time analysing this than me, but is this
> documented anywhere?

Yes, this is the only documented part. Read my email linked to commit
message for more details.

> Technically speaking, this is a behavioral change
> which causes events to be lost on any Dell model which is capable of
> stuffing more than one key code into a single type 0x0000 WMI event (not
> that I know of any such model).

I do not think. Other values in that buffer are not scan codes of other
keys, but additional events. See that table with comments (those
comments which you suggested to change).

> > +			/* Other entries in buffer could contain additional information */
> 
> This comment exceeds 80 characters, but do you think it is needed at
> all?  What does the reader gain by reading it?  Any additional
> information that follows the key code is ignored by kernel code anyway.

It is just documentation purpose, to understand why we are processing
only buffer_entry[2] and why are ignoring anything else after it.

> >  			break;

> > @@ -576,21 +525,71 @@ static int __init dell_wmi_input_setup(void)
> >  		goto err_free_dev;
> >  	}
> >  
> > +	keymap = kcalloc(dmi_results.keymap_size +
> > +			 ARRAY_SIZE(dell_wmi_keymap_type_0000) +
> > +			 ARRAY_SIZE(dell_wmi_keymap_type_0010) +
> > +			 ARRAY_SIZE(dell_wmi_keymap_type_0011) +
> > +			 1,
> > +			 sizeof(struct key_entry), GFP_KERNEL);
> > +	if (!keymap) {
> > +		err = -ENOMEM;
> > +		goto err_free_dev;
> 
> You're potentially leaking dmi_results.keymap here.

You are right, I will fix it.

> > +	}
> > +
> > +	/* Append table with events of type 0x0010 which comes from DMI */
> >  	if (dmi_results.keymap) {
> > -		dell_new_hk_type = true;
> > +		for (i = 0; i < dmi_results.keymap_size; i++) {
> > +			keymap[pos] = dmi_results.keymap[i];
> > +			keymap[pos].code |= (0x0010 << 16);
> > +			pos++;
> > +		}
> > +		kfree(dmi_results.keymap);
> > +	}
> 
> Nit, but is the enclosing conditional expression needed any more, now
> that you got rid of dell_new_hk_type?  If the 0xB2 DMI table is not
> found then dmi_results.keymap_size will be 0 and thus the for loop above
> doesn't do anything and it is okay to pass a null pointer to kfree().

Yes, it is not needed anymore. I will delete it.

> >  
> > -		err = sparse_keymap_setup(dell_wmi_input_dev,
> > -					  dmi_results.keymap, NULL);
> > +	/* Append table with extra events of type 0x0010 which are not in DMI */
> > +	for (i = 0; i < ARRAY_SIZE(dell_wmi_keymap_type_0010); i++) {
> > +		const struct key_entry *entry = &dell_wmi_keymap_type_0010[i];
> >  
> >  		/*
> > -		 * Sparse keymap library makes a copy of keymap so we
> > -		 * don't need the original one that was allocated.
> > +		 * Check if we've already found this scancode.  This takes
> > +		 * quadratic time, but it doesn't matter unless the list
> > +		 * of extra keys gets very long.
> >  		 */
> > -		kfree(dmi_results.keymap);
> > -	} else {
> > -		err = sparse_keymap_setup(dell_wmi_input_dev,
> > -					  dell_wmi_legacy_keymap, NULL);
> > +		if (dmi_results.keymap_size &&
> > +		    have_scancode(entry->code | (0x0010 << 16),
> > +				  keymap, dmi_results.keymap_size)
> > +		   )
> > +			continue;
> 
> Is the first part of this conditional expression really needed?  If
> dmi_results.keymap_size is 0 then have_scancode() will simply return
> false, so the only disadvantage of removing this check is the overhead
> of calling have_scancode() for every iteration of the loop, but I
> believe that overhead is negligible as this is not performance-critical
> code.

It is linear scan of whole table and so above two loops has something
like quadratic time complexity. List dell_wmi_keymap_type_0010 is not
too long for now, so it is OK. But still it is better not to call
have_scancode() everytime if it is not needed. Once we have big list of
events we could switch code to use some hash tables...

-- 
Pali Rohár
pali.rohar@gmail.com

  reply	other threads:[~2016-06-07 22:30 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-22 11:36 [PATCH 0/4] dell-wmi: Changes in WMI event code handling Pali Rohár
2016-05-22 11:36 ` [PATCH 1/4] dell-wmi: Ignore WMI event code 0xe045 Pali Rohár
2016-05-22 11:36   ` Pali Rohár
2016-05-22 11:36 ` [PATCH 2/4] dell-wmi: Sort WMI event codes and update comments Pali Rohár
2016-06-02 10:41   ` Michał Kępień
2016-06-07 22:03     ` Pali Rohár
2016-06-08 19:48       ` Darren Hart
2016-06-08 19:57         ` Pali Rohár
2016-06-08 20:15           ` Darren Hart
2016-06-08 20:15             ` Darren Hart
2016-06-08 20:27             ` Pali Rohár
2016-06-08 20:43               ` Darren Hart
2016-06-08 20:49                 ` Pali Rohár
2016-05-22 11:36 ` [PATCH 3/4] dell-wmi: Add information about other WMI event codes Pali Rohár
2016-05-26 22:04   ` Gabriele Mazzotta
2016-06-07 23:00     ` Pali Rohár
2016-06-07 23:00       ` Pali Rohár
2016-06-08  6:02       ` Mario_Limonciello
2016-06-08  6:02         ` Mario_Limonciello
2016-06-08 10:44         ` Gabriele Mazzotta
2016-06-15 19:51           ` Pali Rohár
2016-06-21 19:51             ` Mario_Limonciello
2016-06-21 19:51               ` Mario_Limonciello
2016-06-22  7:56               ` Pali Rohár
2016-06-22 13:40                 ` Mario_Limonciello
2016-06-22 13:40                   ` Mario_Limonciello
2016-06-22 14:12                   ` Pali Rohár
2016-06-22 14:21                     ` Mario_Limonciello
2016-06-22 14:21                       ` Mario_Limonciello
2016-06-22 14:24                       ` Pali Rohár
2016-06-22 14:28                         ` Mario_Limonciello
2016-06-22 14:28                           ` Mario_Limonciello
2016-06-22 14:31                           ` Pali Rohár
2016-06-22 14:34                             ` Mario_Limonciello
2016-06-22 14:34                               ` Mario_Limonciello
2016-06-22 14:38                               ` Pali Rohár
2016-06-22 14:39                       ` Gabriele Mazzotta
2016-06-22 14:46                         ` Mario_Limonciello
2016-06-22 14:46                           ` Mario_Limonciello
2016-06-02 10:41   ` Michał Kępień
2016-06-07 22:06     ` Pali Rohár
2016-05-22 11:36 ` [PATCH 4/4] dell-wmi: Rework code for generating sparse keymap and processing WMI events Pali Rohár
2016-05-23 17:07   ` Andy Lutomirski
2016-06-02 10:42   ` Michał Kępień
2016-06-07 22:30     ` Pali Rohár [this message]
2016-06-02 10:52 ` [PATCH 0/4] dell-wmi: Changes in WMI event code handling Michał Kępień

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=20160607223011.GP29844@pali \
    --to=pali.rohar@gmail.com \
    --cc=alex.hung@canonical.com \
    --cc=dvhart@infradead.org \
    --cc=gabriele.mzt@gmail.com \
    --cc=kernel@kempniu.pl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mario_limonciello@dell.com \
    --cc=mjg59@srcf.ucam.org \
    --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.