aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/api.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2009-02-18 03:56:59 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2009-02-18 03:56:59 -0500
commit3f683d6175748ef9daf4698d9ef5a488dd037063 (patch)
tree1cea62b5937871b34c533416e05bedbee4a4914c /crypto/api.c
parentff753308d2f70f210ba468492cd9a01274d9d7ce (diff)
crypto: api - Fix crypto_alloc_tfm/create_create_tfm return convention
This is based on a report and patch by Geert Uytterhoeven. The functions crypto_alloc_tfm and create_create_tfm return a pointer that needs to be adjusted by the caller when successful and otherwise an error value. This means that the caller has to check for the error and only perform the adjustment if the pointer returned is valid. Since all callers want to make the adjustment and we know how to adjust it ourselves, it's much easier to just return adjusted pointer directly. The only caveat is that we have to return a void * instead of struct crypto_tfm *. However, this isn't that bad because both of these functions are for internal use only (by types code like shash.c, not even algorithms code). This patch also moves crypto_alloc_tfm into crypto/internal.h (crypto_create_tfm is already there) to reflect this. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/api.c')
-rw-r--r--crypto/api.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/crypto/api.c b/crypto/api.c
index 56b6e0e66311..22385cac90bb 100644
--- a/crypto/api.c
+++ b/crypto/api.c
@@ -453,8 +453,8 @@ err:
453} 453}
454EXPORT_SYMBOL_GPL(crypto_alloc_base); 454EXPORT_SYMBOL_GPL(crypto_alloc_base);
455 455
456struct crypto_tfm *crypto_create_tfm(struct crypto_alg *alg, 456void *crypto_create_tfm(struct crypto_alg *alg,
457 const struct crypto_type *frontend) 457 const struct crypto_type *frontend)
458{ 458{
459 char *mem; 459 char *mem;
460 struct crypto_tfm *tfm = NULL; 460 struct crypto_tfm *tfm = NULL;
@@ -488,9 +488,9 @@ out_free_tfm:
488 crypto_shoot_alg(alg); 488 crypto_shoot_alg(alg);
489 kfree(mem); 489 kfree(mem);
490out_err: 490out_err:
491 tfm = ERR_PTR(err); 491 mem = ERR_PTR(err);
492out: 492out:
493 return tfm; 493 return mem;
494} 494}
495EXPORT_SYMBOL_GPL(crypto_create_tfm); 495EXPORT_SYMBOL_GPL(crypto_create_tfm);
496 496
@@ -514,12 +514,11 @@ EXPORT_SYMBOL_GPL(crypto_create_tfm);
514 * 514 *
515 * In case of error the return value is an error pointer. 515 * In case of error the return value is an error pointer.
516 */ 516 */
517struct crypto_tfm *crypto_alloc_tfm(const char *alg_name, 517void *crypto_alloc_tfm(const char *alg_name,
518 const struct crypto_type *frontend, 518 const struct crypto_type *frontend, u32 type, u32 mask)
519 u32 type, u32 mask)
520{ 519{
521 struct crypto_alg *(*lookup)(const char *name, u32 type, u32 mask); 520 struct crypto_alg *(*lookup)(const char *name, u32 type, u32 mask);
522 struct crypto_tfm *tfm; 521 void *tfm;
523 int err; 522 int err;
524 523
525 type &= frontend->maskclear; 524 type &= frontend->maskclear;