From: Frediano Ziglio <fziglio@redhat.com>
To: Laurent Vivier <laurent@vivier.eu>
Cc: Michael Tokarev <mjt@tls.msk.ru>, qemu-trivial@nongnu.org
Subject: Re: [PATCH 3/3] qemu-timer: reuse MIN macro in qemu_timeout_ns_to_ms
Date: Fri, 27 Sep 2019 07:57:05 -0400 (EDT) [thread overview]
Message-ID: <478273945.3530478.1569585425201.JavaMail.zimbra@redhat.com> (raw)
In-Reply-To: <9ec0d128-86ec-542b-a1b6-5cba36b752ec@vivier.eu>
>
> Le 27/09/2019 à 12:32, Frediano Ziglio a écrit :
> > Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
> > ---
> > util/qemu-timer.c | 6 +-----
> > 1 file changed, 1 insertion(+), 5 deletions(-)
> >
> > diff --git a/util/qemu-timer.c b/util/qemu-timer.c
> > index d428fec567..9bd173ecda 100644
> > --- a/util/qemu-timer.c
> > +++ b/util/qemu-timer.c
> > @@ -322,11 +322,7 @@ int qemu_timeout_ns_to_ms(int64_t ns)
> > ms = DIV_ROUND_UP(ns, SCALE_MS);
> >
> > /* To avoid overflow problems, limit this to 2^31, i.e. approx 25 days
> > */
> > - if (ms > (int64_t) INT32_MAX) {
> > - ms = INT32_MAX;
> > - }
> > -
> > - return (int) ms;
> > + return (int) MIN(ms, INT32_MAX);
> > }
> >
>
> Perhaps it would be cleaner to have always the same return type for
> MIN() with:
>
> MIN(ms, (int64_t) INT32_MAX)
>
The (int64_t) cast here is useless, ms is signed, C compilers knows how to
convert and compare properly.
The function returns int and it's used in some cases to fill 32bit integer,
changing the return type to int64_t is not trivial.
But I suppose that here you mean instead that the 2 sides of the ternary
operator used by MIN macro are int64_t and (probably) int32_t. In this case
feel free to add the cast with a
return (int) MIN(ms, (int64_t) INT32_MAX);
> Anyway:
>
> Reviewed-by: Laurent Vivier <laurent@vivier.eu>
>
> Thanks,
> Laurent
>
Frediano
next prev parent reply other threads:[~2019-09-27 13:13 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-27 10:32 [PATCH 1/3] util/async: avoid useless cast Frediano Ziglio
2019-09-27 10:32 ` [PATCH 2/3] event_notifier: avoid dandling file descriptor in event_notifier_cleanup Frediano Ziglio
2019-09-27 11:47 ` Laurent Vivier
2019-09-27 10:32 ` [PATCH 3/3] qemu-timer: reuse MIN macro in qemu_timeout_ns_to_ms Frediano Ziglio
2019-09-27 11:50 ` Laurent Vivier
2019-09-27 11:57 ` Frediano Ziglio [this message]
2019-09-27 12:07 ` Laurent Vivier
2019-09-27 11:43 ` [PATCH 1/3] util/async: avoid useless cast Laurent Vivier
2019-10-21 16:02 ` Laurent Vivier
-- strict thread matches above, loose matches on Subject: below --
2019-10-23 12:26 Frediano Ziglio
2019-10-23 12:26 ` [PATCH 3/3] qemu-timer: reuse MIN macro in qemu_timeout_ns_to_ms Frediano Ziglio
2019-10-23 13:42 ` Laurent Vivier
2019-10-23 14:12 ` Eric Blake
2019-10-23 14:15 ` Frediano Ziglio
2019-10-23 14:15 ` Frediano Ziglio
2019-10-23 14:23 ` Eric Blake
2019-10-23 14:23 ` Eric Blake
2019-10-23 14:45 ` Laurent Vivier
2019-10-23 14:45 ` Laurent Vivier
2019-10-23 14:51 ` Eric Blake
2019-10-23 14:51 ` Eric Blake
2019-10-23 14:58 ` Laurent Vivier
2019-10-23 14:58 ` Laurent Vivier
2019-10-24 17:31 ` Laurent Vivier
2019-10-24 17:31 ` Laurent Vivier
2019-10-24 18:03 ` Eric Blake
2019-10-24 18:11 ` Laurent Vivier
2019-10-24 20:55 ` Eric Blake
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=478273945.3530478.1569585425201.JavaMail.zimbra@redhat.com \
--to=fziglio@redhat.com \
--cc=laurent@vivier.eu \
--cc=mjt@tls.msk.ru \
--cc=qemu-trivial@nongnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.