All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next v3 1/3] Add error returns to two API functions
@ 2022-04-19 16:03 grantseltzer
  2022-04-19 16:03 ` [PATCH bpf-next v3 2/3] Update API functions usage to check error grantseltzer
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: grantseltzer @ 2022-04-19 16:03 UTC (permalink / raw)
  To: bpf; +Cc: andrii, grantseltzer, song

From: Grant Seltzer <grantseltzer@gmail.com>

This adds an error return to the following API functions:

- bpf_program__set_expected_attach_type()
- bpf_program__set_type()

In both cases, the error occurs when the BPF object has
already been loaded when the function is called. In this
case -EBUSY is returned.

Signed-off-by: Grant Seltzer <grantseltzer@gmail.com>
---
 tools/lib/bpf/libbpf.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index bf4f7ac54ebf..0ed1a8c9c398 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -8551,8 +8551,11 @@ enum bpf_prog_type bpf_program__type(const struct bpf_program *prog)
 	return prog->type;
 }
 
-void bpf_program__set_type(struct bpf_program *prog, enum bpf_prog_type type)
+int bpf_program__set_type(struct bpf_program *prog, enum bpf_prog_type type)
 {
+	if (prog->obj->loaded)
+		return libbpf_err(-EBUSY);
+
 	prog->type = type;
 }
 
@@ -8598,10 +8601,14 @@ enum bpf_attach_type bpf_program__expected_attach_type(const struct bpf_program
 	return prog->expected_attach_type;
 }
 
-void bpf_program__set_expected_attach_type(struct bpf_program *prog,
+int bpf_program__set_expected_attach_type(struct bpf_program *prog,
 					   enum bpf_attach_type type)
 {
+	if (prog->obj->loaded)
+		return libbpf_err(-EBUSY);
+
 	prog->expected_attach_type = type;
+	return 0;
 }
 
 __u32 bpf_program__flags(const struct bpf_program *prog)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-04-20  8:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-19 16:03 [PATCH bpf-next v3 1/3] Add error returns to two API functions grantseltzer
2022-04-19 16:03 ` [PATCH bpf-next v3 2/3] Update API functions usage to check error grantseltzer
2022-04-20  5:35   ` Andrii Nakryiko
2022-04-19 16:03 ` [PATCH bpf-next v3 3/3] Add documentation to API functions grantseltzer
2022-04-20  5:42   ` Andrii Nakryiko
2022-04-20  8:23   ` kernel test robot
2022-04-20  5:32 ` [PATCH bpf-next v3 1/3] Add error returns to two " Andrii Nakryiko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.