Current method of checking pointer error is not user friendly. Especially the __must_check define makes this less intuitive. Since, libbpf has an API libbpf_get_error() which checks pointer error, this commit refactors existing pointer error check logic with libbpf.
Showing the changes to samples (3 of 3 files). Show all
Unified · Split
| @@ -18,9 +18,6 @@ · 17 unmodified lines | |||
| 18 | #include "perf-sys.h" | 18 | #include "perf-sys.h" |
| 19 | #include "trace_helpers.h" | 19 | #include "trace_helpers.h" |
| 20 | 20 | ||
| 21 | #define __must_check | ||
| 22 | #include <linux/err.h> | ||
| 23 | |||
| 24 | #define DEFAULT_FREQ 99 | 21 | #define DEFAULT_FREQ 99 |
| 25 | #define DEFAULT_SECS 5 | 22 | #define DEFAULT_SECS 5 |
| 26 | #define MAX_IPS 8192 | 23 | #define MAX_IPS 8192 |
| @@ -57,7 +54,7 @@ static int sampling_start(int freq, struct bpf_program *prog, · 30 unmodified lines | |||
| 57 | return 1; | 54 | return 1; |
| 58 | } | 55 | } |
| 59 | links[i] = bpf_program__attach_perf_event(prog, pmu_fd); | 56 | links[i] = bpf_program__attach_perf_event(prog, pmu_fd); |
| 60 | if (IS_ERR(links[i])) { | 57 | if (libbpf_get_error(links[i])) { |
| 61 | fprintf(stderr, "ERROR: Attach perf event\n"); | 58 | fprintf(stderr, "ERROR: Attach perf event\n"); |
| 62 | links[i] = NULL; | 59 | links[i] = NULL; |
| 63 | close(pmu_fd); | 60 | close(pmu_fd); |
| @@ -182,7 +179,7 @@ int main(int argc, char **argv) · 118 unmodified lines | |||
| 182 | 179 | ||
| 183 | snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); | 180 | snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); |
| 184 | obj = bpf_object__open_file(filename, NULL); | 181 | obj = bpf_object__open_file(filename, NULL); |
| 185 | if (IS_ERR(obj)) { | 182 | if (libbpf_get_error(obj)) { |
| 186 | fprintf(stderr, "ERROR: opening BPF object file failed\n"); | 183 | fprintf(stderr, "ERROR: opening BPF object file failed\n"); |
| 187 | obj = NULL; | 184 | obj = NULL; |
| 188 | goto cleanup; | 185 | goto cleanup; |
| @@ -16,9 +16,6 @@ · 15 unmodified lines | |||
| 16 | #include "perf-sys.h" | 16 | #include "perf-sys.h" |
| 17 | #include "trace_helpers.h" | 17 | #include "trace_helpers.h" |
| 18 | 18 | ||
| 19 | #define __must_check | ||
| 20 | #include <linux/err.h> | ||
| 21 | |||
| 22 | #define SAMPLE_FREQ 50 | 19 | #define SAMPLE_FREQ 50 |
| 23 | 20 | ||
| 24 | static int pid; | 21 | static int pid; |
| @@ -159,7 +156,7 @@ static void test_perf_event_all_cpu(struct perf_event_attr *attr) · 134 unmodified lines | |||
| 159 | goto all_cpu_err; | 156 | goto all_cpu_err; |
| 160 | } | 157 | } |
| 161 | links[i] = bpf_program__attach_perf_event(prog, pmu_fd); | 158 | links[i] = bpf_program__attach_perf_event(prog, pmu_fd); |
| 162 | if (IS_ERR(links[i])) { | 159 | if (libbpf_get_error(links[i])) { |
| 163 | printf("bpf_program__attach_perf_event failed\n"); | 160 | printf("bpf_program__attach_perf_event failed\n"); |
| 164 | links[i] = NULL; | 161 | links[i] = NULL; |
| 165 | close(pmu_fd); | 162 | close(pmu_fd); |
| @@ -198,7 +195,7 @@ static void test_perf_event_task(struct perf_event_attr *attr) · 32 unmodified lines | |||
| 198 | goto err; | 195 | goto err; |
| 199 | } | 196 | } |
| 200 | link = bpf_program__attach_perf_event(prog, pmu_fd); | 197 | link = bpf_program__attach_perf_event(prog, pmu_fd); |
| 201 | if (IS_ERR(link)) { | 198 | if (libbpf_get_error(link)) { |
| 202 | printf("bpf_program__attach_perf_event failed\n"); | 199 | printf("bpf_program__attach_perf_event failed\n"); |
| 203 | link = NULL; | 200 | link = NULL; |
| 204 | close(pmu_fd); | 201 | close(pmu_fd); |
| @@ -314,7 +311,7 @@ int main(int argc, char **argv) · 109 unmodified lines | |||
| 314 | } | 311 | } |
| 315 | 312 | ||
| 316 | obj = bpf_object__open_file(filename, NULL); | 313 | obj = bpf_object__open_file(filename, NULL); |
| 317 | if (IS_ERR(obj)) { | 314 | if (libbpf_get_error(obj)) { |
| 318 | printf("opening BPF object file failed\n"); | 315 | printf("opening BPF object file failed\n"); |
| 319 | obj = NULL; | 316 | obj = NULL; |
| 320 | goto cleanup; | 317 | goto cleanup; |
| @@ -19,9 +19,6 @@ static const char *__doc__ = · 18 unmodified lines | |||
| 19 | #include <time.h> | 19 | #include <time.h> |
| 20 | #include <linux/limits.h> | 20 | #include <linux/limits.h> |
| 21 | 21 | ||
| 22 | #define __must_check | ||
| 23 | #include <linux/err.h> | ||
| 24 | |||
| 25 | #include <arpa/inet.h> | 22 | #include <arpa/inet.h> |
| 26 | #include <linux/if_link.h> | 23 | #include <linux/if_link.h> |
| 27 | 24 | ||
| @@ -622,7 +619,7 @@ static struct bpf_link * attach_tp(struct bpf_object *obj, · 594 unmodified lines | |||
| 622 | } | 619 | } |
| 623 | 620 | ||
| 624 | link = bpf_program__attach_tracepoint(prog, tp_category, tp_name); | 621 | link = bpf_program__attach_tracepoint(prog, tp_category, tp_name); |
| 625 | if (IS_ERR(link)) | 622 | if (libbpf_get_error(link)) |
| 626 | exit(EXIT_FAIL_BPF); | 623 | exit(EXIT_FAIL_BPF); |
| 627 | 624 | ||
| 628 | return link; | 625 | return link; |