public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Boris Brezillon <boris.brezillon@free-electrons.com>
To: Arvind Yadav <arvind.yadav.cs@gmail.com>
Cc: robert.jarzmik@free.fr, dwmw2@infradead.org,
	computersforpeace@gmail.com, marek.vasut@gmail.com,
	richard@nod.at, cyrille.pitchen@atmel.com,
	linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [V2] mtd: devices: docg3:- Handle return value of devm_ioremap.
Date: Mon, 12 Dec 2016 09:42:18 +0100	[thread overview]
Message-ID: <20161212094218.2d29b34a@bbrezillon> (raw)
In-Reply-To: <1481511604-6116-1-git-send-email-arvind.yadav.cs@gmail.com>

On Mon, 12 Dec 2016 08:30:04 +0530
Arvind Yadav <arvind.yadav.cs@gmail.com> wrote:

> Here, If devm_ioremap will fail. It will return NULL.
> Kernel can run into a NULL-pointer dereference.
> 
> Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
> ---
>  drivers/mtd/devices/docg3.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c
> index b833e6c..ffe3db0 100644
> --- a/drivers/mtd/devices/docg3.c
> +++ b/drivers/mtd/devices/docg3.c
> @@ -2083,9 +2083,14 @@ static int __init docg3_probe(struct platform_device *pdev)
>  		dev_err(dev, "No I/O memory resource defined\n");
>  		return ret;
>  	}
> -	base = devm_ioremap(dev, ress->start, DOC_IOSPACE_SIZE);
>  
>  	ret = -ENOMEM;
> +	base = devm_ioremap(dev, ress->start, DOC_IOSPACE_SIZE);
> +	if (!base) {
> +		dev_err(dev, "failed to map I/O memory\n");
> +		return ret;
> +	}
> +
>  	cascade = devm_kzalloc(dev, sizeof(*cascade) * DOC_MAX_NBFLOORS,
>  			       GFP_KERNEL);
>  	if (!cascade)

How about going even further and doing the following?
This way you can drop the test on rres (it's done for you in
devm_ioremap_resource()), and you can directly return the error
returned by devm_ioremap_resource().

--->8---
diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c
index b833e6cc684c..c59b91734344 100644
--- a/drivers/mtd/devices/docg3.c
+++ b/drivers/mtd/devices/docg3.c
@@ -2077,13 +2077,10 @@ static int __init docg3_probe(struct
platform_device *pdev) int ret, floor;
        struct docg3_cascade *cascade;
 
-       ret = -ENXIO;
        ress = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-       if (!ress) {
-               dev_err(dev, "No I/O memory resource defined\n");
-               return ret;
-       }
-       base = devm_ioremap(dev, ress->start, DOC_IOSPACE_SIZE);
+       base = devm_ioremap_resource(dev, ress);
+       if (IS_ERR(base))
+               return PTR_ERR(base);
 
        ret = -ENOMEM;
        cascade = devm_kzalloc(dev, sizeof(*cascade) * DOC_MAX_NBFLOORS,

  parent reply	other threads:[~2016-12-12  8:42 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-12  3:00 [V2] mtd: devices: docg3:- Handle return value of devm_ioremap Arvind Yadav
2016-12-12  4:10 ` Marek Vasut
2016-12-12  8:42 ` Boris Brezillon [this message]
2016-12-12 16:03   ` arvind Yadav
2016-12-12 16:32     ` Robert Jarzmik
2016-12-12 17:00       ` Boris Brezillon
2016-12-12 17:04     ` Boris Brezillon
2016-12-12 18:15       ` arvind Yadav

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161212094218.2d29b34a@bbrezillon \
    --to=boris.brezillon@free-electrons.com \
    --cc=arvind.yadav.cs@gmail.com \
    --cc=computersforpeace@gmail.com \
    --cc=cyrille.pitchen@atmel.com \
    --cc=dwmw2@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=marek.vasut@gmail.com \
    --cc=richard@nod.at \
    --cc=robert.jarzmik@free.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox