diff mbox series

[1/6] n_tty: Start making use of -EAGAIN returned from process_output_block()

Message ID 20210921103346.64824-2-tony@atomide.com (mailing list archive)
State New, archived
Headers show
Series Get rid of pm_runtime_irq_safe() for 8250_omap | expand

Commit Message

Tony Lindgren Sept. 21, 2021, 10:33 a.m. UTC
We check for -EAGAIN in n_tty_write() but never currently get it from
process_output_block(). Let's add -EAGAIN handling and break out with 0
bytes processed. Note that if we return -EAGAIN from n_tty_write(), it
will be treated as error by the caller rather than a retry.

Looking at the patch description for commit 9ef8927f45f2 ("n_tty: check
for negative and zero space return from tty_write_room") it looks like we
have not made use of -EGAIN from process_output_block() so far, so this
does not seem like it's currently needed as a fix.

We can use -EAGAIN for serial layer power management changes as we now
will make use of write_room() returning 0 for an idled serial port.

Signed-off-by: Tony Lindgren <tony@atomide.com>
---
 drivers/tty/n_tty.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Andy Shevchenko Sept. 21, 2021, 11:58 a.m. UTC | #1
On Tue, Sep 21, 2021 at 1:34 PM Tony Lindgren <tony@atomide.com> wrote:
>
> We check for -EAGAIN in n_tty_write() but never currently get it from
> process_output_block(). Let's add -EAGAIN handling and break out with 0
> bytes processed. Note that if we return -EAGAIN from n_tty_write(), it
> will be treated as error by the caller rather than a retry.
>
> Looking at the patch description for commit 9ef8927f45f2 ("n_tty: check
> for negative and zero space return from tty_write_room") it looks like we
> have not made use of -EGAIN from process_output_block() so far, so this

-EGAIN?

> does not seem like it's currently needed as a fix.
>
> We can use -EAGAIN for serial layer power management changes as we now
> will make use of write_room() returning 0 for an idled serial port.
>
> Signed-off-by: Tony Lindgren <tony@atomide.com>
> ---
>  drivers/tty/n_tty.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
> --- a/drivers/tty/n_tty.c
> +++ b/drivers/tty/n_tty.c
> @@ -549,6 +549,8 @@ static ssize_t process_output_block(struct tty_struct *tty,
>         space = tty_write_room(tty);
>         if (space <= 0) {
>                 mutex_unlock(&ldata->output_lock);
> +               if (!space)
> +                       space = -EAGAIN;
>                 return space;
>         }
>         if (nr > space)
> @@ -2287,8 +2289,10 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
>                         while (nr > 0) {
>                                 ssize_t num = process_output_block(tty, b, nr);
>                                 if (num < 0) {
> -                                       if (num == -EAGAIN)
> -                                               break;
> +                                       if (num == -EAGAIN) {
> +                                               retval = 0;
> +                                               goto break_out;
> +                                       }
>                                         retval = num;
>                                         goto break_out;
>                                 }
> --
> 2.33.0
diff mbox series

Patch

diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -549,6 +549,8 @@  static ssize_t process_output_block(struct tty_struct *tty,
 	space = tty_write_room(tty);
 	if (space <= 0) {
 		mutex_unlock(&ldata->output_lock);
+		if (!space)
+			space = -EAGAIN;
 		return space;
 	}
 	if (nr > space)
@@ -2287,8 +2289,10 @@  static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
 			while (nr > 0) {
 				ssize_t num = process_output_block(tty, b, nr);
 				if (num < 0) {
-					if (num == -EAGAIN)
-						break;
+					if (num == -EAGAIN) {
+						retval = 0;
+						goto break_out;
+					}
 					retval = num;
 					goto break_out;
 				}