From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: "Jiri Slaby (SUSE)" <jirislaby@kernel.org>
Cc: gregkh@linuxfoundation.org, linux-serial@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 03/14] tty: n_tty: use 'retval' for writes' retvals
Date: Wed, 16 Aug 2023 17:21:26 +0300 (EEST) [thread overview]
Message-ID: <b0771d71-dff4-31d-7edb-01056d4c29@linux.intel.com> (raw)
In-Reply-To: <20230816105822.3685-7-jirislaby@kernel.org>
On Wed, 16 Aug 2023, Jiri Slaby (SUSE) wrote:
> We have a separate misnomer 'c' to hold the retuned value from
> tty->ops->write(). Instead, use already defined and properly typed
> 'retval'.
>
> We have another variable 'num' to serve the same purpose in the OPOST
> branch. We can use this 'retval' too. But just clear it in case of
> EAGAIN.
>
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> ---
> drivers/tty/n_tty.c | 30 ++++++++++++++----------------
> 1 file changed, 14 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
> index f6fa4dbdf78f..e293d87b5362 100644
> --- a/drivers/tty/n_tty.c
> +++ b/drivers/tty/n_tty.c
> @@ -2335,7 +2335,6 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
> {
> const u8 *b = buf;
> DEFINE_WAIT_FUNC(wait, woken_wake_function);
> - int c;
> ssize_t retval = 0;
>
> /* Job control check -- must be done at start (POSIX.1 7.1.1.4). */
> @@ -2362,15 +2361,16 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
> }
> if (O_OPOST(tty)) {
> while (nr > 0) {
> - ssize_t num = process_output_block(tty, b, nr);
> - if (num < 0) {
> - if (num == -EAGAIN)
> - break;
> - retval = num;
> - goto break_out;
> + retval = process_output_block(tty, b, nr);
> + if (retval == -EAGAIN) {
> + retval = 0;
> + break;
> }
> - b += num;
> - nr -= num;
> + if (retval < 0)
> + goto break_out;
> +
> + b += retval;
> + nr -= retval;
> if (nr == 0)
> break;
> if (process_output(*b, tty) < 0)
> @@ -2384,16 +2384,14 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
>
> while (nr > 0) {
> mutex_lock(&ldata->output_lock);
> - c = tty->ops->write(tty, b, nr);
> + retval = tty->ops->write(tty, b, nr);
> mutex_unlock(&ldata->output_lock);
> - if (c < 0) {
> - retval = c;
> + if (retval < 0)
> goto break_out;
> - }
> - if (!c)
> + if (!retval)
> break;
> - b += c;
> - nr -= c;
> + b += retval;
> + nr -= retval;
Type might be better but these two don't look like a major improvement...
To me it seems obvious there exists some variable name that is better than
c or retval for this purpose. ;-)
--
i.
next prev parent reply other threads:[~2023-08-16 14:22 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-16 10:58 [PATCH 00/14] tty: n_tty: cleanup Jiri Slaby (SUSE)
2023-08-16 10:58 ` [PATCH 1/4] n_tty: drop fp from n_tty_receive_buf_real_raw() Jiri Slaby (SUSE)
2023-08-16 10:58 ` [PATCH 01/14] tty: n_tty: make flow of n_tty_receive_buf_common() a bool Jiri Slaby (SUSE)
2023-08-16 10:58 ` [PATCH 2/4] n_tty: simplify and sanitize zero_buffer() Jiri Slaby (SUSE)
2023-08-16 10:58 ` [PATCH 02/14] tty: n_tty: use output character directly Jiri Slaby (SUSE)
2023-08-16 10:58 ` [PATCH 3/4] n_tty: pass ldata to canon_skip_eof() directly Jiri Slaby (SUSE)
2023-08-16 10:58 ` [PATCH 03/14] tty: n_tty: use 'retval' for writes' retvals Jiri Slaby (SUSE)
2023-08-16 14:21 ` Ilpo Järvinen [this message]
2023-08-16 10:58 ` [PATCH 4/4] n_tty: make many tty parameters const Jiri Slaby (SUSE)
2023-08-16 10:58 ` [PATCH 04/14] tty: n_tty: use time_is_before_jiffies() in n_tty_receive_overrun() Jiri Slaby (SUSE)
2023-08-16 10:58 ` [PATCH 05/14] tty: n_tty: make n_tty_data::num_overrun unsigned Jiri Slaby (SUSE)
2023-08-16 10:58 ` [PATCH 06/14] tty: n_tty: use MASK() for masking out size bits Jiri Slaby (SUSE)
2023-08-16 10:58 ` [PATCH 07/14] tty: n_tty: move canon handling to a separate function Jiri Slaby (SUSE)
2023-08-16 10:58 ` [PATCH 08/14] tty: n_tty: move newline " Jiri Slaby (SUSE)
2023-08-16 10:58 ` [PATCH 09/14] tty: n_tty: remove unsigned char casts from character constants Jiri Slaby (SUSE)
2023-08-16 10:58 ` [PATCH 10/14] tty: n_tty: simplify chars_in_buffer() Jiri Slaby (SUSE)
2023-08-16 10:58 ` [PATCH 11/14] tty: n_tty: use u8 for chars and flags Jiri Slaby (SUSE)
2023-08-16 10:58 ` [PATCH 12/14] tty: n_tty: unify counts to size_t Jiri Slaby (SUSE)
2023-08-16 10:58 ` [PATCH 13/14] tty: n_tty: extract ECHO_OP processing to a separate function Jiri Slaby (SUSE)
2023-08-16 10:58 ` [PATCH 14/14] tty: n_tty: deduplicate copy code in n_tty_receive_buf_real_raw() Jiri Slaby (SUSE)
2023-08-16 11:02 ` [PATCH 00/14] tty: n_tty: cleanup Jiri Slaby
2023-08-16 11:20 ` Greg KH
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=b0771d71-dff4-31d-7edb-01056d4c29@linux.intel.com \
--to=ilpo.jarvinen@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).