2010-05-22 09:59:53

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 2/8] crypto: Use ERR_CAST

From: Julia Lawall <[email protected]>

Use ERR_CAST(x) rather than ERR_PTR(PTR_ERR(x)). The former makes more
clear what is the purpose of the operation, which otherwise looks like a
no-op.

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

// <smpl>
@@
type T;
T x;
identifier f;
@@

T f (...) { <+...
- ERR_PTR(PTR_ERR(x))
+ x
...+> }

@@
expression x;
@@

- ERR_PTR(PTR_ERR(x))
+ ERR_CAST(x)
// </smpl>

Signed-off-by: Julia Lawall <[email protected]>

---
crypto/authenc.c | 2 +-
crypto/ctr.c | 2 +-
crypto/xts.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)

diff -u -p a/crypto/authenc.c b/crypto/authenc.c
--- a/crypto/authenc.c
+++ b/crypto/authenc.c
@@ -612,7 +612,7 @@ static struct crypto_instance *crypto_au
auth = ahash_attr_alg(tb[1], CRYPTO_ALG_TYPE_HASH,
CRYPTO_ALG_TYPE_AHASH_MASK);
if (IS_ERR(auth))
- return ERR_PTR(PTR_ERR(auth));
+ return ERR_CAST(auth);

auth_base = &auth->base;

diff -u -p a/crypto/ctr.c b/crypto/ctr.c
--- a/crypto/ctr.c
+++ b/crypto/ctr.c
@@ -185,7 +185,7 @@ static struct crypto_instance *crypto_ct
alg = crypto_attr_alg(tb[1], CRYPTO_ALG_TYPE_CIPHER,
CRYPTO_ALG_TYPE_MASK);
if (IS_ERR(alg))
- return ERR_PTR(PTR_ERR(alg));
+ return ERR_CAST(alg);

/* Block size must be >= 4 bytes. */
err = -EINVAL;
diff -u -p a/crypto/xts.c b/crypto/xts.c
--- a/crypto/xts.c
+++ b/crypto/xts.c
@@ -224,7 +224,7 @@ static struct crypto_instance *alloc(str
alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_CIPHER,
CRYPTO_ALG_TYPE_MASK);
if (IS_ERR(alg))
- return ERR_PTR(PTR_ERR(alg));
+ return ERR_CAST(alg);

inst = crypto_alloc_instance("xts", alg);
if (IS_ERR(inst))


2010-05-26 00:37:10

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH 2/8] crypto: Use ERR_CAST

On Sat, May 22, 2010 at 11:59:48AM +0200, Julia Lawall wrote:
> From: Julia Lawall <[email protected]>
>
> Use ERR_CAST(x) rather than ERR_PTR(PTR_ERR(x)). The former makes more
> clear what is the purpose of the operation, which otherwise looks like a
> no-op.

Patch applied. Thanks Julia.
--
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