Skip to content

Commit 16cab32

Browse files
committed
Revert "perf bench futex: Sanitize numeric parameters"
This reverts commit 60758d6. Now that libsubcmd makes sure that OPT_UINTEGER options will not return negative values, we can revert this patch while addressing the problem it solved: # perf bench futex hash -t -4 # Running 'futex/hash' benchmark: Error: switch `t' expects an unsigned numerical value Usage: perf bench futex hash <options> -t, --threads <n> Specify amount of threads # perf bench futex hash -t-4 # Running 'futex/hash' benchmark: Error: switch `t' expects an unsigned numerical value Usage: perf bench futex hash <options> -t, --threads <n> Specify amount of threads # IMO it is more reasonable to flat out refuse to process a negative number than to silently turn it into an absolute value. This also helps in silencing clang's complaint about asking for an absolute value of an unsigned integer: bench/futex-hash.c:133:10: error: taking the absolute value of unsigned type 'unsigned int' has no effect [-Werror,-Wabsolute-value] nsecs = futexbench_sanitize_numeric(nsecs); ^ bench/futex.h:104:42: note: expanded from macro 'futexbench_sanitize_numeric' #define futexbench_sanitize_numeric(__n) abs((__n)) ^ bench/futex-hash.c:133:10: note: remove the call to 'abs' since unsigned values cannot be negative Cc: Adrian Hunter <[email protected]> Cc: David Ahern <[email protected]> Cc: Davidlohr Bueso <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Josh Poimboeuf <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Wang Nan <[email protected]> Link: http://lkml.kernel.org/n/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent b988971 commit 16cab32

File tree

6 files changed

+0
-20
lines changed

6 files changed

+0
-20
lines changed

tools/perf/bench/futex-hash.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,13 @@ int bench_futex_hash(int argc, const char **argv,
130130
}
131131

132132
ncpus = sysconf(_SC_NPROCESSORS_ONLN);
133-
nsecs = futexbench_sanitize_numeric(nsecs);
134-
nfutexes = futexbench_sanitize_numeric(nfutexes);
135133

136134
sigfillset(&act.sa_mask);
137135
act.sa_sigaction = toggle_done;
138136
sigaction(SIGINT, &act, NULL);
139137

140138
if (!nthreads) /* default to the number of CPUs */
141139
nthreads = ncpus;
142-
else
143-
nthreads = futexbench_sanitize_numeric(nthreads);
144140

145141
worker = calloc(nthreads, sizeof(*worker));
146142
if (!worker)

tools/perf/bench/futex-lock-pi.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,13 @@ int bench_futex_lock_pi(int argc, const char **argv,
152152
goto err;
153153

154154
ncpus = sysconf(_SC_NPROCESSORS_ONLN);
155-
nsecs = futexbench_sanitize_numeric(nsecs);
156155

157156
sigfillset(&act.sa_mask);
158157
act.sa_sigaction = toggle_done;
159158
sigaction(SIGINT, &act, NULL);
160159

161160
if (!nthreads)
162161
nthreads = ncpus;
163-
else
164-
nthreads = futexbench_sanitize_numeric(nthreads);
165162

166163
worker = calloc(nthreads, sizeof(*worker));
167164
if (!worker)

tools/perf/bench/futex-requeue.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ int bench_futex_requeue(int argc, const char **argv,
128128

129129
if (!nthreads)
130130
nthreads = ncpus;
131-
else
132-
nthreads = futexbench_sanitize_numeric(nthreads);
133131

134132
worker = calloc(nthreads, sizeof(*worker));
135133
if (!worker)

tools/perf/bench/futex-wake-parallel.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,8 @@ int bench_futex_wake_parallel(int argc, const char **argv,
217217
sigaction(SIGINT, &act, NULL);
218218

219219
ncpus = sysconf(_SC_NPROCESSORS_ONLN);
220-
nwaking_threads = futexbench_sanitize_numeric(nwaking_threads);
221-
222220
if (!nblocked_threads)
223221
nblocked_threads = ncpus;
224-
else
225-
nblocked_threads = futexbench_sanitize_numeric(nblocked_threads);
226222

227223
/* some sanity checks */
228224
if (nwaking_threads > nblocked_threads || !nwaking_threads)

tools/perf/bench/futex-wake.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,13 @@ int bench_futex_wake(int argc, const char **argv,
129129
}
130130

131131
ncpus = sysconf(_SC_NPROCESSORS_ONLN);
132-
nwakes = futexbench_sanitize_numeric(nwakes);
133132

134133
sigfillset(&act.sa_mask);
135134
act.sa_sigaction = toggle_done;
136135
sigaction(SIGINT, &act, NULL);
137136

138137
if (!nthreads)
139138
nthreads = ncpus;
140-
else
141-
nthreads = futexbench_sanitize_numeric(nthreads);
142139

143140
worker = calloc(nthreads, sizeof(*worker));
144141
if (!worker)

tools/perf/bench/futex.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#ifndef _FUTEX_H
88
#define _FUTEX_H
99

10-
#include <stdlib.h>
1110
#include <unistd.h>
1211
#include <sys/syscall.h>
1312
#include <sys/types.h>
@@ -100,7 +99,4 @@ static inline int pthread_attr_setaffinity_np(pthread_attr_t *attr,
10099
}
101100
#endif
102101

103-
/* User input sanitation */
104-
#define futexbench_sanitize_numeric(__n) abs((__n))
105-
106102
#endif /* _FUTEX_H */

0 commit comments

Comments
 (0)