Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools: ynl: make user space policies const

Dan, who's working on C++ YNL, pointed out that the C code
does not make policies const. Sprinkle some 'const's around.

Reported-by: Dan Melnic <dmm@meta.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Reviewed-by: Donald Hunter <donald.hunter@gmail.com>
Reviewed-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Jakub Kicinski and committed by
David S. Miller
924ee531 3e61103b

+13 -13
+4 -4
tools/net/ynl/lib/ynl-priv.h
··· 45 45 enum ynl_policy_type type; 46 46 unsigned int len; 47 47 const char *name; 48 - struct ynl_policy_nest *nest; 48 + const struct ynl_policy_nest *nest; 49 49 }; 50 50 51 51 struct ynl_policy_nest { 52 52 unsigned int max_attr; 53 - struct ynl_policy_attr *table; 53 + const struct ynl_policy_attr *table; 54 54 }; 55 55 56 56 struct ynl_parse_arg { 57 57 struct ynl_sock *ys; 58 - struct ynl_policy_nest *rsp_policy; 58 + const struct ynl_policy_nest *rsp_policy; 59 59 void *data; 60 60 }; 61 61 ··· 119 119 }; 120 120 121 121 struct ynl_ntf_info { 122 - struct ynl_policy_nest *policy; 122 + const struct ynl_policy_nest *policy; 123 123 ynl_parse_cb_t cb; 124 124 size_t alloc_sz; 125 125 void (*free)(struct ynl_ntf_base_type *ntf);
+5 -5
tools/net/ynl/lib/ynl.c
··· 46 46 47 47 /* -- Netlink boiler plate */ 48 48 static int 49 - ynl_err_walk_report_one(struct ynl_policy_nest *policy, unsigned int type, 49 + ynl_err_walk_report_one(const struct ynl_policy_nest *policy, unsigned int type, 50 50 char *str, int str_sz, int *n) 51 51 { 52 52 if (!policy) { ··· 75 75 76 76 static int 77 77 ynl_err_walk(struct ynl_sock *ys, void *start, void *end, unsigned int off, 78 - struct ynl_policy_nest *policy, char *str, int str_sz, 79 - struct ynl_policy_nest **nest_pol) 78 + const struct ynl_policy_nest *policy, char *str, int str_sz, 79 + const struct ynl_policy_nest **nest_pol) 80 80 { 81 81 unsigned int astart_off, aend_off; 82 82 const struct nlattr *attr; ··· 206 206 bad_attr[n] = '\0'; 207 207 } 208 208 if (tb[NLMSGERR_ATTR_MISS_TYPE]) { 209 - struct ynl_policy_nest *nest_pol = NULL; 209 + const struct ynl_policy_nest *nest_pol = NULL; 210 210 unsigned int n, off, type; 211 211 void *start, *end; 212 212 int n2; ··· 296 296 297 297 int ynl_attr_validate(struct ynl_parse_arg *yarg, const struct nlattr *attr) 298 298 { 299 - struct ynl_policy_attr *policy; 299 + const struct ynl_policy_attr *policy; 300 300 unsigned int type, len; 301 301 unsigned char *data; 302 302
+1 -1
tools/net/ynl/lib/ynl.h
··· 76 76 struct ynl_ntf_base_type **ntf_last_next; 77 77 78 78 struct nlmsghdr *nlh; 79 - struct ynl_policy_nest *req_policy; 79 + const struct ynl_policy_nest *req_policy; 80 80 unsigned char *tx_buf; 81 81 unsigned char *rx_buf; 82 82 unsigned char raw_buf[];
+3 -3
tools/net/ynl/ynl-gen-c.py
··· 1507 1507 1508 1508 1509 1509 def put_typol_fwd(cw, struct): 1510 - cw.p(f'extern struct ynl_policy_nest {struct.render_name}_nest;') 1510 + cw.p(f'extern const struct ynl_policy_nest {struct.render_name}_nest;') 1511 1511 1512 1512 1513 1513 def put_typol(cw, struct): 1514 1514 type_max = struct.attr_set.max_name 1515 - cw.block_start(line=f'struct ynl_policy_attr {struct.render_name}_policy[{type_max} + 1] =') 1515 + cw.block_start(line=f'const struct ynl_policy_attr {struct.render_name}_policy[{type_max} + 1] =') 1516 1516 1517 1517 for _, arg in struct.member_list(): 1518 1518 arg.attr_typol(cw) ··· 1520 1520 cw.block_end(line=';') 1521 1521 cw.nl() 1522 1522 1523 - cw.block_start(line=f'struct ynl_policy_nest {struct.render_name}_nest =') 1523 + cw.block_start(line=f'const struct ynl_policy_nest {struct.render_name}_nest =') 1524 1524 cw.p(f'.max_attr = {type_max},') 1525 1525 cw.p(f'.table = {struct.render_name}_policy,') 1526 1526 cw.block_end(line=';')