[PATCH] crypto: resource release functions ought to check for NULL(crypto_free_tfm)

From: Jesper Juhl
Date: Thu Apr 14 2005 - 18:14:50 EST



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@xxxxxx>
---

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.


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/