All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nick Desaulniers <ndesaulniers@google.com>
To: Arnd Bergmann <arnd@kernel.org>
Cc: Anders Roxell <anders.roxell@linaro.org>,
	Shuah Khan <shuah@kernel.org>,
	 Nathan Chancellor <nathan@kernel.org>,
	 "open list:KERNEL SELFTEST FRAMEWORK"
	<linux-kselftest@vger.kernel.org>,
	 Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	llvm@lists.linux.dev
Subject: Re: [PATCH 2/2] selftests: timens: exec: use 'labs()' over 'abs()'
Date: Fri, 5 Nov 2021 13:50:58 -0700	[thread overview]
Message-ID: <CAKwvOdm=a7w0cQdynY2i5ST=xrfjzXVZcUniAoEyqC21oKPQsQ@mail.gmail.com> (raw)
In-Reply-To: <CAK8P3a3ZuL9TQbj+tGkdvRRmEv_jT3OvzmaoFKHwdw=5J1w_SA@mail.gmail.com>

On Fri, Nov 5, 2021 at 1:45 PM Arnd Bergmann <arnd@kernel.org> wrote:
>
> On Fri, Nov 5, 2021 at 9:35 PM Nick Desaulniers <ndesaulniers@google.com> wrote:
> >
> > On Fri, Nov 5, 2021 at 9:31 AM Anders Roxell <anders.roxell@linaro.org> wrote:
> > >
> > > When building selftests/timens with clang, the compiler warn about the
> > > function abs() see below:
> > >
> > > exec.c:33:8: error: absolute value function 'abs' given an argument of type 'long' but has parameter of type 'int' which may cause truncation of value [-Werror,-Wabsolute-value]
> > >                         if (abs(tst.tv_sec - now.tv_sec) > 5)
> > >                             ^
> > > exec.c:33:8: note: use function 'labs' instead
> > >                         if (abs(tst.tv_sec - now.tv_sec) > 5)
> > >                             ^~~
> > >                             labs
> >
> > Careful.
> >
> > Isn't the tv_sec member of `struct timespec` a `time_t` which is 32b
> > on 32b hosts and 64b on 64b hosts? If I'm recalling that correctly,
> > then this patch results in a harmless (though unnecessary) sign
> > extension for 32b targets. That should be fine, but someone like Arnd
> > should triple check if my concern is valid or not.
>
> It could actually be 'int', 'long' or 'long long' depending on the architecture
> and C library. Maybe we need a temporary variable of type 'long long'
> to hold the difference, and pass that to llabs()?

Yeah, that SGTM. Thanks for the review!
-- 
Thanks,
~Nick Desaulniers

  reply	other threads:[~2021-11-05 20:51 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-05 16:31 [PATCH 1/2] selftests: timens: use 'llabs()' over 'abs()' Anders Roxell
2021-11-05 16:31 ` [PATCH 2/2] selftests: timens: exec: use 'labs()' " Anders Roxell
2021-11-05 20:35   ` Nick Desaulniers
2021-11-05 20:45     ` Arnd Bergmann
2021-11-05 20:50       ` Nick Desaulniers [this message]
2021-11-10 18:03       ` [PATCHv2] " Anders Roxell
2021-11-10 20:09         ` Nick Desaulniers
2021-11-10 20:11           ` Nick Desaulniers
2021-11-11  8:26             ` Anders Roxell
2021-11-05 20:26 ` [PATCH 1/2] selftests: timens: use 'llabs()' " Nick Desaulniers
2021-11-20  0:18   ` Shuah Khan

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='CAKwvOdm=a7w0cQdynY2i5ST=xrfjzXVZcUniAoEyqC21oKPQsQ@mail.gmail.com' \
    --to=ndesaulniers@google.com \
    --cc=anders.roxell@linaro.org \
    --cc=arnd@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=nathan@kernel.org \
    --cc=shuah@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 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.