Re: [PATCH v2 1/2] Input: i8042 - Prevent intermixing i8042 commands

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Raul,

On Thu, Aug 27, 2020 at 02:41:53PM -0600, Raul E Rangel wrote:
> The i8042_mutex must be held by writers of the AUX and KBD ports, as
> well as users of i8042_command. There were a lot of users of
> i8042_command that were not calling i8042_lock_chip/i8042_unlock_chip.
> This resulted in i8042_commands being issues in between PS/2
> transactions.
> 
> This change moves the mutex lock into i8042_command and removes the
> burden of locking the mutex from the callers.

I think there is a benefit for allowing users issue a sequence of
commands to i8042 without interruptions, so I would prefer keeping
i8042_[un]lock_chip() in place.

Given that the issue you were observing was caused by i8042_port_close()
interfering with probing, maybe we could do something like this:


diff --git a/drivers/input/serio/i8042.c b/drivers/input/serio/i8042.c
index abae23af0791..aff871001eda 100644
--- a/drivers/input/serio/i8042.c
+++ b/drivers/input/serio/i8042.c
@@ -344,6 +344,8 @@ int i8042_command(unsigned char *param, int command)
 	unsigned long flags;
 	int retval;
 
+	lockdep_assert_held(&i8042_mutex);
+
 	if (!i8042_present)
 		return -1;
 
@@ -364,6 +366,8 @@ static int i8042_kbd_write(struct serio *port, unsigned char c)
 	unsigned long flags;
 	int retval = 0;
 
+	lockdep_assert_held(&i8042_mutex);
+
 	spin_lock_irqsave(&i8042_lock, flags);
 
 	if (!(retval = i8042_wait_write())) {
@@ -411,6 +415,8 @@ static void i8042_port_close(struct serio *serio)
 		port_name = "KBD";
 	}
 
+	i8042_lock_chip();
+
 	i8042_ctr &= ~irq_bit;
 	if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR))
 		pr_warn("Can't write CTR while closing %s port\n", port_name);
@@ -422,6 +428,8 @@ static void i8042_port_close(struct serio *serio)
 	if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR))
 		pr_err("Can't reactivate %s port\n", port_name);
 
+	i8042_unlock_chip();
+
 	/*
 	 * See if there is any data appeared while we were messing with
 	 * port state.


Thanks.

-- 
Dmitry



[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux