hc
2024-05-16 8d2a02b24d66aa359e83eebc1ed3c0f85367a1cb
kernel/tools/perf/trace/beauty/pkey_alloc.c
....@@ -1,40 +1,36 @@
1
+// SPDX-License-Identifier: LGPL-2.1
12 /*
23 * trace/beauty/pkey_alloc.c
34 *
45 * Copyright (C) 2017, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
5
- *
6
- * Released under the GPL v2. (and only v2, not any later version)
76 */
87
98 #include "trace/beauty/beauty.h"
109 #include <linux/kernel.h>
1110 #include <linux/log2.h>
1211
13
-static size_t pkey_alloc__scnprintf_access_rights(int access_rights, char *bf, size_t size)
12
+size_t strarray__scnprintf_flags(struct strarray *sa, char *bf, size_t size, bool show_prefix, unsigned long flags)
1413 {
1514 int i, printed = 0;
1615
17
-#include "trace/beauty/generated/pkey_alloc_access_rights_array.c"
18
- static DEFINE_STRARRAY(pkey_alloc_access_rights);
19
-
20
- if (access_rights == 0) {
21
- const char *s = strarray__pkey_alloc_access_rights.entries[0];
16
+ if (flags == 0) {
17
+ const char *s = sa->entries[0];
2218 if (s)
23
- return scnprintf(bf, size, "%s", s);
19
+ return scnprintf(bf, size, "%s%s", show_prefix ? sa->prefix : "", s);
2420 return scnprintf(bf, size, "%d", 0);
2521 }
2622
27
- for (i = 1; i < strarray__pkey_alloc_access_rights.nr_entries; ++i) {
28
- int bit = 1 << (i - 1);
23
+ for (i = 1; i < sa->nr_entries; ++i) {
24
+ unsigned long bit = 1UL << (i - 1);
2925
30
- if (!(access_rights & bit))
26
+ if (!(flags & bit))
3127 continue;
3228
3329 if (printed != 0)
3430 printed += scnprintf(bf + printed, size - printed, "|");
3531
36
- if (strarray__pkey_alloc_access_rights.entries[i] != NULL)
37
- printed += scnprintf(bf + printed, size - printed, "%s", strarray__pkey_alloc_access_rights.entries[i]);
32
+ if (sa->entries[i] != NULL)
33
+ printed += scnprintf(bf + printed, size - printed, "%s%s", show_prefix ? sa->prefix : "", sa->entries[i]);
3834 else
3935 printed += scnprintf(bf + printed, size - printed, "0x%#", bit);
4036 }
....@@ -42,9 +38,17 @@
4238 return printed;
4339 }
4440
41
+static size_t pkey_alloc__scnprintf_access_rights(int access_rights, char *bf, size_t size, bool show_prefix)
42
+{
43
+#include "trace/beauty/generated/pkey_alloc_access_rights_array.c"
44
+ static DEFINE_STRARRAY(pkey_alloc_access_rights, "PKEY_");
45
+
46
+ return strarray__scnprintf_flags(&strarray__pkey_alloc_access_rights, bf, size, show_prefix, access_rights);
47
+}
48
+
4549 size_t syscall_arg__scnprintf_pkey_alloc_access_rights(char *bf, size_t size, struct syscall_arg *arg)
4650 {
4751 unsigned long cmd = arg->val;
4852
49
- return pkey_alloc__scnprintf_access_rights(cmd, bf, size);
53
+ return pkey_alloc__scnprintf_access_rights(cmd, bf, size, arg->show_string_prefix);
5054 }