[10/10] tty: Return bool from tty_termios_hw_change()

Message ID 20230104151531.73994-11-ilpo.jarvinen@linux.intel.com
State New
Headers
Series tty/serial: bool conversions and cleanups |

Commit Message

Ilpo Järvinen Jan. 4, 2023, 3:15 p.m. UTC
  Change tty_termios_hw_change() return to bool and convert it to
a or-chained return statement.

Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
 drivers/tty/tty_ioctl.c | 10 ++++------
 include/linux/tty.h     |  2 +-
 2 files changed, 5 insertions(+), 7 deletions(-)
  

Comments

Jiri Slaby Jan. 5, 2023, 6:28 a.m. UTC | #1
On 04. 01. 23, 16:15, Ilpo Järvinen wrote:
> Change tty_termios_hw_change() return to bool and convert it to

If you are going to resend, should it be "to return bool" instead?

> a or-chained return statement.

and s/a/an/

> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

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

> ---
>   drivers/tty/tty_ioctl.c | 10 ++++------
>   include/linux/tty.h     |  2 +-
>   2 files changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c
> index ce511557b98b..4a80fabf6d5e 100644
> --- a/drivers/tty/tty_ioctl.c
> +++ b/drivers/tty/tty_ioctl.c
> @@ -270,13 +270,11 @@ EXPORT_SYMBOL(tty_termios_copy_hw);
>    *	between the two termios structures, or a speed change is needed.
>    */
>   
> -int tty_termios_hw_change(const struct ktermios *a, const struct ktermios *b)
> +bool tty_termios_hw_change(const struct ktermios *a, const struct ktermios *b)
>   {
> -	if (a->c_ispeed != b->c_ispeed || a->c_ospeed != b->c_ospeed)
> -		return 1;
> -	if ((a->c_cflag ^ b->c_cflag) & ~(HUPCL | CREAD | CLOCAL))
> -		return 1;
> -	return 0;
> +	return a->c_ispeed != b->c_ispeed ||
> +	       a->c_ospeed != b->c_ospeed ||
> +	       (a->c_cflag ^ b->c_cflag) & ~(HUPCL | CREAD | CLOCAL);
>   }
>   EXPORT_SYMBOL(tty_termios_hw_change);
>   
> diff --git a/include/linux/tty.h b/include/linux/tty.h
> index 730c3301d710..093935e97f42 100644
> --- a/include/linux/tty.h
> +++ b/include/linux/tty.h
> @@ -453,7 +453,7 @@ unsigned char tty_get_char_size(unsigned int cflag);
>   unsigned char tty_get_frame_size(unsigned int cflag);
>   
>   void tty_termios_copy_hw(struct ktermios *new, const struct ktermios *old);
> -int tty_termios_hw_change(const struct ktermios *a, const struct ktermios *b);
> +bool tty_termios_hw_change(const struct ktermios *a, const struct ktermios *b);
>   int tty_set_termios(struct tty_struct *tty, struct ktermios *kt);
>   
>   void tty_wakeup(struct tty_struct *tty);
  
Johan Hovold Jan. 5, 2023, 9:27 a.m. UTC | #2
On Wed, Jan 04, 2023 at 05:15:31PM +0200, Ilpo Järvinen wrote:
> Change tty_termios_hw_change() return to bool and convert it to
> a or-chained return statement.
> 
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> ---
>  drivers/tty/tty_ioctl.c | 10 ++++------
>  include/linux/tty.h     |  2 +-
>  2 files changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c
> index ce511557b98b..4a80fabf6d5e 100644
> --- a/drivers/tty/tty_ioctl.c
> +++ b/drivers/tty/tty_ioctl.c
> @@ -270,13 +270,11 @@ EXPORT_SYMBOL(tty_termios_copy_hw);
>   *	between the two termios structures, or a speed change is needed.
>   */
>  
> -int tty_termios_hw_change(const struct ktermios *a, const struct ktermios *b)
> +bool tty_termios_hw_change(const struct ktermios *a, const struct ktermios *b)
>  {
> -	if (a->c_ispeed != b->c_ispeed || a->c_ospeed != b->c_ospeed)
> -		return 1;
> -	if ((a->c_cflag ^ b->c_cflag) & ~(HUPCL | CREAD | CLOCAL))
> -		return 1;
> -	return 0;
> +	return a->c_ispeed != b->c_ispeed ||
> +	       a->c_ospeed != b->c_ospeed ||
> +	       (a->c_cflag ^ b->c_cflag) & ~(HUPCL | CREAD | CLOCAL);

Please keep the current structure which is more readable rather than
merge everything into one long expression.

Johan
  

Patch

diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c
index ce511557b98b..4a80fabf6d5e 100644
--- a/drivers/tty/tty_ioctl.c
+++ b/drivers/tty/tty_ioctl.c
@@ -270,13 +270,11 @@  EXPORT_SYMBOL(tty_termios_copy_hw);
  *	between the two termios structures, or a speed change is needed.
  */
 
-int tty_termios_hw_change(const struct ktermios *a, const struct ktermios *b)
+bool tty_termios_hw_change(const struct ktermios *a, const struct ktermios *b)
 {
-	if (a->c_ispeed != b->c_ispeed || a->c_ospeed != b->c_ospeed)
-		return 1;
-	if ((a->c_cflag ^ b->c_cflag) & ~(HUPCL | CREAD | CLOCAL))
-		return 1;
-	return 0;
+	return a->c_ispeed != b->c_ispeed ||
+	       a->c_ospeed != b->c_ospeed ||
+	       (a->c_cflag ^ b->c_cflag) & ~(HUPCL | CREAD | CLOCAL);
 }
 EXPORT_SYMBOL(tty_termios_hw_change);
 
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 730c3301d710..093935e97f42 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -453,7 +453,7 @@  unsigned char tty_get_char_size(unsigned int cflag);
 unsigned char tty_get_frame_size(unsigned int cflag);
 
 void tty_termios_copy_hw(struct ktermios *new, const struct ktermios *old);
-int tty_termios_hw_change(const struct ktermios *a, const struct ktermios *b);
+bool tty_termios_hw_change(const struct ktermios *a, const struct ktermios *b);
 int tty_set_termios(struct tty_struct *tty, struct ktermios *kt);
 
 void tty_wakeup(struct tty_struct *tty);