2023-09-19 08:54:24

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 12/15] tty: convert THROTTLE constants into enum

And make an explicit constant for zero too. This allows for easier type
checking of the parameter.

Note: tty_struct::flow_change is kept as int because include/tty.h
(tty_struct) doesn't see tty/tty.h (this enum).

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
---
drivers/tty/tty.h | 13 +++++++++----
drivers/tty/tty_ioctl.c | 2 +-
2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/tty/tty.h b/drivers/tty/tty.h
index 50862f98273e..93cf5ef1e857 100644
--- a/drivers/tty/tty.h
+++ b/drivers/tty/tty.h
@@ -41,15 +41,20 @@ enum {
};

/* Values for tty->flow_change */
-#define TTY_THROTTLE_SAFE 1
-#define TTY_UNTHROTTLE_SAFE 2
+enum tty_flow_change {
+ TTY_FLOW_NO_CHANGE,
+ TTY_THROTTLE_SAFE,
+ TTY_UNTHROTTLE_SAFE,
+};

-static inline void __tty_set_flow_change(struct tty_struct *tty, int val)
+static inline void __tty_set_flow_change(struct tty_struct *tty,
+ enum tty_flow_change val)
{
tty->flow_change = val;
}

-static inline void tty_set_flow_change(struct tty_struct *tty, int val)
+static inline void tty_set_flow_change(struct tty_struct *tty,
+ enum tty_flow_change val)
{
tty->flow_change = val;
smp_mb();
diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c
index 42c793e9d131..4b499301a3db 100644
--- a/drivers/tty/tty_ioctl.c
+++ b/drivers/tty/tty_ioctl.c
@@ -104,7 +104,7 @@ void tty_unthrottle(struct tty_struct *tty)
if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) &&
tty->ops->unthrottle)
tty->ops->unthrottle(tty);
- tty->flow_change = 0;
+ tty->flow_change = TTY_FLOW_NO_CHANGE;
up_write(&tty->termios_rwsem);
}
EXPORT_SYMBOL(tty_unthrottle);
--
2.42.0


2023-09-19 11:11:36

by Jiri Slaby

[permalink] [raw]
Subject: Re: [PATCH 12/15] tty: convert THROTTLE constants into enum

On 19. 09. 23, 12:10, Ilpo Järvinen wrote:
> On Tue, 19 Sep 2023, Jiri Slaby (SUSE) wrote:
>
>> And make an explicit constant for zero too. This allows for easier type
>> checking of the parameter.
>>
>> Note: tty_struct::flow_change is kept as int because include/tty.h
>> (tty_struct) doesn't see tty/tty.h (this enum).
>
> And it cannot moved there because of what?

It's possible, but would make the constants "public". I hoped for
forward enum declaration, but since enum is no longer a simple int, the
compilation then fails with incomplete type of tty_struct.

thanks,
--
js
suse labs

2023-09-19 17:38:16

by Ilpo Järvinen

[permalink] [raw]
Subject: Re: [PATCH 12/15] tty: convert THROTTLE constants into enum

On Tue, 19 Sep 2023, Jiri Slaby (SUSE) wrote:

> And make an explicit constant for zero too. This allows for easier type
> checking of the parameter.
>
> Note: tty_struct::flow_change is kept as int because include/tty.h
> (tty_struct) doesn't see tty/tty.h (this enum).

And it cannot moved there because of what?

--
i.


> Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
> ---
> drivers/tty/tty.h | 13 +++++++++----
> drivers/tty/tty_ioctl.c | 2 +-
> 2 files changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/tty/tty.h b/drivers/tty/tty.h
> index 50862f98273e..93cf5ef1e857 100644
> --- a/drivers/tty/tty.h
> +++ b/drivers/tty/tty.h
> @@ -41,15 +41,20 @@ enum {
> };
>
> /* Values for tty->flow_change */
> -#define TTY_THROTTLE_SAFE 1
> -#define TTY_UNTHROTTLE_SAFE 2
> +enum tty_flow_change {
> + TTY_FLOW_NO_CHANGE,
> + TTY_THROTTLE_SAFE,
> + TTY_UNTHROTTLE_SAFE,
> +};
>
> -static inline void __tty_set_flow_change(struct tty_struct *tty, int val)
> +static inline void __tty_set_flow_change(struct tty_struct *tty,
> + enum tty_flow_change val)
> {
> tty->flow_change = val;
> }
>
> -static inline void tty_set_flow_change(struct tty_struct *tty, int val)
> +static inline void tty_set_flow_change(struct tty_struct *tty,
> + enum tty_flow_change val)
> {
> tty->flow_change = val;
> smp_mb();
> diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c
> index 42c793e9d131..4b499301a3db 100644
> --- a/drivers/tty/tty_ioctl.c
> +++ b/drivers/tty/tty_ioctl.c
> @@ -104,7 +104,7 @@ void tty_unthrottle(struct tty_struct *tty)
> if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) &&
> tty->ops->unthrottle)
> tty->ops->unthrottle(tty);
> - tty->flow_change = 0;
> + tty->flow_change = TTY_FLOW_NO_CHANGE;
> up_write(&tty->termios_rwsem);
> }
> EXPORT_SYMBOL(tty_unthrottle);
>