From: "Jiri Slaby (SUSE)" <jirislaby@kernel.org>
To: gregkh@linuxfoundation.org
Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
"Jiri Slaby (SUSE)" <jirislaby@kernel.org>
Subject: [PATCH 07/15] tty: invert return values of tty_{,un}throttle_safe()
Date: Tue, 19 Sep 2023 10:51:48 +0200 [thread overview]
Message-ID: <20230919085156.1578-8-jirislaby@kernel.org> (raw)
In-Reply-To: <20230919085156.1578-1-jirislaby@kernel.org>
If tty_{,un}throttle_safe() returned true on success (similar to
*_trylock()), it would make the conditions in callers more obvious. So
perform the switch to these inverted values (and fix the callers).
Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
drivers/tty/n_tty.c | 4 ++--
drivers/tty/tty_ioctl.c | 12 ++++++------
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index b34e6612aef6..f252d0b5a434 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -253,7 +253,7 @@ static void n_tty_check_throttle(struct tty_struct *tty)
tty_set_flow_change(tty, TTY_THROTTLE_SAFE);
if (N_TTY_BUF_SIZE - read_cnt(ldata) >= TTY_THRESHOLD_THROTTLE)
break;
- } while (tty_throttle_safe(tty));
+ } while (!tty_throttle_safe(tty));
__tty_set_flow_change(tty, 0);
}
@@ -282,7 +282,7 @@ static void n_tty_check_unthrottle(struct tty_struct *tty)
break;
n_tty_kick_worker(tty);
- } while (tty_unthrottle_safe(tty));
+ } while (!tty_unthrottle_safe(tty));
__tty_set_flow_change(tty, 0);
}
diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c
index ba60fcf518e0..fb2f1ac5172f 100644
--- a/drivers/tty/tty_ioctl.c
+++ b/drivers/tty/tty_ioctl.c
@@ -124,16 +124,16 @@ EXPORT_SYMBOL(tty_unthrottle);
* conditions when throttling is conditional on factors evaluated prior to
* throttling.
*
- * Returns false if tty is throttled (or was already throttled)
+ * Returns true if tty is throttled (or was already throttled)
*/
bool tty_throttle_safe(struct tty_struct *tty)
{
- bool ret = false;
+ bool ret = true;
mutex_lock(&tty->throttle_mutex);
if (!tty_throttled(tty)) {
if (tty->flow_change != TTY_THROTTLE_SAFE)
- ret = true;
+ ret = false;
else {
set_bit(TTY_THROTTLED, &tty->flags);
if (tty->ops->throttle)
@@ -154,16 +154,16 @@ bool tty_throttle_safe(struct tty_struct *tty)
* unthrottle due to race conditions when unthrottling is conditional
* on factors evaluated prior to unthrottling.
*
- * Returns false if tty is unthrottled (or was already unthrottled)
+ * Returns true if tty is unthrottled (or was already unthrottled)
*/
bool tty_unthrottle_safe(struct tty_struct *tty)
{
- bool ret = false;
+ bool ret = true;
mutex_lock(&tty->throttle_mutex);
if (tty_throttled(tty)) {
if (tty->flow_change != TTY_UNTHROTTLE_SAFE)
- ret = true;
+ ret = false;
else {
clear_bit(TTY_THROTTLED, &tty->flags);
if (tty->ops->unthrottle)
--
2.42.0
next prev parent reply other threads:[~2023-09-19 8:52 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-19 8:51 [PATCH 00/15] random tty fixes Jiri Slaby (SUSE)
2023-09-19 8:51 ` [PATCH 01/15] tty: n_tty: use 'retval' instead of 'c' Jiri Slaby (SUSE)
2023-09-19 8:51 ` [PATCH 02/15] tty: n_tty: rename and retype 'retval' in n_tty_ioctl() Jiri Slaby (SUSE)
2023-09-19 8:51 ` [PATCH 03/15] tty: n_tty: use min3() in copy_from_read_buf() Jiri Slaby (SUSE)
2023-09-19 8:51 ` [PATCH 04/15] tty: n_tty: invert the condition " Jiri Slaby (SUSE)
2023-09-19 9:54 ` Ilpo Järvinen
2023-09-19 10:43 ` Jiri Slaby
2023-09-19 8:51 ` [PATCH 05/15] tty: n_tty: use do-while in n_tty_check_{,un}throttle() Jiri Slaby (SUSE)
2023-09-19 8:51 ` [PATCH 06/15] tty: switch tty_{,un}throttle_safe() to return a bool Jiri Slaby (SUSE)
2023-09-19 8:51 ` Jiri Slaby (SUSE) [this message]
2023-09-19 8:51 ` [PATCH 08/15] tty: fix up and plug in tty_ioctl kernel-doc Jiri Slaby (SUSE)
2023-09-19 8:51 ` [PATCH 09/15] tty: fix kernel-doc for functions in tty.h Jiri Slaby (SUSE)
2023-09-19 10:07 ` Ilpo Järvinen
2023-09-19 10:45 ` Jiri Slaby
2023-09-19 10:47 ` Jiri Slaby
2023-09-19 10:51 ` Ilpo Järvinen
2023-09-19 8:51 ` [PATCH 10/15] tty: stop using ndash in kernel-doc Jiri Slaby (SUSE)
2023-09-19 8:51 ` [PATCH 11/15] tty: tty_buffer: use bool for 'restart' in tty_buffer_unlock_exclusive() Jiri Slaby (SUSE)
2023-09-19 8:51 ` [PATCH 12/15] tty: convert THROTTLE constants into enum Jiri Slaby (SUSE)
2023-09-19 10:10 ` Ilpo Järvinen
2023-09-19 10:51 ` Jiri Slaby
2023-09-19 8:51 ` [PATCH 13/15] tty: early return from send_break() on TTY_DRIVER_HARDWARE_BREAK Jiri Slaby (SUSE)
2023-09-19 8:51 ` [PATCH 14/15] tty: don't check for signal_pending() in send_break() Jiri Slaby (SUSE)
2023-09-19 10:14 ` Ilpo Järvinen
2023-09-19 8:51 ` [PATCH 15/15] tty: use 'if' in send_break() instead of 'goto' Jiri Slaby (SUSE)
2023-09-19 10:17 ` [PATCH 00/15] random tty fixes Ilpo Järvinen
2023-09-19 10:21 ` Greg Kroah-Hartman
2023-09-19 10:53 ` Ilpo Järvinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230919085156.1578-8-jirislaby@kernel.org \
--to=jirislaby@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.