Replace some instances of kmalloc + memset. Signed-off-by: Jeremy Sowden <jeremy@xxxxxxxxxx> --- extensions/pknock/xt_pknock.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/extensions/pknock/xt_pknock.c b/extensions/pknock/xt_pknock.c index ba8161517d27..ae3ab2445c3b 100644 --- a/extensions/pknock/xt_pknock.c +++ b/extensions/pknock/xt_pknock.c @@ -450,13 +450,12 @@ add_rule(struct xt_pknock_mtinfo *info) return true; } - rule = kmalloc(sizeof(*rule), GFP_KERNEL); + rule = kzalloc(sizeof(*rule), GFP_KERNEL); if (rule == NULL) return false; INIT_LIST_HEAD(&rule->head); - memset(rule->rule_name, 0, sizeof(rule->rule_name)); strncpy(rule->rule_name, info->rule_name, info->rule_name_len); rule->rule_name_len = info->rule_name_len; @@ -681,12 +680,9 @@ msg_to_userspace_nl(const struct xt_pknock_mtinfo *info, struct cn_msg *m; struct xt_pknock_nl_msg msg; - m = kmalloc(sizeof(*m) + sizeof(msg), GFP_ATOMIC); + m = kzalloc(sizeof(*m) + sizeof(msg), GFP_ATOMIC); if (m == NULL) return false; - - memset(m, 0, sizeof(*m) + sizeof(msg)); - m->seq = 0; m->len = sizeof(msg); msg.peer_ip = peer->ip; @@ -731,7 +727,7 @@ static bool has_secret(const unsigned char *secret, unsigned int secret_len, uint32_t ipsrc, const unsigned char *payload, unsigned int payload_len) { - char result[64]; // 64 bytes * 8 = 512 bits + char result[64] = ""; // 64 bytes * 8 = 512 bits char *hexresult; unsigned int hexa_size; int ret; @@ -752,13 +748,10 @@ has_secret(const unsigned char *secret, unsigned int secret_len, uint32_t ipsrc, if (payload_len != hexa_size + 1) return false; - hexresult = kmalloc(hexa_size, GFP_ATOMIC); + hexresult = kzalloc(hexa_size, GFP_ATOMIC); if (hexresult == NULL) return false; - memset(result, 0, sizeof(result)); - memset(hexresult, 0, hexa_size); - epoch_min = get_seconds() / 60; ret = crypto_shash_setkey(crypto.tfm, secret, secret_len); -- 2.28.0