Skip to contentSkip to conversation

kexec_file: use crypto_free_shash to free memory

PATCH In review Pan Bian 2 participants 2 messages Aug 9, 2017 – Aug 10, 2017

Subsystems (3)
lore
Share & tools
lore

Pan Bian

author
#0 lore raw

PATCH v2 1/1 kexec_file: use crypto_free_shash to free memory

In function kexec_calculate_store_digests(), kfree() is used to free memory allocated by crypto_alloc_shash(). It is better to use function crypto_free_shash(), which frees up tfm and any resources associated with it. And then, the refcount of the algorithm used in crypto_alloc_shash() is also dropped.

---
 kernel/kexec_file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/kexec_file.c +1 -1
index 9f48f44..94eeb38 100644
@@ -627,7 +627,7 @@ static int kexec_calculate_store_digests(struct kimage *image)
 out_free_desc:
 	kfree(desc);
 out_free_tfm:
-	kfree(tfm);
+	crypto_free_shash(tfm);
 out:
 	return ret;
 }
Signature · 8 lines
1.9.1



_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Acked-by on v2 1/1
#1 lore raw
Quoted 7 lines · Pan Bian

In function kexec_calculate_store_digests(), kfree() is used to free memory allocated by crypto_alloc_shash(). It is better to use function crypto_free_shash(), which frees up tfm and any resources associated with it. And then, the refcount of the algorithm used in crypto_alloc_shash() is also dropped.

Makes sense to call the crypto alloc/free api in pairs.

Quoted 26 lines
---
 kernel/kexec_file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/kexec_file.c +1 -1
index 9f48f44..94eeb38 100644
@@ -627,7 +627,7 @@ static int kexec_calculate_store_digests(struct kimage *image)
 out_free_desc:
 	kfree(desc);
 out_free_tfm:
-	kfree(tfm);
+	crypto_free_shash(tfm);
 out:
 	return ret;
 }
Signature · 8 lines
1.9.1



_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec