From: Anders Roxell <anders.roxell@linaro.org>
To: shuah@kernel.org, christian@brauner.io
Cc: nathan@kernel.org, ndesaulniers@google.com,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
llvm@lists.linux.dev, Anders Roxell <anders.roxell@linaro.org>
Subject: [PATCH 2/2] selftests: cgroup: use function 'labs()' over 'abs()'
Date: Fri, 5 Nov 2021 17:25:30 +0100 [thread overview]
Message-ID: <20211105162530.3307666-2-anders.roxell@linaro.org> (raw)
In-Reply-To: <20211105162530.3307666-1-anders.roxell@linaro.org>
When building selftests/cgroup with clang, the compiler warn about the
function abs() see below:
In file included from test_memcontrol.c:21:
./cgroup_util.h:16:9: warning: absolute value function 'abs' given an argument of type 'long' but has parameter of type 'int' which may cause truncation of value [-Wabsolute-value]
return abs(a - b) <= (a + b) / 100 * err;
^
./cgroup_util.h:16:9: note: use function 'labs' instead
return abs(a - b) <= (a + b) / 100 * err;
^~~
labs
The note indicates what to do, Rework to use the function 'labs()'.
Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
---
tools/testing/selftests/cgroup/cgroup_util.h | 2 +-
tools/testing/selftests/cgroup/test_kmem.c | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/cgroup/cgroup_util.h b/tools/testing/selftests/cgroup/cgroup_util.h
index 82e59cdf16e7..76b35d9dffb5 100644
--- a/tools/testing/selftests/cgroup/cgroup_util.h
+++ b/tools/testing/selftests/cgroup/cgroup_util.h
@@ -13,7 +13,7 @@
*/
static inline int values_close(long a, long b, int err)
{
- return abs(a - b) <= (a + b) / 100 * err;
+ return labs(a - b) <= (a + b) / 100 * err;
}
extern int cg_find_unified_root(char *root, size_t len);
diff --git a/tools/testing/selftests/cgroup/test_kmem.c b/tools/testing/selftests/cgroup/test_kmem.c
index 22b31ebb3513..d65bb8fe876a 100644
--- a/tools/testing/selftests/cgroup/test_kmem.c
+++ b/tools/testing/selftests/cgroup/test_kmem.c
@@ -192,7 +192,7 @@ static int test_kmem_memcg_deletion(const char *root)
goto cleanup;
sum = slab + anon + file + kernel_stack + pagetables + percpu + sock;
- if (abs(sum - current) < MAX_VMSTAT_ERROR) {
+ if (labs(sum - current) < MAX_VMSTAT_ERROR) {
ret = KSFT_PASS;
} else {
printf("memory.current = %ld\n", current);
@@ -383,7 +383,7 @@ static int test_percpu_basic(const char *root)
current = cg_read_long(parent, "memory.current");
percpu = cg_read_key_long(parent, "memory.stat", "percpu ");
- if (current > 0 && percpu > 0 && abs(current - percpu) <
+ if (current > 0 && percpu > 0 && labs(current - percpu) <
MAX_VMSTAT_ERROR)
ret = KSFT_PASS;
else
--
2.33.0
next prev parent reply other threads:[~2021-11-05 16:25 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-05 16:25 [PATCH 1/2] selftests: cgroup: build error multiple outpt files Anders Roxell
2021-11-05 16:25 ` Anders Roxell [this message]
2021-11-05 20:15 ` [PATCH 2/2] selftests: cgroup: use function 'labs()' over 'abs()' Nick Desaulniers
2021-11-09 15:02 ` Christian Brauner
2021-11-05 20:10 ` [PATCH 1/2] selftests: cgroup: build error multiple outpt files Nick Desaulniers
2021-11-09 15:01 ` Christian Brauner
2021-11-20 0:22 ` Shuah Khan
2021-11-23 14:26 ` Christian Brauner
2021-11-30 16:41 ` Shuah Khan
2021-12-01 13:06 ` Christian Brauner
2021-12-03 17:08 ` 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=20211105162530.3307666-2-anders.roxell@linaro.org \
--to=anders.roxell@linaro.org \
--cc=christian@brauner.io \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--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.