Skip to contentSkip to conversation

tools: ynl: add ynl_dump_empty() helper

PATCH Applied Jakub Kicinski 3 participants 3 messages Mar 29, 2024 – Apr 3, 2024

Subsystems (3)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH 1/1 tools: ynl: add ynl_dump_empty() helper

Checking if dump is empty requires a couple of casts. Add a convenient wrapper.

Add an example use in the netdev sample, loopback is always present so an empty dump is an error.

---
CC: [email protected]
CC: [email protected]

---
 tools/net/ynl/lib/ynl.h        | 12 ++++++++++++
 tools/net/ynl/samples/netdev.c |  2 ++
 2 files changed, 14 insertions(+)
tools/net/ynl/lib/ynl.h +12 -0
index 9842e85a8c57..eef7c6324ed4 100644
@@ -91,6 +91,18 @@ void ynl_sock_destroy(struct ynl_sock *ys);
 	     !ynl_dump_obj_is_last(iter);				\
 	     iter = ynl_dump_obj_next(iter))
 
+/**
+ * ynl_dump_empty() - does the dump have no entries
+ * @dump: pointer to the dump list, as returned by a dump call
+ *
+ * Check if the dump is empty, i.e. contains no objects.
+ * Dump calls return NULL on error, and terminator element if empty.
+ */
+static inline bool ynl_dump_empty(void *dump)
+{
+	return dump == (void *)YNL_LIST_END;
+}
+
 int ynl_subscribe(struct ynl_sock *ys, const char *grp_name);
 int ynl_socket_get_fd(struct ynl_sock *ys);
 int ynl_ntf_check(struct ynl_sock *ys);
tools/net/ynl/samples/netdev.c +2 -0
index 591b90e21890..3e7b29bd55d5 100644
@@ -100,6 +100,8 @@ int main(int argc, char **argv)
 		if (!devs)
 			goto err_close;
 
+		if (ynl_dump_empty(devs))
+			fprintf(stderr, "Error: no devices reported\n");
 		ynl_dump_foreach(devs, d)
 			netdev_print_device(d, 0);
 		netdev_dev_get_list_free(devs);
Signature · 1 line
2.44.0
#2 lore raw
In reply to Jakub Kicinski
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Fri, 29 Mar 2024 11:16:51 -0700 you wrote:

Checking if dump is empty requires a couple of casts. Add a convenient wrapper.

Add an example use in the netdev sample, loopback is always present so an empty dump is an error.

[...]

Here is the summary with links:
- [net-next] tools: ynl: add ynl_dump_empty() helper

    https://git.kernel.org/netdev/net-next/c/d6d647d7ba64

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html