crypto: use ERR_CAST

Replace PTR_ERR followed by ERR_PTR by ERR_CAST, to be more concise.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
expression err,x;
@@
-       err = PTR_ERR(x);
        if (IS_ERR(x))
-                return ERR_PTR(err);
+                return ERR_CAST(x);
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
Julia Lawall 2013-01-22 12:29:26 +01:00 committed by Herbert Xu
parent 7b5c253c88
commit 3e8afe35c3
11 changed files with 27 additions and 59 deletions

View File

@ -282,18 +282,16 @@ struct crypto_instance *aead_geniv_alloc(struct crypto_template *tmpl,
int err; int err;
algt = crypto_get_attr_type(tb); algt = crypto_get_attr_type(tb);
err = PTR_ERR(algt);
if (IS_ERR(algt)) if (IS_ERR(algt))
return ERR_PTR(err); return ERR_CAST(algt);
if ((algt->type ^ (CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_GENIV)) & if ((algt->type ^ (CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_GENIV)) &
algt->mask) algt->mask)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
name = crypto_attr_alg_name(tb[1]); name = crypto_attr_alg_name(tb[1]);
err = PTR_ERR(name);
if (IS_ERR(name)) if (IS_ERR(name))
return ERR_PTR(err); return ERR_CAST(name);
inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL); inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL);
if (!inst) if (!inst)

View File

@ -749,12 +749,10 @@ struct crypto_alg *crypto_attr_alg2(struct rtattr *rta,
u32 type, u32 mask) u32 type, u32 mask)
{ {
const char *name; const char *name;
int err;
name = crypto_attr_alg_name(rta); name = crypto_attr_alg_name(rta);
err = PTR_ERR(name);
if (IS_ERR(name)) if (IS_ERR(name))
return ERR_PTR(err); return ERR_CAST(name);
return crypto_find_alg(name, frontend, type, mask); return crypto_find_alg(name, frontend, type, mask);
} }

View File

@ -592,9 +592,8 @@ static struct crypto_instance *crypto_authenc_alloc(struct rtattr **tb)
int err; int err;
algt = crypto_get_attr_type(tb); algt = crypto_get_attr_type(tb);
err = PTR_ERR(algt);
if (IS_ERR(algt)) if (IS_ERR(algt))
return ERR_PTR(err); return ERR_CAST(algt);
if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask) if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);

View File

@ -715,9 +715,8 @@ static struct crypto_instance *crypto_authenc_esn_alloc(struct rtattr **tb)
int err; int err;
algt = crypto_get_attr_type(tb); algt = crypto_get_attr_type(tb);
err = PTR_ERR(algt);
if (IS_ERR(algt)) if (IS_ERR(algt))
return ERR_PTR(err); return ERR_CAST(algt);
if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask) if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);

View File

@ -588,18 +588,16 @@ struct crypto_instance *skcipher_geniv_alloc(struct crypto_template *tmpl,
int err; int err;
algt = crypto_get_attr_type(tb); algt = crypto_get_attr_type(tb);
err = PTR_ERR(algt);
if (IS_ERR(algt)) if (IS_ERR(algt))
return ERR_PTR(err); return ERR_CAST(algt);
if ((algt->type ^ (CRYPTO_ALG_TYPE_GIVCIPHER | CRYPTO_ALG_GENIV)) & if ((algt->type ^ (CRYPTO_ALG_TYPE_GIVCIPHER | CRYPTO_ALG_GENIV)) &
algt->mask) algt->mask)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
name = crypto_attr_alg_name(tb[1]); name = crypto_attr_alg_name(tb[1]);
err = PTR_ERR(name);
if (IS_ERR(name)) if (IS_ERR(name))
return ERR_PTR(err); return ERR_CAST(name);
inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL); inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL);
if (!inst) if (!inst)

View File

@ -484,18 +484,16 @@ static struct crypto_instance *crypto_ccm_alloc_common(struct rtattr **tb,
int err; int err;
algt = crypto_get_attr_type(tb); algt = crypto_get_attr_type(tb);
err = PTR_ERR(algt);
if (IS_ERR(algt)) if (IS_ERR(algt))
return ERR_PTR(err); return ERR_CAST(algt);
if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask) if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
cipher = crypto_alg_mod_lookup(cipher_name, CRYPTO_ALG_TYPE_CIPHER, cipher = crypto_alg_mod_lookup(cipher_name, CRYPTO_ALG_TYPE_CIPHER,
CRYPTO_ALG_TYPE_MASK); CRYPTO_ALG_TYPE_MASK);
err = PTR_ERR(cipher);
if (IS_ERR(cipher)) if (IS_ERR(cipher))
return ERR_PTR(err); return ERR_CAST(cipher);
err = -EINVAL; err = -EINVAL;
if (cipher->cra_blocksize != 16) if (cipher->cra_blocksize != 16)
@ -573,15 +571,13 @@ out_put_cipher:
static struct crypto_instance *crypto_ccm_alloc(struct rtattr **tb) static struct crypto_instance *crypto_ccm_alloc(struct rtattr **tb)
{ {
int err;
const char *cipher_name; const char *cipher_name;
char ctr_name[CRYPTO_MAX_ALG_NAME]; char ctr_name[CRYPTO_MAX_ALG_NAME];
char full_name[CRYPTO_MAX_ALG_NAME]; char full_name[CRYPTO_MAX_ALG_NAME];
cipher_name = crypto_attr_alg_name(tb[1]); cipher_name = crypto_attr_alg_name(tb[1]);
err = PTR_ERR(cipher_name);
if (IS_ERR(cipher_name)) if (IS_ERR(cipher_name))
return ERR_PTR(err); return ERR_CAST(cipher_name);
if (snprintf(ctr_name, CRYPTO_MAX_ALG_NAME, "ctr(%s)", if (snprintf(ctr_name, CRYPTO_MAX_ALG_NAME, "ctr(%s)",
cipher_name) >= CRYPTO_MAX_ALG_NAME) cipher_name) >= CRYPTO_MAX_ALG_NAME)
@ -612,20 +608,17 @@ static struct crypto_template crypto_ccm_tmpl = {
static struct crypto_instance *crypto_ccm_base_alloc(struct rtattr **tb) static struct crypto_instance *crypto_ccm_base_alloc(struct rtattr **tb)
{ {
int err;
const char *ctr_name; const char *ctr_name;
const char *cipher_name; const char *cipher_name;
char full_name[CRYPTO_MAX_ALG_NAME]; char full_name[CRYPTO_MAX_ALG_NAME];
ctr_name = crypto_attr_alg_name(tb[1]); ctr_name = crypto_attr_alg_name(tb[1]);
err = PTR_ERR(ctr_name);
if (IS_ERR(ctr_name)) if (IS_ERR(ctr_name))
return ERR_PTR(err); return ERR_CAST(ctr_name);
cipher_name = crypto_attr_alg_name(tb[2]); cipher_name = crypto_attr_alg_name(tb[2]);
err = PTR_ERR(cipher_name);
if (IS_ERR(cipher_name)) if (IS_ERR(cipher_name))
return ERR_PTR(err); return ERR_CAST(cipher_name);
if (snprintf(full_name, CRYPTO_MAX_ALG_NAME, "ccm_base(%s,%s)", if (snprintf(full_name, CRYPTO_MAX_ALG_NAME, "ccm_base(%s,%s)",
ctr_name, cipher_name) >= CRYPTO_MAX_ALG_NAME) ctr_name, cipher_name) >= CRYPTO_MAX_ALG_NAME)
@ -760,17 +753,15 @@ static struct crypto_instance *crypto_rfc4309_alloc(struct rtattr **tb)
int err; int err;
algt = crypto_get_attr_type(tb); algt = crypto_get_attr_type(tb);
err = PTR_ERR(algt);
if (IS_ERR(algt)) if (IS_ERR(algt))
return ERR_PTR(err); return ERR_CAST(algt);
if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask) if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
ccm_name = crypto_attr_alg_name(tb[1]); ccm_name = crypto_attr_alg_name(tb[1]);
err = PTR_ERR(ccm_name);
if (IS_ERR(ccm_name)) if (IS_ERR(ccm_name))
return ERR_PTR(err); return ERR_CAST(ccm_name);
inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL); inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL);
if (!inst) if (!inst)

View File

@ -291,9 +291,8 @@ static struct crypto_instance *chainiv_alloc(struct rtattr **tb)
int err; int err;
algt = crypto_get_attr_type(tb); algt = crypto_get_attr_type(tb);
err = PTR_ERR(algt);
if (IS_ERR(algt)) if (IS_ERR(algt))
return ERR_PTR(err); return ERR_CAST(algt);
err = crypto_get_default_rng(); err = crypto_get_default_rng();
if (err) if (err)

View File

@ -334,9 +334,8 @@ static struct crypto_instance *crypto_rfc3686_alloc(struct rtattr **tb)
alg = crypto_attr_alg(tb[1], CRYPTO_ALG_TYPE_BLKCIPHER, alg = crypto_attr_alg(tb[1], CRYPTO_ALG_TYPE_BLKCIPHER,
CRYPTO_ALG_TYPE_MASK); CRYPTO_ALG_TYPE_MASK);
err = PTR_ERR(alg);
if (IS_ERR(alg)) if (IS_ERR(alg))
return ERR_PTR(err); return ERR_CAST(alg);
/* We only support 16-byte blocks. */ /* We only support 16-byte blocks. */
err = -EINVAL; err = -EINVAL;

View File

@ -282,9 +282,8 @@ static struct crypto_instance *crypto_cts_alloc(struct rtattr **tb)
alg = crypto_attr_alg(tb[1], CRYPTO_ALG_TYPE_BLKCIPHER, alg = crypto_attr_alg(tb[1], CRYPTO_ALG_TYPE_BLKCIPHER,
CRYPTO_ALG_TYPE_MASK); CRYPTO_ALG_TYPE_MASK);
err = PTR_ERR(alg);
if (IS_ERR(alg)) if (IS_ERR(alg))
return ERR_PTR(err); return ERR_CAST(alg);
inst = ERR_PTR(-EINVAL); inst = ERR_PTR(-EINVAL);
if (!is_power_of_2(alg->cra_blocksize)) if (!is_power_of_2(alg->cra_blocksize))

View File

@ -701,9 +701,8 @@ static struct crypto_instance *crypto_gcm_alloc_common(struct rtattr **tb,
int err; int err;
algt = crypto_get_attr_type(tb); algt = crypto_get_attr_type(tb);
err = PTR_ERR(algt);
if (IS_ERR(algt)) if (IS_ERR(algt))
return ERR_PTR(err); return ERR_CAST(algt);
if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask) if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
@ -711,9 +710,8 @@ static struct crypto_instance *crypto_gcm_alloc_common(struct rtattr **tb,
ghash_alg = crypto_find_alg(ghash_name, &crypto_ahash_type, ghash_alg = crypto_find_alg(ghash_name, &crypto_ahash_type,
CRYPTO_ALG_TYPE_HASH, CRYPTO_ALG_TYPE_HASH,
CRYPTO_ALG_TYPE_AHASH_MASK); CRYPTO_ALG_TYPE_AHASH_MASK);
err = PTR_ERR(ghash_alg);
if (IS_ERR(ghash_alg)) if (IS_ERR(ghash_alg))
return ERR_PTR(err); return ERR_CAST(ghash_alg);
err = -ENOMEM; err = -ENOMEM;
inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL); inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL);
@ -787,15 +785,13 @@ out_put_ghash:
static struct crypto_instance *crypto_gcm_alloc(struct rtattr **tb) static struct crypto_instance *crypto_gcm_alloc(struct rtattr **tb)
{ {
int err;
const char *cipher_name; const char *cipher_name;
char ctr_name[CRYPTO_MAX_ALG_NAME]; char ctr_name[CRYPTO_MAX_ALG_NAME];
char full_name[CRYPTO_MAX_ALG_NAME]; char full_name[CRYPTO_MAX_ALG_NAME];
cipher_name = crypto_attr_alg_name(tb[1]); cipher_name = crypto_attr_alg_name(tb[1]);
err = PTR_ERR(cipher_name);
if (IS_ERR(cipher_name)) if (IS_ERR(cipher_name))
return ERR_PTR(err); return ERR_CAST(cipher_name);
if (snprintf(ctr_name, CRYPTO_MAX_ALG_NAME, "ctr(%s)", cipher_name) >= if (snprintf(ctr_name, CRYPTO_MAX_ALG_NAME, "ctr(%s)", cipher_name) >=
CRYPTO_MAX_ALG_NAME) CRYPTO_MAX_ALG_NAME)
@ -826,20 +822,17 @@ static struct crypto_template crypto_gcm_tmpl = {
static struct crypto_instance *crypto_gcm_base_alloc(struct rtattr **tb) static struct crypto_instance *crypto_gcm_base_alloc(struct rtattr **tb)
{ {
int err;
const char *ctr_name; const char *ctr_name;
const char *ghash_name; const char *ghash_name;
char full_name[CRYPTO_MAX_ALG_NAME]; char full_name[CRYPTO_MAX_ALG_NAME];
ctr_name = crypto_attr_alg_name(tb[1]); ctr_name = crypto_attr_alg_name(tb[1]);
err = PTR_ERR(ctr_name);
if (IS_ERR(ctr_name)) if (IS_ERR(ctr_name))
return ERR_PTR(err); return ERR_CAST(ctr_name);
ghash_name = crypto_attr_alg_name(tb[2]); ghash_name = crypto_attr_alg_name(tb[2]);
err = PTR_ERR(ghash_name);
if (IS_ERR(ghash_name)) if (IS_ERR(ghash_name))
return ERR_PTR(err); return ERR_CAST(ghash_name);
if (snprintf(full_name, CRYPTO_MAX_ALG_NAME, "gcm_base(%s,%s)", if (snprintf(full_name, CRYPTO_MAX_ALG_NAME, "gcm_base(%s,%s)",
ctr_name, ghash_name) >= CRYPTO_MAX_ALG_NAME) ctr_name, ghash_name) >= CRYPTO_MAX_ALG_NAME)
@ -971,17 +964,15 @@ static struct crypto_instance *crypto_rfc4106_alloc(struct rtattr **tb)
int err; int err;
algt = crypto_get_attr_type(tb); algt = crypto_get_attr_type(tb);
err = PTR_ERR(algt);
if (IS_ERR(algt)) if (IS_ERR(algt))
return ERR_PTR(err); return ERR_CAST(algt);
if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask) if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
ccm_name = crypto_attr_alg_name(tb[1]); ccm_name = crypto_attr_alg_name(tb[1]);
err = PTR_ERR(ccm_name);
if (IS_ERR(ccm_name)) if (IS_ERR(ccm_name))
return ERR_PTR(err); return ERR_CAST(ccm_name);
inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL); inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL);
if (!inst) if (!inst)
@ -1222,17 +1213,15 @@ static struct crypto_instance *crypto_rfc4543_alloc(struct rtattr **tb)
int err; int err;
algt = crypto_get_attr_type(tb); algt = crypto_get_attr_type(tb);
err = PTR_ERR(algt);
if (IS_ERR(algt)) if (IS_ERR(algt))
return ERR_PTR(err); return ERR_CAST(algt);
if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask) if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
ccm_name = crypto_attr_alg_name(tb[1]); ccm_name = crypto_attr_alg_name(tb[1]);
err = PTR_ERR(ccm_name);
if (IS_ERR(ccm_name)) if (IS_ERR(ccm_name))
return ERR_PTR(err); return ERR_CAST(ccm_name);
inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL); inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL);
if (!inst) if (!inst)

View File

@ -305,9 +305,8 @@ static struct crypto_instance *seqiv_alloc(struct rtattr **tb)
int err; int err;
algt = crypto_get_attr_type(tb); algt = crypto_get_attr_type(tb);
err = PTR_ERR(algt);
if (IS_ERR(algt)) if (IS_ERR(algt))
return ERR_PTR(err); return ERR_CAST(algt);
err = crypto_get_default_rng(); err = crypto_get_default_rng();
if (err) if (err)