Skip to content

Commit

Permalink
[CRYPTO] Add null short circuit to crypto_free_tfm
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Jesper Juhl authored and davem330 committed Jul 6, 2005
1 parent 476df25 commit a61cc44
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions crypto/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* any later version.
*
*/

#include <linux/compiler.h>
#include <linux/init.h>
#include <linux/crypto.h>
#include <linux/errno.h>
Expand Down Expand Up @@ -189,8 +191,14 @@ struct crypto_tfm *crypto_alloc_tfm(const char *name, u32 flags)

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 (unlikely(!tfm))
return;

alg = tfm->__crt_alg;
size = sizeof(*tfm) + alg->cra_ctxsize;

crypto_exit_ops(tfm);
crypto_alg_put(alg);
Expand Down

0 comments on commit a61cc44

Please sign in to comment.