2016-09-16 01:49:47

by Wei Yongjun

[permalink] [raw]
Subject: [PATCH -next] hwrng: amd - Fix return value check in mod_init()

From: Wei Yongjun <[email protected]>

In case of error, the function devm_kzalloc() or devm_ioport_map()
return NULL pointer not ERR_PTR(). The IS_ERR() test in the return
value check should be replaced with NULL test.

Fixes: 31b2a73c9c5f ("hwrng: amd - Migrate to managed API")
Signed-off-by: Wei Yongjun <[email protected]>
---
drivers/char/hw_random/amd-rng.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/char/hw_random/amd-rng.c b/drivers/char/hw_random/amd-rng.c
index 4dbc5aa..4a99ac7 100644
--- a/drivers/char/hw_random/amd-rng.c
+++ b/drivers/char/hw_random/amd-rng.c
@@ -149,8 +149,8 @@ static int __init mod_init(void)
return -EIO;

priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
- if (IS_ERR(priv))
- return PTR_ERR(priv);
+ if (!priv)
+ return -ENOMEM;

if (!devm_request_region(&pdev->dev, pmbase + PMBASE_OFFSET,
PMBASE_SIZE, DRV_NAME)) {
@@ -161,9 +161,9 @@ static int __init mod_init(void)

priv->iobase = devm_ioport_map(&pdev->dev, pmbase + PMBASE_OFFSET,
PMBASE_SIZE);
- if (IS_ERR(priv->iobase)) {
+ if (!priv->iobase) {
pr_err(DRV_NAME "Cannot map ioport\n");
- return PTR_ERR(priv->iobase);
+ return -ENOMEM;
}

amd_rng.priv = (unsigned long)priv;


Subject: Re: [PATCH -next] hwrng: amd - Fix return value check in mod_init()

> In case of error, the function devm_kzalloc() or devm_ioport_map()
> return NULL pointer not ERR_PTR(). The IS_ERR() test in the return
> value check should be replaced with NULL test.
>
> Fixes: 31b2a73c9c5f ("hwrng: amd - Migrate to managed API")
> Signed-off-by: Wei Yongjun <[email protected]>
> ---
> drivers/char/hw_random/amd-rng.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/char/hw_random/amd-rng.c b/drivers/char/hw_random/amd-rng.c
> index 4dbc5aa..4a99ac7 100644
> --- a/drivers/char/hw_random/amd-rng.c
> +++ b/drivers/char/hw_random/amd-rng.c
> @@ -149,8 +149,8 @@ static int __init mod_init(void)
> return -EIO;
>
> priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
> - if (IS_ERR(priv))
> - return PTR_ERR(priv);
> + if (!priv)
> + return -ENOMEM;
>
> if (!devm_request_region(&pdev->dev, pmbase + PMBASE_OFFSET,
> PMBASE_SIZE, DRV_NAME)) {
> @@ -161,9 +161,9 @@ static int __init mod_init(void)
>
> priv->iobase = devm_ioport_map(&pdev->dev, pmbase + PMBASE_OFFSET,
> PMBASE_SIZE);
> - if (IS_ERR(priv->iobase)) {
> + if (!priv->iobase) {
> pr_err(DRV_NAME "Cannot map ioport\n");
> - return PTR_ERR(priv->iobase);
> + return -ENOMEM;
> }
>
> amd_rng.priv = (unsigned long)priv;
>

My change introduced this issue. Thanks for fixing it.

2016-09-22 10:45:08

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH -next] hwrng: amd - Fix return value check in mod_init()

On Fri, Sep 16, 2016 at 01:49:41AM +0000, Wei Yongjun wrote:
> From: Wei Yongjun <[email protected]>
>
> In case of error, the function devm_kzalloc() or devm_ioport_map()
> return NULL pointer not ERR_PTR(). The IS_ERR() test in the return
> value check should be replaced with NULL test.
>
> Fixes: 31b2a73c9c5f ("hwrng: amd - Migrate to managed API")
> Signed-off-by: Wei Yongjun <[email protected]>

Patch applied. Thanks.
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt