* [PATCH] tty: tty_jobctrl: use guard() in tiocgsid()
@ 2026-07-01 21:49 John de la Garza
0 siblings, 0 replies; 3+ messages in thread
From: John de la Garza @ 2026-07-01 21:49 UTC (permalink / raw)
To: gregkh, jirislaby; +Cc: linux-serial, linux-kernel, John de la Garza
guard()s express more clearly what the lock protects and let the
function return immediately instead of jumping to an unlock label.
Signed-off-by: John de la Garza <john@jjdev.com>
---
drivers/tty/tty_jobctrl.c | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/drivers/tty/tty_jobctrl.c b/drivers/tty/tty_jobctrl.c
index ef8741c3e662..939569f12119 100644
--- a/drivers/tty/tty_jobctrl.c
+++ b/drivers/tty/tty_jobctrl.c
@@ -542,7 +542,6 @@ static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t
*/
static int tiocgsid(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p)
{
- unsigned long flags;
pid_t sid;
/*
@@ -552,17 +551,13 @@ static int tiocgsid(struct tty_struct *tty, struct tty_struct *real_tty, pid_t _
if (tty == real_tty && current->signal->tty != real_tty)
return -ENOTTY;
- spin_lock_irqsave(&real_tty->ctrl.lock, flags);
- if (!real_tty->ctrl.session)
- goto err;
- sid = pid_vnr(real_tty->ctrl.session);
- spin_unlock_irqrestore(&real_tty->ctrl.lock, flags);
+ scoped_guard(spinlock_irqsave, &real_tty->ctrl.lock) {
+ if (!real_tty->ctrl.session)
+ return -ENOTTY;
+ sid = pid_vnr(real_tty->ctrl.session);
+ }
return put_user(sid, p);
-
-err:
- spin_unlock_irqrestore(&real_tty->ctrl.lock, flags);
- return -ENOTTY;
}
/*
--
2.54.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH] tty: tty_jobctrl: use guard() in tiocgsid()
@ 2026-07-01 23:12 John de la Garza
2026-07-02 3:34 ` Jiri Slaby
0 siblings, 1 reply; 3+ messages in thread
From: John de la Garza @ 2026-07-01 23:12 UTC (permalink / raw)
To: gregkh, jirislaby; +Cc: linux-serial, linux-kernel, John de la Garza
guard()s express more clearly what the lock protects and let the
function return immediately instead of jumping to an unlock label.
Signed-off-by: John de la Garza <john@jjdev.com>
---
drivers/tty/tty_jobctrl.c | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/drivers/tty/tty_jobctrl.c b/drivers/tty/tty_jobctrl.c
index ef8741c3e662..939569f12119 100644
--- a/drivers/tty/tty_jobctrl.c
+++ b/drivers/tty/tty_jobctrl.c
@@ -542,7 +542,6 @@ static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t
*/
static int tiocgsid(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p)
{
- unsigned long flags;
pid_t sid;
/*
@@ -552,17 +551,13 @@ static int tiocgsid(struct tty_struct *tty, struct tty_struct *real_tty, pid_t _
if (tty == real_tty && current->signal->tty != real_tty)
return -ENOTTY;
- spin_lock_irqsave(&real_tty->ctrl.lock, flags);
- if (!real_tty->ctrl.session)
- goto err;
- sid = pid_vnr(real_tty->ctrl.session);
- spin_unlock_irqrestore(&real_tty->ctrl.lock, flags);
+ scoped_guard(spinlock_irqsave, &real_tty->ctrl.lock) {
+ if (!real_tty->ctrl.session)
+ return -ENOTTY;
+ sid = pid_vnr(real_tty->ctrl.session);
+ }
return put_user(sid, p);
-
-err:
- spin_unlock_irqrestore(&real_tty->ctrl.lock, flags);
- return -ENOTTY;
}
/*
--
2.54.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] tty: tty_jobctrl: use guard() in tiocgsid()
2026-07-01 23:12 John de la Garza
@ 2026-07-02 3:34 ` Jiri Slaby
0 siblings, 0 replies; 3+ messages in thread
From: Jiri Slaby @ 2026-07-02 3:34 UTC (permalink / raw)
To: John de la Garza, gregkh; +Cc: linux-serial, linux-kernel
On 02. 07. 26, 1:12, John de la Garza wrote:
> guard()s express more clearly what the lock protects and let the
> function return immediately instead of jumping to an unlock label.
Why did you send this twice? Other than that:
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] 3+ messages in thread
end of thread, other threads:[~2026-07-02 3:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-01 21:49 [PATCH] tty: tty_jobctrl: use guard() in tiocgsid() John de la Garza
-- strict thread matches above, loose matches on Subject: below --
2026-07-01 23:12 John de la Garza
2026-07-02 3:34 ` Jiri Slaby
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox