aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesper Juhl <juhl-lkml@dif.dk>2005-07-06 16:54:31 -0400
committerDavid S. Miller <davem@davemloft.net>2005-07-06 16:54:31 -0400
commita61cc44812ff94793987bf43b70a3d9bc64a6820 (patch)
tree65cf93c2a89fb0072a69c2904202713a2e895098
parent476df259cd577e20379b02a7f7ffd086ea925a83 (diff)
[CRYPTO] Add null short circuit to crypto_free_tfm
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. Signed-off-by: Jesper Juhl <juhl-lkml@dif.dk> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--crypto/api.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/crypto/api.c b/crypto/api.c
index 2d8d828c0ca2..b4728811ce3b 100644
--- a/crypto/api.c
+++ b/crypto/api.c
@@ -13,6 +13,8 @@
13 * any later version. 13 * any later version.
14 * 14 *
15 */ 15 */
16
17#include <linux/compiler.h>
16#include <linux/init.h> 18#include <linux/init.h>
17#include <linux/crypto.h> 19#include <linux/crypto.h>
18#include <linux/errno.h> 20#include <linux/errno.h>
@@ -189,8 +191,14 @@ out:
189 191
190void crypto_free_tfm(struct crypto_tfm *tfm) 192void crypto_free_tfm(struct crypto_tfm *tfm)
191{ 193{
192 struct crypto_alg *alg = tfm->__crt_alg; 194 struct crypto_alg *alg;
193 int size = sizeof(*tfm) + alg->cra_ctxsize; 195 int size;
196
197 if (unlikely(!tfm))
198 return;
199
200 alg = tfm->__crt_alg;
201 size = sizeof(*tfm) + alg->cra_ctxsize;
194 202
195 crypto_exit_ops(tfm); 203 crypto_exit_ops(tfm);
196 crypto_alg_put(alg); 204 crypto_alg_put(alg);