Skip to content

Commit

Permalink
perf jevents: Fix getting maximum number of fds
Browse files Browse the repository at this point in the history
commit 75ea44e356b5de8c817f821c9dd68ae329e82add upstream.

On some hosts, rlim.rlim_max can be returned as RLIM_INFINITY.
By casting it to int, it is interpreted as -1, which will cause get_maxfds
to return 0, causing "Invalid argument" errors in nftw() calls.
Fix this by casting the second argument of min() to rlim_t instead.

Fixes: 80eeb67 ("perf jevents: Program to convert JSON file")
Signed-off-by: Felix Fietkau <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Sukadev Bhattiprolu <[email protected]>
Link: http://lore.kernel.org/lkml/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
nbd168 authored and gregkh committed Jun 3, 2021
1 parent c70e1ba commit 7551304
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tools/perf/pmu-events/jevents.c
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ static int get_maxfds(void)
struct rlimit rlim;

if (getrlimit(RLIMIT_NOFILE, &rlim) == 0)
return min((int)rlim.rlim_max / 2, 512);
return min(rlim.rlim_max / 2, (rlim_t)512);

return 512;
}
Expand Down

0 comments on commit 7551304

Please sign in to comment.