With the help of Coccinelle. We find some place to replace.
@@
expression M, S;
@@
- memset(M, 0, S);
- kfree(M);
+ kzfree(M);
zhong jiang (3):
ixgbe: Use kzfree() rather than its implementation.
sunrpc: Use kzfree rather than its implementation.
net: mpoa: Use kzfree rather than its implementation.
drivers/net/ethernet/intel/ixgbe/ixgbe_ipsec.c | 9 +++------
net/atm/mpoa_caches.c | 6 ++----
net/sunrpc/auth_gss/gss_krb5_keys.c | 9 +++------
3 files changed, 8 insertions(+), 16 deletions(-)
--
1.7.12.4
Use kzfree() instead of memset() + kfree().
Signed-off-by: zhong jiang <[email protected]>
---
drivers/net/ethernet/intel/ixgbe/ixgbe_ipsec.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ipsec.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ipsec.c
index 31629fc..113f608 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ipsec.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ipsec.c
@@ -960,11 +960,9 @@ int ixgbe_ipsec_vf_add_sa(struct ixgbe_adapter *adapter, u32 *msgbuf, u32 vf)
return 0;
err_aead:
- memset(xs->aead, 0, sizeof(*xs->aead));
- kfree(xs->aead);
+ kzfree(xs->aead);
err_xs:
- memset(xs, 0, sizeof(*xs));
- kfree(xs);
+ kzfree(xs);
err_out:
msgbuf[1] = err;
return err;
@@ -1049,8 +1047,7 @@ int ixgbe_ipsec_vf_del_sa(struct ixgbe_adapter *adapter, u32 *msgbuf, u32 vf)
ixgbe_ipsec_del_sa(xs);
/* remove the xs that was made-up in the add request */
- memset(xs, 0, sizeof(*xs));
- kfree(xs);
+ kzfree(xs);
return 0;
}
--
1.7.12.4
Use kzfree instead of memset() + kfree().
Signed-off-by: zhong jiang <[email protected]>
---
net/atm/mpoa_caches.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
index 4bb4183..3286f9d 100644
--- a/net/atm/mpoa_caches.c
+++ b/net/atm/mpoa_caches.c
@@ -180,8 +180,7 @@ static int cache_hit(in_cache_entry *entry, struct mpoa_client *mpc)
static void in_cache_put(in_cache_entry *entry)
{
if (refcount_dec_and_test(&entry->use)) {
- memset(entry, 0, sizeof(in_cache_entry));
- kfree(entry);
+ kzfree(entry);
}
}
@@ -416,8 +415,7 @@ static eg_cache_entry *eg_cache_get_by_src_ip(__be32 ipaddr,
static void eg_cache_put(eg_cache_entry *entry)
{
if (refcount_dec_and_test(&entry->use)) {
- memset(entry, 0, sizeof(eg_cache_entry));
- kfree(entry);
+ kzfree(entry);
}
}
--
1.7.12.4
Use kzfree instead of memset() + kfree().
Signed-off-by: zhong jiang <[email protected]>
---
net/sunrpc/auth_gss/gss_krb5_keys.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/net/sunrpc/auth_gss/gss_krb5_keys.c b/net/sunrpc/auth_gss/gss_krb5_keys.c
index 550fdf1..3b7f721 100644
--- a/net/sunrpc/auth_gss/gss_krb5_keys.c
+++ b/net/sunrpc/auth_gss/gss_krb5_keys.c
@@ -228,14 +228,11 @@ u32 krb5_derive_key(const struct gss_krb5_enctype *gk5e,
ret = 0;
err_free_raw:
- memset(rawkey, 0, keybytes);
- kfree(rawkey);
+ kzfree(rawkey);
err_free_out:
- memset(outblockdata, 0, blocksize);
- kfree(outblockdata);
+ kzfree(outblockdata);
err_free_in:
- memset(inblockdata, 0, blocksize);
- kfree(inblockdata);
+ kzfree(inblockdata);
err_free_cipher:
crypto_free_sync_skcipher(cipher);
err_return:
--
1.7.12.4
From: zhong jiang <[email protected]>
Date: Wed, 4 Sep 2019 10:39:09 +0800
> With the help of Coccinelle. We find some place to replace.
>
> @@
> expression M, S;
> @@
>
> - memset(M, 0, S);
> - kfree(M);
> + kzfree(M);
Series applied to net-next.
On Wed, 4 Sep 2019 10:39:10 +0800, zhong jiang wrote:
> Use kzfree() instead of memset() + kfree().
>
> Signed-off-by: zhong jiang <[email protected]>
> ---
> drivers/net/ethernet/intel/ixgbe/ixgbe_ipsec.c | 9 +++------
> 1 file changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ipsec.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ipsec.c
> index 31629fc..113f608 100644
> --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ipsec.c
> +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ipsec.c
> @@ -960,11 +960,9 @@ int ixgbe_ipsec_vf_add_sa(struct ixgbe_adapter *adapter, u32 *msgbuf, u32 vf)
> return 0;
>
> err_aead:
> - memset(xs->aead, 0, sizeof(*xs->aead));
> - kfree(xs->aead);
> + kzfree(xs->aead);
> err_xs:
> - memset(xs, 0, sizeof(*xs));
> - kfree(xs);
> + kzfree(xs);
> err_out:
> msgbuf[1] = err;
> return err;
> @@ -1049,8 +1047,7 @@ int ixgbe_ipsec_vf_del_sa(struct ixgbe_adapter *adapter, u32 *msgbuf, u32 vf)
> ixgbe_ipsec_del_sa(xs);
>
> /* remove the xs that was made-up in the add request */
> - memset(xs, 0, sizeof(*xs));
> - kfree(xs);
> + kzfree(xs);
>
> return 0;
> }
All the crypto cases should really be converted to memzero_explicit().
On 2019/9/17 10:43, Jakub Kicinski wrote:
> On Wed, 4 Sep 2019 10:39:10 +0800, zhong jiang wrote:
>> Use kzfree() instead of memset() + kfree().
>>
>> Signed-off-by: zhong jiang <[email protected]>
>> ---
>> drivers/net/ethernet/intel/ixgbe/ixgbe_ipsec.c | 9 +++------
>> 1 file changed, 3 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ipsec.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ipsec.c
>> index 31629fc..113f608 100644
>> --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ipsec.c
>> +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ipsec.c
>> @@ -960,11 +960,9 @@ int ixgbe_ipsec_vf_add_sa(struct ixgbe_adapter *adapter, u32 *msgbuf, u32 vf)
>> return 0;
>>
>> err_aead:
>> - memset(xs->aead, 0, sizeof(*xs->aead));
>> - kfree(xs->aead);
>> + kzfree(xs->aead);
>> err_xs:
>> - memset(xs, 0, sizeof(*xs));
>> - kfree(xs);
>> + kzfree(xs);
>> err_out:
>> msgbuf[1] = err;
>> return err;
>> @@ -1049,8 +1047,7 @@ int ixgbe_ipsec_vf_del_sa(struct ixgbe_adapter *adapter, u32 *msgbuf, u32 vf)
>> ixgbe_ipsec_del_sa(xs);
>>
>> /* remove the xs that was made-up in the add request */
>> - memset(xs, 0, sizeof(*xs));
>> - kfree(xs);
>> + kzfree(xs);
>>
>> return 0;
>> }
> All the crypto cases should really be converted to memzero_explicit().
It's better to do that. I will repost it in v2.
Thanks,
zhong jiang