Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tty: simplify throttling using guard()s

tty_throttle_safe() and tty_unthrottle_safe can be made less convoluted
using guard()s. Switch them.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Link: https://lore.kernel.org/r/20250425111315.1036184-2-jirislaby@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Jiri Slaby (SUSE) and committed by
Greg Kroah-Hartman
3eabc1a3 e6afad45

+22 -26
+22 -26
drivers/tty/tty_ioctl.c
··· 122 122 */ 123 123 bool tty_throttle_safe(struct tty_struct *tty) 124 124 { 125 - bool ret = true; 125 + guard(mutex)(&tty->throttle_mutex); 126 126 127 - mutex_lock(&tty->throttle_mutex); 128 - if (!tty_throttled(tty)) { 129 - if (tty->flow_change != TTY_THROTTLE_SAFE) 130 - ret = false; 131 - else { 132 - set_bit(TTY_THROTTLED, &tty->flags); 133 - if (tty->ops->throttle) 134 - tty->ops->throttle(tty); 135 - } 136 - } 137 - mutex_unlock(&tty->throttle_mutex); 127 + if (tty_throttled(tty)) 128 + return true; 138 129 139 - return ret; 130 + if (tty->flow_change != TTY_THROTTLE_SAFE) 131 + return false; 132 + 133 + set_bit(TTY_THROTTLED, &tty->flags); 134 + if (tty->ops->throttle) 135 + tty->ops->throttle(tty); 136 + 137 + return true; 140 138 } 141 139 142 140 /** ··· 150 152 */ 151 153 bool tty_unthrottle_safe(struct tty_struct *tty) 152 154 { 153 - bool ret = true; 155 + guard(mutex)(&tty->throttle_mutex); 154 156 155 - mutex_lock(&tty->throttle_mutex); 156 - if (tty_throttled(tty)) { 157 - if (tty->flow_change != TTY_UNTHROTTLE_SAFE) 158 - ret = false; 159 - else { 160 - clear_bit(TTY_THROTTLED, &tty->flags); 161 - if (tty->ops->unthrottle) 162 - tty->ops->unthrottle(tty); 163 - } 164 - } 165 - mutex_unlock(&tty->throttle_mutex); 157 + if (!tty_throttled(tty)) 158 + return true; 166 159 167 - return ret; 160 + if (tty->flow_change != TTY_UNTHROTTLE_SAFE) 161 + return false; 162 + 163 + clear_bit(TTY_THROTTLED, &tty->flags); 164 + if (tty->ops->unthrottle) 165 + tty->ops->unthrottle(tty); 166 + 167 + return true; 168 168 } 169 169 170 170 /**