[printk,v2,35/38] tty: tty_io: use console_list_lock for list synchronization

Message ID 20221019145600.1282823-36-john.ogness@linutronix.de
State New
Headers
Series reduce console_lock scope |

Commit Message

John Ogness Oct. 19, 2022, 2:55 p.m. UTC
  show_cons_active() uses the console_lock to gather information
on registered consoles. It requires that no consoles are unregistered
until it is finished. The console_list_lock should be used because
list synchronization repsponsibility will be removed from the
console_lock in a later change.

Note, the console_lock is still needed to stop console printing.

Signed-off-by: John Ogness <john.ogness@linutronix.de>
---
 drivers/tty/tty_io.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
  

Comments

Greg KH Oct. 20, 2022, 7:43 a.m. UTC | #1
On Wed, Oct 19, 2022 at 05:01:57PM +0206, John Ogness wrote:
> show_cons_active() uses the console_lock to gather information
> on registered consoles. It requires that no consoles are unregistered
> until it is finished. The console_list_lock should be used because
> list synchronization repsponsibility will be removed from the
> console_lock in a later change.
> 
> Note, the console_lock is still needed to stop console printing.
> 
> Signed-off-by: John Ogness <john.ogness@linutronix.de>

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  
Petr Mladek Oct. 27, 2022, 10:17 a.m. UTC | #2
On Wed 2022-10-19 17:01:57, John Ogness wrote:
> show_cons_active() uses the console_lock to gather information
> on registered consoles. It requires that no consoles are unregistered
> until it is finished. The console_list_lock should be used because
> list synchronization repsponsibility will be removed from the
> console_lock in a later change.
> 
> Note, the console_lock is still needed to stop console printing.
> 
> Signed-off-by: John Ogness <john.ogness@linutronix.de>

Reviewed-by: Petr Mladek <pmladek@suse.com>

Best Regards,
Petr
  

Patch

diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 333579bfa335..46a0e3c5c3a5 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -3527,14 +3527,12 @@  static ssize_t show_cons_active(struct device *dev,
 	ssize_t count = 0;
 
 	/*
-	 * Hold the console_lock to guarantee that no consoles are
+	 * Hold the console_list_lock to guarantee that no consoles are
 	 * unregistered until all console processing is complete.
 	 * This also allows safe traversal of the console list.
-	 *
-	 * Stop console printing because the device() callback may
-	 * assume the console is not within its write() callback.
 	 */
-	console_lock();
+	console_list_lock();
+
 	for_each_console(c) {
 		if (!c->device)
 			continue;
@@ -3546,6 +3544,12 @@  static ssize_t show_cons_active(struct device *dev,
 		if (i >= ARRAY_SIZE(cs))
 			break;
 	}
+
+	/*
+	 * Stop console printing because the device() callback may
+	 * assume the console is not within its write() callback.
+	 */
+	console_lock();
 	while (i--) {
 		int index = cs[i]->index;
 		struct tty_driver *drv = cs[i]->device(cs[i], &index);
@@ -3561,6 +3565,8 @@  static ssize_t show_cons_active(struct device *dev,
 	}
 	console_unlock();
 
+	console_list_unlock();
+
 	return count;
 }
 static DEVICE_ATTR(active, S_IRUGO, show_cons_active, NULL);