mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] crypto: resource release functions ought to check for NULL (crypto_free_tfm)
@ 2005-04-14 23:15 Jesper Juhl
  2005-04-18 11:49 ` Herbert Xu
  0 siblings, 1 reply; 5+ messages in thread
From: Jesper Juhl @ 2005-04-14 23:15 UTC (permalink / raw)
  To: David S. Miller; +Cc: Herbert Xu, James Morris, linux-crypto, linux-kernel


As far as I'm aware there's a general concensus that functions that are 
responsible for freeing resources should be able to cope with being passed 
a NULL pointer. This makes sense as it removes the need for all callers to 
check for NULL, thus elliminating the bugs that happen when some forget 
(safer to just check centrally in the freeing function) and it also makes 
for smaller code all over due to the lack of all those NULL checks.
This patch makes it safe to pass the crypto_free_tfm() function a NULL 
pointer. Once this patch is applied we can start removing the NULL checks 
from the callers.  
Please consider applying.

Please CC: me on replies as I'm not subscribed to linux-crypto


Signed-off-by: Jesper Juhl <juhl-lkml@dif.dk>
---

 api.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

--- linux-2.6.12-rc2-mm3-orig/crypto/api.c	2005-04-11 21:20:39.000000000 +0200
+++ linux-2.6.12-rc2-mm3/crypto/api.c	2005-04-15 01:05:52.000000000 +0200
@@ -163,8 +163,14 @@ out:
 
 void crypto_free_tfm(struct crypto_tfm *tfm)
 {
-	struct crypto_alg *alg = tfm->__crt_alg;
-	int size = sizeof(*tfm) + alg->cra_ctxsize;
+	struct crypto_alg *alg;
+	int size;
+
+	if (!tfm)
+		return;
+
+	alg = tfm->__crt_alg;
+	size = sizeof(*tfm) + alg->cra_ctxsize;
 
 	crypto_exit_ops(tfm);
 	crypto_alg_put(alg);



-- 
Jesper Juhl

PS. Please CC: me on replies to linux-crypto as I'm not subscribed to that 
list.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-04-19  8:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-14 23:15 [PATCH] crypto: resource release functions ought to check for NULL (crypto_free_tfm) Jesper Juhl
2005-04-18 11:49 ` Herbert Xu
2005-04-18 15:23   ` Jesper Juhl
2005-04-19  8:20     ` Herbert Xu
2005-04-19  8:39       ` Jesper Juhl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®