Skip to content

Commit

Permalink
netlink: Don't use a zero-length array
Browse files Browse the repository at this point in the history
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 69945c4)
  • Loading branch information
bsdjhb committed Feb 27, 2024
1 parent 75fad83 commit 7bb1cfa
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions sys/netlink/netlink_snl.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,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, \
Expand Down Expand Up @@ -917,14 +929,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)
Expand Down

0 comments on commit 7bb1cfa

Please sign in to comment.