Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf bpf-utils: Constify bpil_array_desc

The array's contents is a compile time constant. Constify to make the
code more intention revealing and avoid unintended errors.

Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20250902181713.309797-3-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Ian Rogers and committed by
Namhyung Kim
1654a0e4 d7b67dd6

+6 -12
+6 -12
tools/perf/util/bpf-utils.c
··· 20 20 */ 21 21 }; 22 22 23 - static struct bpil_array_desc bpil_array_desc[] = { 23 + static const struct bpil_array_desc bpil_array_desc[] = { 24 24 [PERF_BPIL_JITED_INSNS] = { 25 25 offsetof(struct bpf_prog_info, jited_prog_insns), 26 26 offsetof(struct bpf_prog_info, jited_prog_len), ··· 129 129 130 130 /* step 2: calculate total size of all arrays */ 131 131 for (i = PERF_BPIL_FIRST_ARRAY; i < PERF_BPIL_LAST_ARRAY; ++i) { 132 + const struct bpil_array_desc *desc = &bpil_array_desc[i]; 132 133 bool include_array = (arrays & (1UL << i)) > 0; 133 - struct bpil_array_desc *desc; 134 134 __u32 count, size; 135 - 136 - desc = bpil_array_desc + i; 137 135 138 136 /* kernel is too old to support this field */ 139 137 if (info_len < desc->array_offset + sizeof(__u32) || ··· 161 163 ptr = info_linear->data; 162 164 163 165 for (i = PERF_BPIL_FIRST_ARRAY; i < PERF_BPIL_LAST_ARRAY; ++i) { 164 - struct bpil_array_desc *desc; 166 + const struct bpil_array_desc *desc = &bpil_array_desc[i]; 165 167 __u32 count, size; 166 168 167 169 if ((arrays & (1UL << i)) == 0) 168 170 continue; 169 171 170 - desc = bpil_array_desc + i; 171 172 count = bpf_prog_info_read_offset_u32(&info, desc->count_offset); 172 173 size = bpf_prog_info_read_offset_u32(&info, desc->size_offset); 173 174 bpf_prog_info_set_offset_u32(&info_linear->info, ··· 189 192 190 193 /* step 6: verify the data */ 191 194 for (i = PERF_BPIL_FIRST_ARRAY; i < PERF_BPIL_LAST_ARRAY; ++i) { 192 - struct bpil_array_desc *desc; 195 + const struct bpil_array_desc *desc = &bpil_array_desc[i]; 193 196 __u32 v1, v2; 194 197 195 198 if ((arrays & (1UL << i)) == 0) 196 199 continue; 197 200 198 - desc = bpil_array_desc + i; 199 201 v1 = bpf_prog_info_read_offset_u32(&info, desc->count_offset); 200 202 v2 = bpf_prog_info_read_offset_u32(&info_linear->info, 201 203 desc->count_offset); ··· 220 224 int i; 221 225 222 226 for (i = PERF_BPIL_FIRST_ARRAY; i < PERF_BPIL_LAST_ARRAY; ++i) { 223 - struct bpil_array_desc *desc; 227 + const struct bpil_array_desc *desc = &bpil_array_desc[i]; 224 228 __u64 addr, offs; 225 229 226 230 if ((info_linear->arrays & (1UL << i)) == 0) 227 231 continue; 228 232 229 - desc = bpil_array_desc + i; 230 233 addr = bpf_prog_info_read_offset_u64(&info_linear->info, 231 234 desc->array_offset); 232 235 offs = addr - ptr_to_u64(info_linear->data); ··· 239 244 int i; 240 245 241 246 for (i = PERF_BPIL_FIRST_ARRAY; i < PERF_BPIL_LAST_ARRAY; ++i) { 242 - struct bpil_array_desc *desc; 247 + const struct bpil_array_desc *desc = &bpil_array_desc[i]; 243 248 __u64 addr, offs; 244 249 245 250 if ((info_linear->arrays & (1UL << i)) == 0) 246 251 continue; 247 252 248 - desc = bpil_array_desc + i; 249 253 offs = bpf_prog_info_read_offset_u64(&info_linear->info, 250 254 desc->array_offset); 251 255 addr = offs + ptr_to_u64(info_linear->data);