2008-04-29 13:38:22

by Julia Lawall

[permalink] [raw]
Subject: [PATCH] crypto: Correct kzalloc error test

From: Julia Lawall <[email protected]>

Normally, kzalloc returns NULL or a valid pointer value, not a value to be
tested using IS_ERR.

Signed-off-by: Julia Lawall <[email protected]>
---
diff -u -p a/crypto/cryptd.c b/crypto/cryptd.c
--- a/crypto/cryptd.c 2008-04-16 13:27:56.000000000 +0200
+++ b/crypto/cryptd.c 2008-04-29 15:29:54.000000000 +0200
@@ -190,7 +190,7 @@ static struct crypto_instance *cryptd_al
int err;

inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL);
- if (IS_ERR(inst))
+ if (!inst)
goto out;

err = -ENAMETOOLONG;


2008-04-29 14:07:43

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH] crypto: Correct kzalloc error test

Julia Lawall <[email protected]> wrote:
> From: Julia Lawall <[email protected]>
>
> Normally, kzalloc returns NULL or a valid pointer value, not a value to be
> tested using IS_ERR.

Ouch :)

> diff -u -p a/crypto/cryptd.c b/crypto/cryptd.c
> --- a/crypto/cryptd.c 2008-04-16 13:27:56.000000000 +0200
> +++ b/crypto/cryptd.c 2008-04-29 15:29:54.000000000 +0200
> @@ -190,7 +190,7 @@ static struct crypto_instance *cryptd_al
> int err;
>
> inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL);
> - if (IS_ERR(inst))
> + if (!inst)
> goto out;

However, this function is expected to return an ERR_PTR so you'll
need set it to ENOMEM first.

Thanks,
--
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

2008-04-29 14:18:11

by Julia Lawall

[permalink] [raw]
Subject: Re: [revised PATCH] crypto: Correct kzalloc error test

From: Julia Lawall <[email protected]>

Normally, kzalloc returns NULL or a valid pointer value, not a value to be
tested using IS_ERR.

Signed-off-by: Julia Lawall <[email protected]>
---
diff -u -p a/crypto/cryptd.c b/crypto/cryptd.c
--- a/crypto/cryptd.c 2008-04-16 13:27:56.000000000 +0200
+++ b/crypto/cryptd.c 2008-04-29 16:13:10.000000000 +0200
@@ -190,8 +190,10 @@ static struct crypto_instance *cryptd_al
int err;

inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL);
- if (IS_ERR(inst))
+ if (!inst) {
+ inst = ERR_PTR(-ENOMEM);
goto out;
+ }

err = -ENAMETOOLONG;
if (snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME,

2008-04-29 16:28:05

by Herbert Xu

[permalink] [raw]
Subject: Re: [revised PATCH] crypto: Correct kzalloc error test

On Tue, Apr 29, 2008 at 04:18:08PM +0200, Julia Lawall wrote:
> From: Julia Lawall <[email protected]>
>
> Normally, kzalloc returns NULL or a valid pointer value, not a value to be
> tested using IS_ERR.
>
> Signed-off-by: Julia Lawall <[email protected]>

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