crypto: fix crypto_alloc_{tfm,base}() return value
PATCH 1/2 crypto: fix crypto_alloc_{tfm,base}() return value
crypto_alloc_tfm() and crypto_alloc_base() are suppose to return error code as pointer on failures. But there are some cases where they return NULL (for example, crypto_alloc_tfm() returns NULL on kzalloc() failure)
This patch fixes that wrong return value, and also fixes tcrypt so that it can detect error code correctly.
crypto/api.c | 47 ++++++++++++++++++++++++++++------------------- crypto/tcrypt.c | 5 +++-- 2 files changed, 31 insertions(+), 21 deletions(-)
crypto/tcrypt.c +3 -2
@@ -766,8 +766,9 @@ static void test_deflate(void) tv = (void *)tvmem; tfm =crypto_alloc_tfm ("deflate" ,0 ); -if (tfm ==NULL ) { -printk ("failed to load transform for deflate\n" ); +if (IS_ERR (tfm)) { +printk ("failed to load transform for deflate: %ld\n" , +PTR_ERR (tfm));return ; }
crypto/api.c +28 -19
91 lines not on this page · raw message
PATCH 2/2 crypto: delete duplicated code
crypto_alloc_tfm() and crypto_alloc_base() are almost same.
crypto/api.c | 40 +++++++++------------------------------- 1 file changed, 9 insertions(+), 31 deletions(-)
crypto/api.c +9 -31
@@ -362,7 +362,8 @@ out: }EXPORT_SYMBOL_GPL (__crypto_alloc_tfm); -struct crypto_tfm *crypto_alloc_tfm (const char *name,u32 flags) +static struct crypto_tfm *crypto_alloc_tfm_base (const char *name,u32 flags, +u32 type,u32 mask) {struct crypto_tfm *tfm;int err;
@@ -370,7 +371,7 @@ struct crypto_tfm *crypto_alloc_tfm(consfor (;;) {struct crypto_alg *alg; - alg =crypto_alg_mod_lookup (name,0 ,CRYPTO_ALG_ASYNC ); + alg =crypto_alg_mod_lookup (name, type, mask);if (IS_ERR (alg)) { err =PTR_ERR (alg); goto err;
@@ -395,6 +396,11 @@ err:return ERR_PTR (err); } +struct crypto_tfm *crypto_alloc_tfm (const char *name,u32 flags) +{ +return crypto_alloc_tfm_base (name, flags,0 ,CRYPTO_ALG_ASYNC ); +} +/* * crypto_alloc_base - Locate algorithm and allocate transform * @alg_name: Name of algorithm
@@ -416,35 +422,7 @@ err:*/ struct crypto_tfm *crypto_alloc_base (const char *alg_name,u32 type,u32 mask) { -struct crypto_tfm *tfm; -int err; - -for (;;) { -struct crypto_alg *alg; - - alg =crypto_alg_mod_lookup (alg_name, type, mask); -if (IS_ERR (alg)) { - err =PTR_ERR (alg); - goto err; - } - - tfm =__crypto_alloc_tfm (alg,0 ); -if (!IS_ERR (tfm)) -return tfm; - -crypto_mod_put (alg); - err =PTR_ERR (tfm); - -err: -if (err != -EAGAIN ) -break ; -if (signal_pending (current)) { - err = -EINTR ; -break ; - } - } - -return ERR_PTR (err); +return crypto_alloc_tfm_base (alg_name,0 , type, mask); }EXPORT_SYMBOL_GPL (crypto_alloc_base);
Herbert Xu
maintainerQuoted 6 lines · Akinobu Mita
crypto_alloc_tfm()andcrypto_alloc_base()are suppose to return error code as pointer on failures. But there are some cases where they return NULL (for example,crypto_alloc_tfm()returns NULL onkzalloc()failure)This patch fixes that wrong return value, and also fixes tcrypt so that it can detect error code correctly.
Actually, crypto_alloc_tfm is an obsolete function which is supposed to maintain its previous semantics of returning NULL or success.
I don't quite see where the problem with crypto_alloc_base is.
Cheers,
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txtQuoted 2 lines · Herbert Xu
Actually,
crypto_alloc_tfmis an obsolete function which is supposed to maintain its previous semantics of returning NULL or success.
I misunderstood about crypto_alloc_tfm().
BTW, ecryptfs and reiser4 are still using crypto_alloc_tfm(). Should we mark it as __deprecated?
Quoted 1 line
I don't quite see where the problem with
crypto_alloc_baseis.
- __crypto_alloc_tfm() should return -ENOMEM on kzalloc() failure. But it returns NULL.
- crypto_alloc_base() may not return -EINTR on signal_pending()
I'll fix the patch and resend with more clear description later.
Herbert Xu
maintainerQuoted 5 lines · Akinobu Mita
I misunderstood about
crypto_alloc_tfm().BTW, ecryptfs and reiser4 are still using
crypto_alloc_tfm(). Should we mark it as__deprecated?
Probably. Although anybody using crypto_alloc_tfm will probably also use the old crypto interface which gives plenty of warnings already.
Quoted 6 lines
-
__crypto_alloc_tfm()should return-ENOMEMonkzalloc()failure. But it returns NULL.-
crypto_alloc_base()may not return-EINTRonsignal_pending()I'll fix the patch and resend with more clear description later.
Thanks,
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt