Commit a149a3a1 authored by Jakub Kicinski's avatar Jakub Kicinski

tools: ynl-gen: set length of binary fields

Remember to set the length field in the request setters.
Reviewed-by: default avatarDonald Hunter <donald.hunter@gmail.com>
Link: https://lore.kernel.org/r/20230824003056.1436637-3-kuba@kernel.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 649bde90
...@@ -1422,6 +1422,7 @@ ethtool_wol_set_req_set_sopass(struct ethtool_wol_set_req *req, ...@@ -1422,6 +1422,7 @@ ethtool_wol_set_req_set_sopass(struct ethtool_wol_set_req *req,
const void *sopass, size_t len) const void *sopass, size_t len)
{ {
free(req->sopass); free(req->sopass);
req->_present.sopass_len = len;
req->sopass = malloc(req->_present.sopass_len); req->sopass = malloc(req->_present.sopass_len);
memcpy(req->sopass, sopass, req->_present.sopass_len); memcpy(req->sopass, sopass, req->_present.sopass_len);
} }
...@@ -4071,6 +4072,7 @@ ethtool_fec_set_req_set_stats_corrected(struct ethtool_fec_set_req *req, ...@@ -4071,6 +4072,7 @@ ethtool_fec_set_req_set_stats_corrected(struct ethtool_fec_set_req *req,
const void *corrected, size_t len) const void *corrected, size_t len)
{ {
free(req->stats.corrected); free(req->stats.corrected);
req->stats._present.corrected_len = len;
req->stats.corrected = malloc(req->stats._present.corrected_len); req->stats.corrected = malloc(req->stats._present.corrected_len);
memcpy(req->stats.corrected, corrected, req->stats._present.corrected_len); memcpy(req->stats.corrected, corrected, req->stats._present.corrected_len);
} }
...@@ -4079,6 +4081,7 @@ ethtool_fec_set_req_set_stats_uncorr(struct ethtool_fec_set_req *req, ...@@ -4079,6 +4081,7 @@ ethtool_fec_set_req_set_stats_uncorr(struct ethtool_fec_set_req *req,
const void *uncorr, size_t len) const void *uncorr, size_t len)
{ {
free(req->stats.uncorr); free(req->stats.uncorr);
req->stats._present.uncorr_len = len;
req->stats.uncorr = malloc(req->stats._present.uncorr_len); req->stats.uncorr = malloc(req->stats._present.uncorr_len);
memcpy(req->stats.uncorr, uncorr, req->stats._present.uncorr_len); memcpy(req->stats.uncorr, uncorr, req->stats._present.uncorr_len);
} }
...@@ -4087,6 +4090,7 @@ ethtool_fec_set_req_set_stats_corr_bits(struct ethtool_fec_set_req *req, ...@@ -4087,6 +4090,7 @@ ethtool_fec_set_req_set_stats_corr_bits(struct ethtool_fec_set_req *req,
const void *corr_bits, size_t len) const void *corr_bits, size_t len)
{ {
free(req->stats.corr_bits); free(req->stats.corr_bits);
req->stats._present.corr_bits_len = len;
req->stats.corr_bits = malloc(req->stats._present.corr_bits_len); req->stats.corr_bits = malloc(req->stats._present.corr_bits_len);
memcpy(req->stats.corr_bits, corr_bits, req->stats._present.corr_bits_len); memcpy(req->stats.corr_bits, corr_bits, req->stats._present.corr_bits_len);
} }
......
...@@ -91,6 +91,7 @@ fou_add_req_set_local_v6(struct fou_add_req *req, const void *local_v6, ...@@ -91,6 +91,7 @@ fou_add_req_set_local_v6(struct fou_add_req *req, const void *local_v6,
size_t len) size_t len)
{ {
free(req->local_v6); free(req->local_v6);
req->_present.local_v6_len = len;
req->local_v6 = malloc(req->_present.local_v6_len); req->local_v6 = malloc(req->_present.local_v6_len);
memcpy(req->local_v6, local_v6, req->_present.local_v6_len); memcpy(req->local_v6, local_v6, req->_present.local_v6_len);
} }
...@@ -99,6 +100,7 @@ fou_add_req_set_peer_v6(struct fou_add_req *req, const void *peer_v6, ...@@ -99,6 +100,7 @@ fou_add_req_set_peer_v6(struct fou_add_req *req, const void *peer_v6,
size_t len) size_t len)
{ {
free(req->peer_v6); free(req->peer_v6);
req->_present.peer_v6_len = len;
req->peer_v6 = malloc(req->_present.peer_v6_len); req->peer_v6 = malloc(req->_present.peer_v6_len);
memcpy(req->peer_v6, peer_v6, req->_present.peer_v6_len); memcpy(req->peer_v6, peer_v6, req->_present.peer_v6_len);
} }
...@@ -192,6 +194,7 @@ fou_del_req_set_local_v6(struct fou_del_req *req, const void *local_v6, ...@@ -192,6 +194,7 @@ fou_del_req_set_local_v6(struct fou_del_req *req, const void *local_v6,
size_t len) size_t len)
{ {
free(req->local_v6); free(req->local_v6);
req->_present.local_v6_len = len;
req->local_v6 = malloc(req->_present.local_v6_len); req->local_v6 = malloc(req->_present.local_v6_len);
memcpy(req->local_v6, local_v6, req->_present.local_v6_len); memcpy(req->local_v6, local_v6, req->_present.local_v6_len);
} }
...@@ -200,6 +203,7 @@ fou_del_req_set_peer_v6(struct fou_del_req *req, const void *peer_v6, ...@@ -200,6 +203,7 @@ fou_del_req_set_peer_v6(struct fou_del_req *req, const void *peer_v6,
size_t len) size_t len)
{ {
free(req->peer_v6); free(req->peer_v6);
req->_present.peer_v6_len = len;
req->peer_v6 = malloc(req->_present.peer_v6_len); req->peer_v6 = malloc(req->_present.peer_v6_len);
memcpy(req->peer_v6, peer_v6, req->_present.peer_v6_len); memcpy(req->peer_v6, peer_v6, req->_present.peer_v6_len);
} }
...@@ -280,6 +284,7 @@ fou_get_req_set_local_v6(struct fou_get_req *req, const void *local_v6, ...@@ -280,6 +284,7 @@ fou_get_req_set_local_v6(struct fou_get_req *req, const void *local_v6,
size_t len) size_t len)
{ {
free(req->local_v6); free(req->local_v6);
req->_present.local_v6_len = len;
req->local_v6 = malloc(req->_present.local_v6_len); req->local_v6 = malloc(req->_present.local_v6_len);
memcpy(req->local_v6, local_v6, req->_present.local_v6_len); memcpy(req->local_v6, local_v6, req->_present.local_v6_len);
} }
...@@ -288,6 +293,7 @@ fou_get_req_set_peer_v6(struct fou_get_req *req, const void *peer_v6, ...@@ -288,6 +293,7 @@ fou_get_req_set_peer_v6(struct fou_get_req *req, const void *peer_v6,
size_t len) size_t len)
{ {
free(req->peer_v6); free(req->peer_v6);
req->_present.peer_v6_len = len;
req->peer_v6 = malloc(req->_present.peer_v6_len); req->peer_v6 = malloc(req->_present.peer_v6_len);
memcpy(req->peer_v6, peer_v6, req->_present.peer_v6_len); memcpy(req->peer_v6, peer_v6, req->_present.peer_v6_len);
} }
......
...@@ -428,6 +428,7 @@ class TypeBinary(Type): ...@@ -428,6 +428,7 @@ class TypeBinary(Type):
def _setter_lines(self, ri, member, presence): def _setter_lines(self, ri, member, presence):
return [f"free({member});", return [f"free({member});",
f"{presence}_len = len;",
f"{member} = malloc({presence}_len);", f"{member} = malloc({presence}_len);",
f'memcpy({member}, {self.c_name}, {presence}_len);'] f'memcpy({member}, {self.c_name}, {presence}_len);']
......
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