[PATCH] tty: use assign_bit() where applicable

Peng Fan (OSS) posted 1 patch 6 days, 8 hours ago
drivers/tty/pty.c   | 5 +----
drivers/tty/sysrq.c | 5 +----
2 files changed, 2 insertions(+), 8 deletions(-)
[PATCH] tty: use assign_bit() where applicable
Posted by Peng Fan (OSS) 6 days, 8 hours ago
From: Peng Fan <peng.fan@nxp.com>

Convert open-coded if/else with set_bit/clear_bit and their
non-atomic __set_bit/__clear_bit variants to the assign_bit/__assign_bit
API.

Done with Coccinelle semantic patch.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 drivers/tty/pty.c   | 5 +----
 drivers/tty/sysrq.c | 5 +----
 2 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
index cc7f7091ed9a..9a37008c4e91 100644
--- a/drivers/tty/pty.c
+++ b/drivers/tty/pty.c
@@ -138,10 +138,7 @@ static int pty_set_lock(struct tty_struct *tty, int __user *arg)
 
 	if (get_user(val, arg))
 		return -EFAULT;
-	if (val)
-		set_bit(TTY_PTY_LOCK, &tty->flags);
-	else
-		clear_bit(TTY_PTY_LOCK, &tty->flags);
+	assign_bit(TTY_PTY_LOCK, &tty->flags, val);
 	return 0;
 }
 
diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
index c2e4b31b699a..f4571d05b496 100644
--- a/drivers/tty/sysrq.c
+++ b/drivers/tty/sysrq.c
@@ -911,10 +911,7 @@ static bool sysrq_handle_keypress(struct sysrq_state *sysrq,
 		 * keyboard state so we can release keys that have been
 		 * pressed before entering SysRq mode.
 		 */
-		if (value)
-			set_bit(code, sysrq->key_down);
-		else
-			clear_bit(code, sysrq->key_down);
+		assign_bit(code, sysrq->key_down, value);
 
 		if (was_active)
 			schedule_work(&sysrq->reinject_work);
-- 
2.51.0