From: Dan Carpenter <dan.carpenter@oracle.com>
To: Bjorn Helgaas <helgaas@kernel.org>
Cc: Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
Colin King <colin.king@canonical.com>,
Ryder Lee <ryder.lee@mediatek.com>,
Jianjun Wang <jianjun.wang@mediatek.com>,
Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
Rob Herring <robh@kernel.org>,
Bjorn Helgaas <bhelgaas@google.com>,
Matthias Brugger <matthias.bgg@gmail.com>,
linux-pci@vger.kernel.org, linux-mediatek@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH][next] PCI: mediatek-gen3: Add missing null pointer check
Date: Mon, 3 May 2021 10:03:51 +0300 [thread overview]
Message-ID: <20210503070351.GJ1981@kadam> (raw)
In-Reply-To: <20210430163450.GA657994@bjorn-Precision-5520>
On Fri, Apr 30, 2021 at 11:34:50AM -0500, Bjorn Helgaas wrote:
> On Fri, Apr 30, 2021 at 09:47:06AM +0200, Christophe JAILLET wrote:
> > Le 29/04/2021 à 13:00, Colin King a écrit :
> > > From: Colin Ian King <colin.king@canonical.com>
> > >
> > > The call to platform_get_resource_byname can potentially return null, so
> > > add a null pointer check to avoid a null pointer dereference issue.
> > >
> > > Addresses-Coverity: ("Dereference null return")
> > > Fixes: 441903d9e8f0 ("PCI: mediatek-gen3: Add MediaTek Gen3 driver for MT8192")
> > > Signed-off-by: Colin Ian King <colin.king@canonical.com>
> > > ---
> > > drivers/pci/controller/pcie-mediatek-gen3.c | 2 ++
> > > 1 file changed, 2 insertions(+)
> > >
> > > diff --git a/drivers/pci/controller/pcie-mediatek-gen3.c b/drivers/pci/controller/pcie-mediatek-gen3.c
> > > index 20165e4a75b2..3c5b97716d40 100644
> > > --- a/drivers/pci/controller/pcie-mediatek-gen3.c
> > > +++ b/drivers/pci/controller/pcie-mediatek-gen3.c
> > > @@ -721,6 +721,8 @@ static int mtk_pcie_parse_port(struct mtk_pcie_port *port)
> > > int ret;
> > > regs = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcie-mac");
> > > + if (!regs)
> > > + return -EINVAL;
> > > port->base = devm_ioremap_resource(dev, regs);
> > > if (IS_ERR(port->base)) {
> > > dev_err(dev, "failed to map register base\n");
> > >
> >
> > Nitpick:
> > Using 'devm_platform_ioremap_resource_byname' is slightly less verbose
> > and should please Coverity.
>
> Not a nitpick at all. Jianjun is correct that devm_ioremap_resource()
> does check "regs" for NULL and it fails gracefully before trying to
> dereference it, so the extra check shouldn't be needed. And most
> cases in drivers/pci/ look like this, without the extra check:
>
> res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "app");
> base = devm_ioremap_resource(dev, res);
> if (IS_ERR(base))
> ...
>
> If devm_platform_ioremap_resource_byname() keeps Coverity happy, I
> think that's what we should be doing across drivers/pci/. Coverity
> false positives are a hassle.
Smatch knows that devm_ioremap_resource() will return ERR_PTR(-EINVAL)
when we pass it a NULL. ;)
regards,
dan carpenter
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2021-05-03 7:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-29 11:00 [PATCH][next] PCI: mediatek-gen3: Add missing null pointer check Colin King
2021-04-30 7:24 ` Jianjun Wang
2021-04-30 7:47 ` Christophe JAILLET
2021-04-30 16:34 ` Bjorn Helgaas
2021-05-03 7:03 ` Dan Carpenter [this message]
2021-04-30 8:40 ` 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=20210503070351.GJ1981@kadam \
--to=dan.carpenter@oracle.com \
--cc=bhelgaas@google.com \
--cc=christophe.jaillet@wanadoo.fr \
--cc=colin.king@canonical.com \
--cc=helgaas@kernel.org \
--cc=jianjun.wang@mediatek.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-pci@vger.kernel.org \
--cc=lorenzo.pieralisi@arm.com \
--cc=matthias.bgg@gmail.com \
--cc=robh@kernel.org \
--cc=ryder.lee@mediatek.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).