The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] tty: tty_jobctrl: use guard()s in tiocspgrp()
@ 2026-07-01  3:27 John de la Garza
  2026-07-01  4:11 ` Jiri Slaby
  0 siblings, 1 reply; 2+ messages in thread
From: John de la Garza @ 2026-07-01  3:27 UTC (permalink / raw)
  To: gregkh, jirislaby, john; +Cc: linux-serial, linux-kernel

Convert the manual spin_lock_irq()/rcu_read_lock() nesting in tiocspgrp()
to scoped guard()s. This drops the out_unlock and out_unlock_ctrl labels
and lets the error paths return directly.

No functional change intended.

Signed-off-by: John de la Garza <john@jjdev.com>
---
 drivers/tty/tty_jobctrl.c | 26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)

diff --git a/drivers/tty/tty_jobctrl.c b/drivers/tty/tty_jobctrl.c
index ef8741c3e662..583e2412a47b 100644
--- a/drivers/tty/tty_jobctrl.c
+++ b/drivers/tty/tty_jobctrl.c
@@ -506,29 +506,23 @@ static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t
 	if (pgrp_nr < 0)
 		return -EINVAL;
 
-	spin_lock_irq(&real_tty->ctrl.lock);
+	guard(spinlock_irq)(&real_tty->ctrl.lock);
 	if (!current->signal->tty ||
 	    (current->signal->tty != real_tty) ||
-	    (real_tty->ctrl.session != task_session(current))) {
-		retval = -ENOTTY;
-		goto out_unlock_ctrl;
-	}
-	rcu_read_lock();
+	    (real_tty->ctrl.session != task_session(current)))
+		return -ENOTTY;
+
+	guard(rcu)();
 	pgrp = find_vpid(pgrp_nr);
-	retval = -ESRCH;
 	if (!pgrp)
-		goto out_unlock;
-	retval = -EPERM;
+		return -ESRCH;
 	if (session_of_pgrp(pgrp) != task_session(current))
-		goto out_unlock;
-	retval = 0;
+		return -EPERM;
+
 	put_pid(real_tty->ctrl.pgrp);
 	real_tty->ctrl.pgrp = get_pid(pgrp);
-out_unlock:
-	rcu_read_unlock();
-out_unlock_ctrl:
-	spin_unlock_irq(&real_tty->ctrl.lock);
-	return retval;
+
+	return 0;
 }
 
 /**
-- 
2.53.0



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

* Re: [PATCH] tty: tty_jobctrl: use guard()s in tiocspgrp()
  2026-07-01  3:27 [PATCH] tty: tty_jobctrl: use guard()s in tiocspgrp() John de la Garza
@ 2026-07-01  4:11 ` Jiri Slaby
  0 siblings, 0 replies; 2+ messages in thread
From: Jiri Slaby @ 2026-07-01  4:11 UTC (permalink / raw)
  To: John de la Garza, gregkh; +Cc: linux-serial, linux-kernel

On 01. 07. 26, 5:27, John de la Garza wrote:
> Convert the manual spin_lock_irq()/rcu_read_lock() nesting in tiocspgrp()
> to scoped guard()s. This drops the out_unlock and out_unlock_ctrl labels
> and lets the error paths return directly.
> 
> No functional change intended.

Nice cleanup!

Reviewed-by: Jiri Slaby <jirislaby@kernel.org>

> Signed-off-by: John de la Garza <john@jjdev.com>
thanks,
-- 
js
suse labs

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

end of thread, other threads:[~2026-07-01  4:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-01  3:27 [PATCH] tty: tty_jobctrl: use guard()s in tiocspgrp() John de la Garza
2026-07-01  4:11 ` Jiri Slaby

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox