Skip to content

Commit 2e59bfe

Browse files
geliangtangKernel Patches Daemon
authored andcommitted
selftests: bpf: drop duplicate max/min definitions
Drop duplicate macros min() and MAX() definitions in prog_tests, use MIN() or MAX() in sys/param.h instead. Signed-off-by: Geliang Tang <geliang.tang@suse.com>
1 parent 4385286 commit 2e59bfe

File tree

5 files changed

+5
-11
lines changed

5 files changed

+5
-11
lines changed

tools/testing/selftests/bpf/prog_tests/bpf_iter.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,8 +1192,6 @@ static void str_strip_first_line(char *str)
11921192
*dst = '\0';
11931193
}
11941194

1195-
#define min(a, b) ((a) < (b) ? (a) : (b))
1196-
11971195
static void test_task_vma(void)
11981196
{
11991197
int err, iter_fd = -1, proc_maps_fd = -1;
@@ -1229,7 +1227,7 @@ static void test_task_vma(void)
12291227
len = 0;
12301228
while (len < CMP_BUFFER_SIZE) {
12311229
err = read_fd_into_buffer(iter_fd, task_vma_output + len,
1232-
min(read_size, CMP_BUFFER_SIZE - len));
1230+
MIN(read_size, CMP_BUFFER_SIZE - len));
12331231
if (!err)
12341232
break;
12351233
if (CHECK(err < 0, "read_iter_fd", "read_iter_fd failed\n"))

tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
#include "bpf_tcp_nogpl.skel.h"
1111
#include "bpf_dctcp_release.skel.h"
1212

13-
#define min(a, b) ((a) < (b) ? (a) : (b))
14-
1513
#ifndef ENOTSUPP
1614
#define ENOTSUPP 524
1715
#endif
@@ -53,7 +51,7 @@ static void *server(void *arg)
5351

5452
while (bytes < total_bytes && !READ_ONCE(stop)) {
5553
nr_sent = send(fd, &batch,
56-
min(total_bytes - bytes, sizeof(batch)), 0);
54+
MIN(total_bytes - bytes, sizeof(batch)), 0);
5755
if (nr_sent == -1 && errno == EINTR)
5856
continue;
5957
if (nr_sent == -1) {
@@ -146,7 +144,7 @@ static void do_test(const char *tcp_ca, const struct bpf_map *sk_stg_map)
146144
/* recv total_bytes */
147145
while (bytes < total_bytes && !READ_ONCE(stop)) {
148146
nr_recv = recv(fd, &batch,
149-
min(total_bytes - bytes, sizeof(batch)), 0);
147+
MIN(total_bytes - bytes, sizeof(batch)), 0);
150148
if (nr_recv == -1 && errno == EINTR)
151149
continue;
152150
if (nr_recv == -1)

tools/testing/selftests/bpf/prog_tests/snprintf.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ static void test_snprintf_positive(void)
8383
test_snprintf__destroy(skel);
8484
}
8585

86-
#define min(a, b) ((a) < (b) ? (a) : (b))
87-
8886
/* Loads an eBPF object calling bpf_snprintf with up to 10 characters of fmt */
8987
static int load_single_snprintf(char *fmt)
9088
{
@@ -95,7 +93,7 @@ static int load_single_snprintf(char *fmt)
9593
if (!skel)
9694
return -EINVAL;
9795

98-
memcpy(skel->rodata->fmt, fmt, min(strlen(fmt) + 1, 10));
96+
memcpy(skel->rodata->fmt, fmt, MIN(strlen(fmt) + 1, 10));
9997

10098
ret = test_snprintf_single__load(skel);
10199
test_snprintf_single__destroy(skel);

tools/testing/selftests/bpf/prog_tests/tc_redirect.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,6 @@ static int tun_open(char *name)
949949
return -1;
950950
}
951951

952-
#define MAX(a, b) ((a) > (b) ? (a) : (b))
953952
enum {
954953
SRC_TO_TARGET = 0,
955954
TARGET_TO_SRC = 1,

tools/testing/selftests/bpf/test_progs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ typedef __u16 __sum16;
2525
#include <sys/wait.h>
2626
#include <sys/types.h>
2727
#include <sys/time.h>
28+
#include <sys/param.h>
2829
#include <fcntl.h>
2930
#include <pthread.h>
3031
#include <linux/bpf.h>

0 commit comments

Comments
 (0)