DMA Engine development
 help / color / mirror / Atom feed
From: Lars-Peter Clausen <lars@metafoo.de>
To: Wei Yongjun <weiyongjun1@huawei.com>,
	Dan Williams <dan.j.williams@intel.com>,
	Vinod Koul <vkoul@kernel.org>, Orson Zhai <orsonzhai@gmail.com>,
	Baolin Wang <baolin.wang@linaro.org>,
	Chunyan Zhang <zhang.lyra@gmail.com>
Cc: dmaengine@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: [-next] dmaengine: sprd: Fix potential NULL dereference in sprd_dma_probe()
Date: Tue, 8 May 2018 13:46:23 +0200	[thread overview]
Message-ID: <6a99ed9b-ef0c-98c8-b750-2be730774aa4@metafoo.de> (raw)

On 05/07/2018 03:40 AM, Wei Yongjun wrote:
> platform_get_resource() may fail and return NULL, so we should
> better check it's return value to avoid a NULL pointer dereference
> a bit later in the code.
> 
> This is detected by Coccinelle semantic patch.
> 
> @@
> expression pdev, res, n, t, e, e1, e2;
> @@
> 
> res = platform_get_resource(pdev, t, n);
> + if (!res)
> +   return -EINVAL;
> ... when != res == NULL
> e = devm_ioremap_nocache(e1, res->start, e2);
> 
> Fixes: 9b3b8171f7f4 ("dmaengine: sprd: Add Spreadtrum DMA driver")
> Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
> ---
>  drivers/dma/sprd-dma.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/dma/sprd-dma.c b/drivers/dma/sprd-dma.c
> index ccdeb8f..dba7a17 100644
> --- a/drivers/dma/sprd-dma.c
> +++ b/drivers/dma/sprd-dma.c
> @@ -807,6 +807,8 @@ static int sprd_dma_probe(struct platform_device *pdev)
>  	}
>  
>  	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	if (!res)
> +		return -EINVAL;
>  	sdev->glb_base = devm_ioremap_nocache(&pdev->dev, res->start,
>  					      resource_size(res));

I think a better improvement would be to replace this with
devm_ioremap_resource() which has the NULL pointer check and some other
things built-in.
---
To unsubscribe from this list: send the line "unsubscribe dmaengine" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

             reply	other threads:[~2018-05-08 11:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-08 11:46 Lars-Peter Clausen [this message]
  -- strict thread matches above, loose matches on Subject: below --
2018-05-09  1:29 [-next] dmaengine: sprd: Fix potential NULL dereference in sprd_dma_probe() Baolin Wang
2018-05-08 12:10 Lars-Peter Clausen
2018-05-08 12:05 Vinod Koul
2018-05-07  8:04 Vinod Koul
2018-05-07  1:56 Baolin Wang
2018-05-07  1:40 weiyongjun (A)

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=6a99ed9b-ef0c-98c8-b750-2be730774aa4@metafoo.de \
    --to=lars@metafoo.de \
    --cc=baolin.wang@linaro.org \
    --cc=dan.j.williams@intel.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=orsonzhai@gmail.com \
    --cc=vkoul@kernel.org \
    --cc=weiyongjun1@huawei.com \
    --cc=zhang.lyra@gmail.com \
    /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