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 | 18 | #include "perf-sys.h" |
| 19 | 19 | #include "trace_helpers.h" |
| 20 | 20 | |
| 21 | −#define __must_check | |
| 22 | −#include <linux/err.h> | |
| 23 | − | |
| 24 | 21 | #define DEFAULT_FREQ 99 |
| 25 | 22 | #define DEFAULT_SECS 5 |
| 26 | 23 | #define MAX_IPS 8192 |
| @@ -57,7 +54,7 @@ static int sampling_start(int freq, struct bpf_program *prog, · 30 unmodified lines | ||
| 57 | 54 | return 1; |
| 58 | 55 | } |
| 59 | 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 | 58 | fprintf(stderr, "ERROR: Attach perf event\n"); |
| 62 | 59 | links[i] = NULL; |
| 63 | 60 | close(pmu_fd); |
| @@ -182,7 +179,7 @@ int main(int argc, char **argv) · 118 unmodified lines | ||
| 182 | 179 | |
| 183 | 180 | snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); |
| 184 | 181 | obj = bpf_object__open_file(filename, NULL); |
| 185 | − if (IS_ERR(obj)) { | |
| 182 | + if (libbpf_get_error(obj)) { | |
| 186 | 183 | fprintf(stderr, "ERROR: opening BPF object file failed\n"); |
| 187 | 184 | obj = NULL; |
| 188 | 185 | goto cleanup; |
| @@ -16,9 +16,6 @@ · 15 unmodified lines | ||
| 16 | 16 | #include "perf-sys.h" |
| 17 | 17 | #include "trace_helpers.h" |
| 18 | 18 | |
| 19 | −#define __must_check | |
| 20 | −#include <linux/err.h> | |
| 21 | − | |
| 22 | 19 | #define SAMPLE_FREQ 50 |
| 23 | 20 | |
| 24 | 21 | static int pid; |
| @@ -159,7 +156,7 @@ static void test_perf_event_all_cpu(struct perf_event_attr *attr) · 134 unmodified lines | ||
| 159 | 156 | goto all_cpu_err; |
| 160 | 157 | } |
| 161 | 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 | 160 | printf("bpf_program__attach_perf_event failed\n"); |
| 164 | 161 | links[i] = NULL; |
| 165 | 162 | close(pmu_fd); |
| @@ -198,7 +195,7 @@ static void test_perf_event_task(struct perf_event_attr *attr) · 32 unmodified lines | ||
| 198 | 195 | goto err; |
| 199 | 196 | } |
| 200 | 197 | link = bpf_program__attach_perf_event(prog, pmu_fd); |
| 201 | − if (IS_ERR(link)) { | |
| 198 | + if (libbpf_get_error(link)) { | |
| 202 | 199 | printf("bpf_program__attach_perf_event failed\n"); |
| 203 | 200 | link = NULL; |
| 204 | 201 | close(pmu_fd); |
| @@ -314,7 +311,7 @@ int main(int argc, char **argv) · 109 unmodified lines | ||
| 314 | 311 | } |
| 315 | 312 | |
| 316 | 313 | obj = bpf_object__open_file(filename, NULL); |
| 317 | − if (IS_ERR(obj)) { | |
| 314 | + if (libbpf_get_error(obj)) { | |
| 318 | 315 | printf("opening BPF object file failed\n"); |
| 319 | 316 | obj = NULL; |
| 320 | 317 | goto cleanup; |
| @@ -19,9 +19,6 @@ static const char *__doc__ = · 18 unmodified lines | ||
| 19 | 19 | #include <time.h> |
| 20 | 20 | #include <linux/limits.h> |
| 21 | 21 | |
| 22 | −#define __must_check | |
| 23 | −#include <linux/err.h> | |
| 24 | − | |
| 25 | 22 | #include <arpa/inet.h> |
| 26 | 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 | 621 | link = bpf_program__attach_tracepoint(prog, tp_category, tp_name); |
| 625 | − if (IS_ERR(link)) | |
| 622 | + if (libbpf_get_error(link)) | |
| 626 | 623 | exit(EXIT_FAIL_BPF); |
| 627 | 624 | |
| 628 | 625 | return link; |