Linux Input Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH resend 0/1] Input: i8042 - Allow insmod to succeed on devices without an i8042 controller
@ 2020-10-08 11:26 Hans de Goede
  2020-10-08 11:26 ` [PATCH resend] " Hans de Goede
  0 siblings, 1 reply; 3+ messages in thread
From: Hans de Goede @ 2020-10-08 11:26 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: Hans de Goede, linux-input

Hi Dmitry,

This one seems to have fallen through the cracks, hence this resend.

Regards,

Hans


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH resend] Input: i8042 - Allow insmod to succeed on devices without an i8042 controller
  2020-10-08 11:26 [PATCH resend 0/1] Input: i8042 - Allow insmod to succeed on devices without an i8042 controller Hans de Goede
@ 2020-10-08 11:26 ` Hans de Goede
  2020-10-27  3:56   ` Dmitry Torokhov
  0 siblings, 1 reply; 3+ messages in thread
From: Hans de Goede @ 2020-10-08 11:26 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: Hans de Goede, linux-input, Marius Iacob

The i8042 module exports several symbols which may be used by other
modules.

Before this commit it would refuse to load (when built as a module itself)
on systems without an i8042 controller.

This is a problem specifically for the asus-nb-wmi module. Many Asus
laptops support the Asus WMI interface. Some of them have an i8042
controller and need to use i8042_install_filter() to filter some kbd
events. Other models do not have an i8042 controller (e.g. they use an
USB attached kbd).

Before this commit the asus-nb-wmi driver could not be loaded on Asus
models without an i8042 controller, when the i8042 code was built as
a module (as Arch Linux does) because the module_init function of the
i8042 module would fail with -ENODEV and thus the i8042_install_filter
symbol could not be loaded.

This commit fixes this by exiting from module_init with a return code
of 0 if no controller is found.  It also adds a i8042_present bool to
make the module_exit function a no-op in this case and also adds a
check for i8042_present to the exported i8042_command function.

The latter i8042_present check should not really be necessary because
when builtin that function can already be used on systems without
an i8042 controller, but better safe then sorry.

Reported-and-tested-by: Marius Iacob <themariusus@gmail.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/input/serio/i8042.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/input/serio/i8042.c b/drivers/input/serio/i8042.c
index d3eda48032e3..944cbb519c6d 100644
--- a/drivers/input/serio/i8042.c
+++ b/drivers/input/serio/i8042.c
@@ -122,6 +122,7 @@ module_param_named(unmask_kbd_data, i8042_unmask_kbd_data, bool, 0600);
 MODULE_PARM_DESC(unmask_kbd_data, "Unconditional enable (may reveal sensitive data) of normally sanitize-filtered kbd data traffic debug log [pre-condition: i8042.debug=1 enabled]");
 #endif
 
+static bool i8042_present;
 static bool i8042_bypass_aux_irq_test;
 static char i8042_kbd_firmware_id[128];
 static char i8042_aux_firmware_id[128];
@@ -343,6 +344,9 @@ int i8042_command(unsigned char *param, int command)
 	unsigned long flags;
 	int retval;
 
+	if (!i8042_present)
+		return -1;
+
 	spin_lock_irqsave(&i8042_lock, flags);
 	retval = __i8042_command(param, command);
 	spin_unlock_irqrestore(&i8042_lock, flags);
@@ -1612,12 +1616,15 @@ static int __init i8042_init(void)
 
 	err = i8042_platform_init();
 	if (err)
-		return err;
+		return (err == -ENODEV) ? 0 : err;
 
 	err = i8042_controller_check();
 	if (err)
 		goto err_platform_exit;
 
+	/* Set this before creating the dev to allow i8042_command to work right away */
+	i8042_present = true;
+
 	pdev = platform_create_bundle(&i8042_driver, i8042_probe, NULL, 0, NULL, 0);
 	if (IS_ERR(pdev)) {
 		err = PTR_ERR(pdev);
@@ -1636,6 +1643,9 @@ static int __init i8042_init(void)
 
 static void __exit i8042_exit(void)
 {
+	if (!i8042_present)
+		return;
+
 	platform_device_unregister(i8042_platform_device);
 	platform_driver_unregister(&i8042_driver);
 	i8042_platform_exit();
-- 
2.28.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH resend] Input: i8042 - Allow insmod to succeed on devices without an i8042 controller
  2020-10-08 11:26 ` [PATCH resend] " Hans de Goede
@ 2020-10-27  3:56   ` Dmitry Torokhov
  0 siblings, 0 replies; 3+ messages in thread
From: Dmitry Torokhov @ 2020-10-27  3:56 UTC (permalink / raw)
  To: Hans de Goede; +Cc: linux-input, Marius Iacob

On Thu, Oct 08, 2020 at 01:26:28PM +0200, Hans de Goede wrote:
> The i8042 module exports several symbols which may be used by other
> modules.
> 
> Before this commit it would refuse to load (when built as a module itself)
> on systems without an i8042 controller.
> 
> This is a problem specifically for the asus-nb-wmi module. Many Asus
> laptops support the Asus WMI interface. Some of them have an i8042
> controller and need to use i8042_install_filter() to filter some kbd
> events. Other models do not have an i8042 controller (e.g. they use an
> USB attached kbd).
> 
> Before this commit the asus-nb-wmi driver could not be loaded on Asus
> models without an i8042 controller, when the i8042 code was built as
> a module (as Arch Linux does) because the module_init function of the
> i8042 module would fail with -ENODEV and thus the i8042_install_filter
> symbol could not be loaded.
> 
> This commit fixes this by exiting from module_init with a return code
> of 0 if no controller is found.  It also adds a i8042_present bool to
> make the module_exit function a no-op in this case and also adds a
> check for i8042_present to the exported i8042_command function.
> 
> The latter i8042_present check should not really be necessary because
> when builtin that function can already be used on systems without
> an i8042 controller, but better safe then sorry.
> 
> Reported-and-tested-by: Marius Iacob <themariusus@gmail.com>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>

Applied, thank you.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-08 11:26 [PATCH resend 0/1] Input: i8042 - Allow insmod to succeed on devices without an i8042 controller Hans de Goede
2020-10-08 11:26 ` [PATCH resend] " Hans de Goede
2020-10-27  3:56   ` Dmitry Torokhov

Linux Input Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-input/0 linux-input/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-input linux-input/ https://lore.kernel.org/linux-input \
		linux-input@vger.kernel.org
	public-inbox-index linux-input

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-input


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git