git: 794517a0f379 - stable/14 - netlink: Don't use a zero-length array
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 08 Apr 2024 19:04:38 UTC
The branch stable/14 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=794517a0f3794131d79e3c9d0c12fcceb840ae80 commit 794517a0f3794131d79e3c9d0c12fcceb840ae80 Author: John Baldwin <jhb@FreeBSD.org> AuthorDate: 2024-02-27 19:59:52 +0000 Commit: John Baldwin <jhb@FreeBSD.org> CommitDate: 2024-04-08 17:58:16 +0000 netlink: Don't use a zero-length array Define SNL_DECLARE_FIELD_PARSER* macros to create a parser that has no output attributes only input fields and use this to define the snl_donemsg_parser. This removes the need for the zero-length nla_p_donemsg[] variable. Zero length arrays are not valid in ISO C. Reviewed by: jrtc27, melifaro Differential Revision: https://reviews.freebsd.org/D43918 (cherry picked from commit 69945c49fea7ac2352c1fd7d22f70f2e3861ba81) --- sys/netlink/netlink_snl.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/sys/netlink/netlink_snl.h b/sys/netlink/netlink_snl.h index 7bdf5424ddf3..f8387132f78a 100644 --- a/sys/netlink/netlink_snl.h +++ b/sys/netlink/netlink_snl.h @@ -174,6 +174,18 @@ static const struct snl_hdr_parser _name = { \ #define SNL_DECLARE_PARSER(_name, _t, _fp, _np) \ SNL_DECLARE_PARSER_EXT(_name, sizeof(_t), 0, _fp, _np, NULL) +#define SNL_DECLARE_FIELD_PARSER_EXT(_name, _sz_h_in, _sz_out, _fp, _cb) \ +static const struct snl_hdr_parser _name = { \ + .in_hdr_size = _sz_h_in, \ + .out_size = _sz_out, \ + .fp = &((_fp)[0]), \ + .fp_size = NL_ARRAY_LEN(_fp), \ + .cb_post = _cb, \ +} + +#define SNL_DECLARE_FIELD_PARSER(_name, _t, _fp) \ + SNL_DECLARE_FIELD_PARSER_EXT(_name, sizeof(_t), 0, _fp, NULL) + #define SNL_DECLARE_ATTR_PARSER_EXT(_name, _sz_out, _np, _cb) \ static const struct snl_hdr_parser _name = { \ .out_size = _sz_out, \ @@ -909,14 +921,12 @@ SNL_DECLARE_PARSER(snl_errmsg_parser, struct nlmsgerr, nlf_p_errmsg, nla_p_errms #define _IN(_field) offsetof(struct nlmsgerr, _field) #define _OUT(_field) offsetof(struct snl_errmsg_data, _field) -static const struct snl_attr_parser nla_p_donemsg[] = {}; - static const struct snl_field_parser nlf_p_donemsg[] = { { .off_in = _IN(error), .off_out = _OUT(error), .cb = snl_field_get_uint32 }, }; #undef _IN #undef _OUT -SNL_DECLARE_PARSER(snl_donemsg_parser, struct nlmsgerr, nlf_p_donemsg, nla_p_donemsg); +SNL_DECLARE_FIELD_PARSER(snl_donemsg_parser, struct nlmsgerr, nlf_p_donemsg); static inline bool snl_parse_errmsg(struct snl_state *ss, struct nlmsghdr *hdr, struct snl_errmsg_data *e)