pcrypt: handle crypto_get_attr_type() errors
Subsystems (3)
PATCH 1/1 pcrypt: handle crypto_get_attr_type() errors
crypto_get_attr_type() can returns ERR_PTRs if there is a problem.
crypto/pcrypt.c +2 -0
@@ -322,6 +322,8 @@ static struct crypto_instance *pcrypt_alloc_aead(struct rtattr **tb)struct crypto_attr_type *algt; algt =crypto_get_attr_type (tb); +if (IS_ERR (algt)) +return ERR_CAST (algt); alg =crypto_get_attr_alg (tb, algt->type, (algt->mask &CRYPTO_ALG_TYPE_MASK ));
Steffen Klassert
maintainerQuoted 9 lines · Dan Carpenter
crypto_get_attr_type()can returnsERR_PTRsif there is a problem.Signed-off-by Dan Carpenter <[email protected]>crypto/pcrypt.c +0
-0
crypto/pcrypt.c static struct crypto_instance *pcrypt_alloc_aead(struct rtattr **tb) · line 329
Quoted 8 lines
crypto/pcrypt.c +2
-0@@ -322,6 +322,8 @@ static struct crypto_instance *pcrypt_alloc_aead(struct rtattr **tb)struct crypto_attr_type *algt; algt =crypto_get_attr_type (tb); +if (IS_ERR (algt)) +return ERR_CAST (algt); alg =crypto_get_attr_alg (tb, algt->type, (algt->mask &CRYPTO_ALG_TYPE_MASK ));
I've just noticed that we are calling crypto_get_attr_type already in pcrypt_alloc, so perhaps we could just pass the type and mask to pcrypt_alloc_aead. Then we can remove this second call to crypto_get_attr_type completely.
Steffen
Quoted 16 lines · Steffen Klassert
Quoted 15 lines · Dan Carpenter
crypto_get_attr_type()can returnsERR_PTRsif there is a problem.Signed-off-by Dan Carpenter <[email protected]>crypto/pcrypt.c +2
-0@@ -322,6 +322,8 @@ static struct crypto_instance *pcrypt_alloc_aead(struct rtattr **tb)struct crypto_attr_type *algt; algt =crypto_get_attr_type (tb); +if (IS_ERR (algt)) +return ERR_CAST (algt);
Quoted 8 lines
crypto/pcrypt.c static struct crypto_instance *pcrypt_alloc_aead(struct rtattr **tb) · line 329
Quoted 2 lines
crypto/pcrypt.c +0
-0alg =crypto_get_attr_alg (tb, algt->type, (algt->mask &CRYPTO_ALG_TYPE_MASK ));I've just noticed that we are calling
crypto_get_attr_typealready inpcrypt_alloc, so perhaps we could just pass the type and mask topcrypt_alloc_aead. Then we can remove this second call tocrypto_get_attr_typecompletely.
Yup. That works too. I will send an updated patch.
regards,
dan carpenter
Quoted 1 line
Steffen
PATCH v2 1/1 pcrypt: handle crypto_get_attr_type() errors
In reply to Steffen KlassertI was concerned about the error handling for crypto_get_attr_type() in pcrypt_alloc_aead(). Steffen Klassert pointed out that we could simply avoid calling crypto_get_attr_type() if we passed the type and mask as a parameter.
crypto/pcrypt.c +3 -5
@@ -315,13 +315,11 @@ out_free_inst: goto out; } -static struct crypto_instance *pcrypt_alloc_aead (struct rtattr **tb) +static struct crypto_instance *pcrypt_alloc_aead (struct rtattr **tb, +struct crypto_attr_type *algt) {struct crypto_instance *inst;struct crypto_alg *alg; -struct crypto_attr_type *algt; - - algt =crypto_get_attr_type (tb); alg =crypto_get_attr_alg (tb, algt->type, (algt->mask &CRYPTO_ALG_TYPE_MASK ));
@@ -365,7 +363,7 @@ static struct crypto_instance *pcrypt_alloc(struct rtattr **tb)switch (algt->type & algt->mask &CRYPTO_ALG_TYPE_MASK ) {case CRYPTO_ALG_TYPE_AEAD : -return pcrypt_alloc_aead (tb); +return pcrypt_alloc_aead (tb, algt); }return ERR_PTR (-EINVAL );
Steffen Klassert
maintainerQuoted 14 lines · Dan Carpenter
crypto/pcrypt.c +2
-4-static struct crypto_instance *pcrypt_alloc_aead (struct rtattr **tb) +static struct crypto_instance *pcrypt_alloc_aead (struct rtattr **tb, +struct crypto_attr_type *algt) {struct crypto_instance *inst;struct crypto_alg *alg; -struct crypto_attr_type *algt; - - algt =crypto_get_attr_type (tb); alg =crypto_get_attr_alg (tb, algt->type, (algt->mask &CRYPTO_ALG_TYPE_MASK ));
crypto/pcrypt.c static struct crypto_instance *pcrypt_alloc(struct rtattr **tb) · line 368
Quoted 7 lines
crypto/pcrypt.c +1
-1@@ -365,7 +363,7 @@ static struct crypto_instance *pcrypt_alloc(struct rtattr **tb)switch (algt->type & algt->mask &CRYPTO_ALG_TYPE_MASK ) {case CRYPTO_ALG_TYPE_AEAD : -return pcrypt_alloc_aead (tb); +return pcrypt_alloc_aead (tb, algt); }
I thought about passing the type and mask values separately to pcrypt_alloc_aead, like type and mask values are passed to crypto_get_attr_alg. This is the usual way to do this in the crypto layer.
Thanks,
Steffen
PATCH v3 1/1 pcrypt: handle crypto_get_attr_type() errors
I was concerned about the error handling for crypto_get_attr_type() in pcrypt_alloc_aead(). Steffen Klassert pointed out that we could simply avoid calling crypto_get_attr_type() if we passed the type and mask as a parameters.
---
All three versions have basically been the same except for style issues. I will confess that this (hopefully final :P) version looks much nicer than the earlier ones.
crypto/pcrypt.c +4 -7
@@ -315,16 +315,13 @@ out_free_inst: goto out; } -static struct crypto_instance *pcrypt_alloc_aead (struct rtattr **tb) +static struct crypto_instance *pcrypt_alloc_aead (struct rtattr **tb, +u32 type,u32 mask) {struct crypto_instance *inst;struct crypto_alg *alg; -struct crypto_attr_type *algt; - - algt =crypto_get_attr_type (tb); - alg =crypto_get_attr_alg (tb, algt->type, - (algt->mask &CRYPTO_ALG_TYPE_MASK )); + alg =crypto_get_attr_alg (tb, type, (mask &CRYPTO_ALG_TYPE_MASK ));if (IS_ERR (alg))return ERR_CAST (alg);
@@ -365,7 +362,7 @@ static struct crypto_instance *pcrypt_alloc(struct rtattr **tb)switch (algt->type & algt->mask &CRYPTO_ALG_TYPE_MASK ) {case CRYPTO_ALG_TYPE_AEAD : -return pcrypt_alloc_aead (tb); +return pcrypt_alloc_aead (tb, algt->type, algt->mask); }return ERR_PTR (-EINVAL );
Quoted 6 lines · Dan Carpenter
I was concerned about the error handling for
crypto_get_attr_type()inpcrypt_alloc_aead(). Steffen Klassert pointed out that we could simply avoid callingcrypto_get_attr_type()if we passed the type and mask as a parameters.Signed-off-by Dan Carpenter <[email protected]>
Thanks a lot!
Quoted 5 lines
---
All three versions have basically been the same except for style issues. I will confess that this (hopefully final :P) version looks much nicer than the earlier ones.
It's not only style issues. We also got some additional benefit from this version. We got rid of a superfluous call to crypto_get_attr_type and we are able to change type and mask before we pass it to pcrypt_alloc_aead if this becomes necessary.
Steffen
Herbert Xu
maintainer�