Skip to content

Commit 2eb57bb

Browse files
Jakub Kicinskiborkmann
authored andcommitted
tools: bpf: improve comments in libbpf.h
Fix spelling mistakes, improve and clarify the language of comments in libbpf.h. Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com> Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent d0cabbb commit 2eb57bb

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

tools/lib/bpf/libbpf.h

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ enum libbpf_errno {
5252
int libbpf_strerror(int err, char *buf, size_t size);
5353

5454
/*
55-
* In include/linux/compiler-gcc.h, __printf is defined. However
56-
* it should be better if libbpf.h doesn't depend on Linux header file.
55+
* __printf is defined in include/linux/compiler-gcc.h. However,
56+
* it would be better if libbpf.h didn't depend on Linux header files.
5757
* So instead of __printf, here we use gcc attribute directly.
5858
*/
5959
typedef int (*libbpf_print_fn_t)(const char *, ...)
@@ -92,7 +92,7 @@ int bpf_object__set_priv(struct bpf_object *obj, void *priv,
9292
bpf_object_clear_priv_t clear_priv);
9393
void *bpf_object__priv(struct bpf_object *prog);
9494

95-
/* Accessors of bpf_program. */
95+
/* Accessors of bpf_program */
9696
struct bpf_program;
9797
struct bpf_program *bpf_program__next(struct bpf_program *prog,
9898
struct bpf_object *obj);
@@ -121,28 +121,28 @@ struct bpf_insn;
121121

122122
/*
123123
* Libbpf allows callers to adjust BPF programs before being loaded
124-
* into kernel. One program in an object file can be transform into
125-
* multiple variants to be attached to different code.
124+
* into kernel. One program in an object file can be transformed into
125+
* multiple variants to be attached to different hooks.
126126
*
127127
* bpf_program_prep_t, bpf_program__set_prep and bpf_program__nth_fd
128-
* are APIs for this propose.
128+
* form an API for this purpose.
129129
*
130130
* - bpf_program_prep_t:
131-
* It defines 'preprocessor', which is a caller defined function
131+
* Defines a 'preprocessor', which is a caller defined function
132132
* passed to libbpf through bpf_program__set_prep(), and will be
133133
* called before program is loaded. The processor should adjust
134-
* the program one time for each instances according to the number
134+
* the program one time for each instance according to the instance id
135135
* passed to it.
136136
*
137137
* - bpf_program__set_prep:
138-
* Attachs a preprocessor to a BPF program. The number of instances
139-
* whould be created is also passed through this function.
138+
* Attaches a preprocessor to a BPF program. The number of instances
139+
* that should be created is also passed through this function.
140140
*
141141
* - bpf_program__nth_fd:
142-
* After the program is loaded, get resuling fds from bpf program for
143-
* each instances.
142+
* After the program is loaded, get resulting FD of a given instance
143+
* of the BPF program.
144144
*
145-
* If bpf_program__set_prep() is not used, the program whould be loaded
145+
* If bpf_program__set_prep() is not used, the program would be loaded
146146
* without adjustment during bpf_object__load(). The program has only
147147
* one instance. In this case bpf_program__fd(prog) is equal to
148148
* bpf_program__nth_fd(prog, 0).
@@ -156,7 +156,7 @@ struct bpf_prog_prep_result {
156156
struct bpf_insn *new_insn_ptr;
157157
int new_insn_cnt;
158158

159-
/* If not NULL, result fd is set to it */
159+
/* If not NULL, result FD is written to it. */
160160
int *pfd;
161161
};
162162

@@ -169,8 +169,8 @@ struct bpf_prog_prep_result {
169169
* - res: Output parameter, result of transformation.
170170
*
171171
* Return value:
172-
* - Zero: pre-processing success.
173-
* - Non-zero: pre-processing, stop loading.
172+
* - Zero: pre-processing success.
173+
* - Non-zero: pre-processing error, stop loading.
174174
*/
175175
typedef int (*bpf_program_prep_t)(struct bpf_program *prog, int n,
176176
struct bpf_insn *insns, int insns_cnt,
@@ -182,7 +182,7 @@ int bpf_program__set_prep(struct bpf_program *prog, int nr_instance,
182182
int bpf_program__nth_fd(struct bpf_program *prog, int n);
183183

184184
/*
185-
* Adjust type of bpf program. Default is kprobe.
185+
* Adjust type of BPF program. Default is kprobe.
186186
*/
187187
int bpf_program__set_socket_filter(struct bpf_program *prog);
188188
int bpf_program__set_tracepoint(struct bpf_program *prog);
@@ -206,10 +206,10 @@ bool bpf_program__is_xdp(struct bpf_program *prog);
206206
bool bpf_program__is_perf_event(struct bpf_program *prog);
207207

208208
/*
209-
* We don't need __attribute__((packed)) now since it is
210-
* unnecessary for 'bpf_map_def' because they are all aligned.
211-
* In addition, using it will trigger -Wpacked warning message,
212-
* and will be treated as an error due to -Werror.
209+
* No need for __attribute__((packed)), all members of 'bpf_map_def'
210+
* are all aligned. In addition, using __attribute__((packed))
211+
* would trigger a -Wpacked warning message, and lead to an error
212+
* if -Werror is set.
213213
*/
214214
struct bpf_map_def {
215215
unsigned int type;
@@ -220,16 +220,16 @@ struct bpf_map_def {
220220
};
221221

222222
/*
223-
* There is another 'struct bpf_map' in include/linux/map.h. However,
224-
* it is not a uapi header so no need to consider name clash.
223+
* The 'struct bpf_map' in include/linux/bpf.h is internal to the kernel,
224+
* so no need to worry about a name clash.
225225
*/
226226
struct bpf_map;
227227
struct bpf_map *
228228
bpf_object__find_map_by_name(struct bpf_object *obj, const char *name);
229229

230230
/*
231231
* Get bpf_map through the offset of corresponding struct bpf_map_def
232-
* in the bpf object file.
232+
* in the BPF object file.
233233
*/
234234
struct bpf_map *
235235
bpf_object__find_map_by_offset(struct bpf_object *obj, size_t offset);

0 commit comments

Comments
 (0)