mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Vamshi Gajjela <vamshigajjela@google.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiri Slaby <jirislaby@kernel.org>,
	linux-serial <linux-serial@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	manugautam@google.com, Subhash Jadavani <sjadavani@google.com>,
	Channa Kadabi <kadabi@google.com>
Subject: Re: [PATCH v5 2/2] serial: core: Clean up uart_update_timeout() function
Date: Mon, 30 Oct 2023 11:33:30 +0200 (EET)	[thread overview]
Message-ID: <275b9b10-204f-534e-2155-98f623d9f63a@linux.intel.com> (raw)
In-Reply-To: <20231030073542.251281-3-vamshigajjela@google.com>

On Mon, 30 Oct 2023, Vamshi Gajjela wrote:

> Rename the variable size to temp and change its data type from
> unsigned int to u64 to avoid type casting in multiplication. Remove the
> intermediate variable frame_time and use temp instead to accommodate
> the nanoseconds. port->frame_time is an unsigned int, therefore an
> explicit cast is used to improve readability.

You should focus more on why instead of what. So add explanation that the 
frame time is small (you could even calculate the largest value and add 
it to the commit message) and therefore it always fits safely to unsigned 
int. And that we do not upconvert the type to avoid unnecessary costly 
64-bit arithmetic done in a few places in the serial code.

> Signed-off-by: Vamshi Gajjela <vamshigajjela@google.com>
> ---
> v5:
> - shortlog changed from "serial: core: Make local variable size to
>   u64" to "Clean up uart_update_timeout() function"
> - renamed local variable size to temp, generic name
> - removed intermediate variable frame_time
> - added typecast "unsigned int" while assigning to port->frame_time
> v4:
> - no change, not submitted with series
> v3:
> - no change, not submitted with series
> v2:
> - no change, not submitted with series
> 
>  drivers/tty/serial/serial_core.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
> index 7bdc21d5e13b..21d345a9812a 100644
> --- a/drivers/tty/serial/serial_core.c
> +++ b/drivers/tty/serial/serial_core.c
> @@ -410,11 +410,10 @@ void
>  uart_update_timeout(struct uart_port *port, unsigned int cflag,
>  		    unsigned int baud)
>  {
> -	unsigned int size = tty_get_frame_size(cflag);
> -	u64 frame_time;
> +	u64 temp = tty_get_frame_size(cflag);
>  
> -	frame_time = (u64)size * NSEC_PER_SEC;
> -	port->frame_time = DIV64_U64_ROUND_UP(frame_time, baud);
> +	temp *= NSEC_PER_SEC;
> +	port->frame_time = (unsigned int)DIV64_U64_ROUND_UP(temp, baud);
>  }
>  EXPORT_SYMBOL(uart_update_timeout);
>  
> 

-- 
 i.


      reply	other threads:[~2023-10-30  9:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-30  7:35 [PATCH v5 0/2] serial core type consistency and clean up Vamshi Gajjela
2023-10-30  7:35 ` [PATCH v5 1/2] serial: core: Update uart_poll_timeout() function to return unsigned long Vamshi Gajjela
2023-10-30  9:25   ` Ilpo Järvinen
2023-10-30  7:35 ` [PATCH v5 2/2] serial: core: Clean up uart_update_timeout() function Vamshi Gajjela
2023-10-30  9:33   ` Ilpo Järvinen [this message]

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=275b9b10-204f-534e-2155-98f623d9f63a@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=kadabi@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=manugautam@google.com \
    --cc=sjadavani@google.com \
    --cc=vamshigajjela@google.com \
    /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

all inboxes | Powered by JetHome®