linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vignesh Raghavendra <vigneshr@ti.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Wei Yongjun <weiyongjun1@huawei.com>,
	Kishon Vijay Abraham I <kishon@ti.com>,
	Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
	Rob Herring <robh@kernel.org>,
	Bjorn Helgaas <bhelgaas@google.com>, <linux-omap@vger.kernel.org>,
	<linux-pci@vger.kernel.org>, <kernel-janitors@vger.kernel.org>
Subject: Re: [PATCH -next] PCI: dwc: pci-dra7xx: Fix potential NULL dereference in dra7xx_pcie_probe()
Date: Tue, 28 Apr 2020 21:45:51 +0530	[thread overview]
Message-ID: <ebb4db96-08ef-64fe-5331-291f054562ed@ti.com> (raw)
In-Reply-To: <20200428130734.GF2014@kadam>



On 28/04/20 6:37 pm, Dan Carpenter wrote:
> On Mon, Apr 27, 2020 at 05:29:50PM +0530, Vignesh Raghavendra wrote:
>> Hi,
>>
>> On 27/04/20 4:40 pm, 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\|platform_get_resource_byname\)(pdev, t, n);
>>> + if (!res)
>>> +   return -EINVAL;
>>> ... when != res == NULL
>>> e = devm_ioremap(e1, res->start, e2);
>>>
>>> Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
>>> ---
>>>  drivers/pci/controller/dwc/pci-dra7xx.c | 3 +++
>>>  1 file changed, 3 insertions(+)
>>>
>>> diff --git a/drivers/pci/controller/dwc/pci-dra7xx.c b/drivers/pci/controller/dwc/pci-dra7xx.c
>>> index 3b0e58f2de58..7a3d12f7e7d9 100644
>>> --- a/drivers/pci/controller/dwc/pci-dra7xx.c
>>> +++ b/drivers/pci/controller/dwc/pci-dra7xx.c
>>> @@ -878,6 +878,9 @@ static int __init dra7xx_pcie_probe(struct platform_device *pdev)
>>>  	}
>>>  
>>>  	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ti_conf");
>                                            ^^^^
> 
>>> +	if (!res)
>>> +		return -EINVAL;
>>> +
>>>  	base = devm_ioremap(dev, res->start, resource_size(res));
>                             ^^^
>>
>> I don't see why this should be devm_ioremap(). It should also have been
>> devm_ioremap_resource() which does the NULL check.
> 
> It's different device pointers.
> 

Sorry, I don't understand this comment... Currently we have:

static int __init dra7xx_pcie_probe(struct platform_device *pdev)
{
        struct device *dev = &pdev->dev;
	...
	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ti_conf");
        base = devm_ioremap(dev, res->start, resource_size(res));
        if (!base)
                return -ENOMEM;

Instead of the proposed patch, what I am asking is:

	base = devm_platform_ioremap_resource_byname(pdev, "ti_conf");
	if (IS_ERR(base))
		return PTR_ERR(base);




> regards,
> dan carpenter
> 

  reply	other threads:[~2020-04-28 16:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-27 11:10 [PATCH -next] PCI: dwc: pci-dra7xx: Fix potential NULL dereference in dra7xx_pcie_probe() Wei Yongjun
2020-04-27 11:59 ` Vignesh Raghavendra
2020-04-28 13:07   ` Dan Carpenter
2020-04-28 16:15     ` Vignesh Raghavendra [this message]
2020-04-28 17:23       ` Dan Carpenter
2020-04-29  1:50 ` [PATCH -next v2] PCI: dwc: pci-dra7xx: use devm_platform_ioremap_resource_byname() Wei Yongjun
2020-05-05 10:54   ` Lorenzo Pieralisi

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=ebb4db96-08ef-64fe-5331-291f054562ed@ti.com \
    --to=vigneshr@ti.com \
    --cc=bhelgaas@google.com \
    --cc=dan.carpenter@oracle.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=kishon@ti.com \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=robh@kernel.org \
    --cc=weiyongjun1@huawei.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;
as well as URLs for NNTP newsgroup(s).