Commit 1e07900d authored by Jakub Kicinski's avatar Jakub Kicinski

Merge branch 'tools-ynl-fix-impossible-errors'

Jakub Kicinski says:

====================
tools: ynl: fix impossible errors

Fix bugs discovered while I was hacking in low level stuff in YNL
and kept breaking the socket, exercising the "impossible" error paths.

v1: https://lore.kernel.org/all/20240217001742.2466993-1-kuba@kernel.org/
====================

Link: https://lore.kernel.org/r/20240220161112.2735195-1-kuba@kernel.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents 9990889b 5d78b73e
...@@ -466,6 +466,8 @@ ynl_gemsg_start_dump(struct ynl_sock *ys, __u32 id, __u8 cmd, __u8 version) ...@@ -466,6 +466,8 @@ ynl_gemsg_start_dump(struct ynl_sock *ys, __u32 id, __u8 cmd, __u8 version)
int ynl_recv_ack(struct ynl_sock *ys, int ret) int ynl_recv_ack(struct ynl_sock *ys, int ret)
{ {
struct ynl_parse_arg yarg = { .ys = ys, };
if (!ret) { if (!ret) {
yerr(ys, YNL_ERROR_EXPECT_ACK, yerr(ys, YNL_ERROR_EXPECT_ACK,
"Expecting an ACK but nothing received"); "Expecting an ACK but nothing received");
...@@ -478,7 +480,7 @@ int ynl_recv_ack(struct ynl_sock *ys, int ret) ...@@ -478,7 +480,7 @@ int ynl_recv_ack(struct ynl_sock *ys, int ret)
return ret; return ret;
} }
return mnl_cb_run(ys->rx_buf, ret, ys->seq, ys->portid, return mnl_cb_run(ys->rx_buf, ret, ys->seq, ys->portid,
ynl_cb_null, ys); ynl_cb_null, &yarg);
} }
int ynl_cb_null(const struct nlmsghdr *nlh, void *data) int ynl_cb_null(const struct nlmsghdr *nlh, void *data)
...@@ -586,7 +588,13 @@ static int ynl_sock_read_family(struct ynl_sock *ys, const char *family_name) ...@@ -586,7 +588,13 @@ static int ynl_sock_read_family(struct ynl_sock *ys, const char *family_name)
return err; return err;
} }
return ynl_recv_ack(ys, err); err = ynl_recv_ack(ys, err);
if (err < 0) {
free(ys->mcast_groups);
return err;
}
return 0;
} }
struct ynl_sock * struct ynl_sock *
...@@ -741,11 +749,14 @@ static int ynl_ntf_parse(struct ynl_sock *ys, const struct nlmsghdr *nlh) ...@@ -741,11 +749,14 @@ static int ynl_ntf_parse(struct ynl_sock *ys, const struct nlmsghdr *nlh)
static int ynl_ntf_trampoline(const struct nlmsghdr *nlh, void *data) static int ynl_ntf_trampoline(const struct nlmsghdr *nlh, void *data)
{ {
return ynl_ntf_parse((struct ynl_sock *)data, nlh); struct ynl_parse_arg *yarg = data;
return ynl_ntf_parse(yarg->ys, nlh);
} }
int ynl_ntf_check(struct ynl_sock *ys) int ynl_ntf_check(struct ynl_sock *ys)
{ {
struct ynl_parse_arg yarg = { .ys = ys, };
ssize_t len; ssize_t len;
int err; int err;
...@@ -767,7 +778,7 @@ int ynl_ntf_check(struct ynl_sock *ys) ...@@ -767,7 +778,7 @@ int ynl_ntf_check(struct ynl_sock *ys)
return len; return len;
err = mnl_cb_run2(ys->rx_buf, len, ys->seq, ys->portid, err = mnl_cb_run2(ys->rx_buf, len, ys->seq, ys->portid,
ynl_ntf_trampoline, ys, ynl_ntf_trampoline, &yarg,
ynl_cb_array, NLMSG_MIN_TYPE); ynl_cb_array, NLMSG_MIN_TYPE);
if (err < 0) if (err < 0)
return err; return err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment