[PATCH printk v2 36/38] proc: consoles: use console_list_lock for list iteration

John Ogness posted 38 patches 3 years, 5 months ago
There is a newer version of this series
[PATCH printk v2 36/38] proc: consoles: use console_list_lock for list iteration
Posted by John Ogness 3 years, 5 months ago
The console_lock is used in part to guarantee safe list iteration.
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>
---
 fs/proc/consoles.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/fs/proc/consoles.c b/fs/proc/consoles.c
index 32512b477605..77409b176569 100644
--- a/fs/proc/consoles.c
+++ b/fs/proc/consoles.c
@@ -33,7 +33,15 @@ static int show_console_dev(struct seq_file *m, void *v)
 	if (con->device) {
 		const struct tty_driver *driver;
 		int index;
+
+		/*
+		 * Stop console printing because the device() callback may
+		 * assume the console is not within its write() callback.
+		 */
+		console_lock();
 		driver = con->device(con, &index);
+		console_unlock();
+
 		if (driver) {
 			dev = MKDEV(driver->major, driver->minor_start);
 			dev += index;
@@ -64,14 +72,11 @@ static void *c_start(struct seq_file *m, loff_t *pos)
 	loff_t off = 0;
 
 	/*
-	 * Stop console printing because the device() callback may
-	 * assume the console is not within its write() callback.
-	 *
-	 * Hold the console_lock to guarantee safe traversal of the
+	 * Hold the console_list_lock to guarantee safe traversal of the
 	 * console list. SRCU cannot be used because there is no
 	 * place to store the SRCU cookie.
 	 */
-	console_lock();
+	console_list_lock();
 	for_each_console(con)
 		if (off++ == *pos)
 			break;
@@ -89,7 +94,7 @@ static void *c_next(struct seq_file *m, void *v, loff_t *pos)
 
 static void c_stop(struct seq_file *m, void *v)
 {
-	console_unlock();
+	console_list_unlock();
 }
 
 static const struct seq_operations consoles_op = {
-- 
2.30.2
Re: [PATCH printk v2 36/38] proc: consoles: use console_list_lock for list iteration
Posted by Petr Mladek 3 years, 5 months ago
On Wed 2022-10-19 17:01:58, John Ogness wrote:
> The console_lock is used in part to guarantee safe list iteration.
> 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