* [PATCH][next] PCI: mediatek-gen3: Add missing null pointer check
@ 2021-04-29 11:00 Colin King
2021-04-30 7:24 ` Jianjun Wang
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Colin King @ 2021-04-29 11:00 UTC (permalink / raw)
To: Ryder Lee, Jianjun Wang, Lorenzo Pieralisi, Rob Herring,
Bjorn Helgaas, Matthias Brugger, linux-pci, linux-mediatek,
linux-arm-kernel
Cc: kernel-janitors, linux-kernel
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");
--
2.30.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH][next] PCI: mediatek-gen3: Add missing null pointer check
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 8:40 ` Lorenzo Pieralisi
2 siblings, 0 replies; 6+ messages in thread
From: Jianjun Wang @ 2021-04-30 7:24 UTC (permalink / raw)
To: Colin King
Cc: Ryder Lee, Lorenzo Pieralisi, Rob Herring, Bjorn Helgaas,
Matthias Brugger, linux-pci, linux-mediatek, linux-arm-kernel,
kernel-janitors, linux-kernel
Hi Colin,
On Thu, 2021-04-29 at 12:00 +0100, Colin King wrote:
> 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;
Thanks for your patch.
devm_ioremap_resource() will check and decode this null pointer
dereference error, so I don't think we need to check here.
Thanks.
> port->base = devm_ioremap_resource(dev, regs);
> if (IS_ERR(port->base)) {
> dev_err(dev, "failed to map register base\n");
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH][next] PCI: mediatek-gen3: Add missing null pointer check
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-04-30 8:40 ` Lorenzo Pieralisi
2 siblings, 1 reply; 6+ messages in thread
From: Christophe JAILLET @ 2021-04-30 7:47 UTC (permalink / raw)
To: Colin King, Ryder Lee, Jianjun Wang, Lorenzo Pieralisi,
Rob Herring, Bjorn Helgaas, Matthias Brugger, linux-pci,
linux-mediatek, linux-arm-kernel
Cc: kernel-janitors, linux-kernel
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.
Also, which git repo are you using? On linux-next ([1)], your proposed
patch is already part of "PCI: mediatek-gen3: Add MediaTek Gen3 driver
for MT8192".
[1]:
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/log/drivers/pci/controller/pcie-mediatek-gen3.c
CJ
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH][next] PCI: mediatek-gen3: Add missing null pointer check
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 8:40 ` Lorenzo Pieralisi
2 siblings, 0 replies; 6+ messages in thread
From: Lorenzo Pieralisi @ 2021-04-30 8:40 UTC (permalink / raw)
To: Colin King
Cc: Ryder Lee, Jianjun Wang, Rob Herring, Bjorn Helgaas,
Matthias Brugger, linux-pci, linux-mediatek, linux-arm-kernel,
kernel-janitors, linux-kernel
On Thu, Apr 29, 2021 at 12:00:40PM +0100, Colin King wrote:
> 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(+)
Squashed into the commit it is fixing, in my pci/mediatek branch.
Thanks,
Lorenzo
> 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");
> --
> 2.30.2
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH][next] PCI: mediatek-gen3: Add missing null pointer check
2021-04-30 7:47 ` Christophe JAILLET
@ 2021-04-30 16:34 ` Bjorn Helgaas
2021-05-03 7:03 ` Dan Carpenter
0 siblings, 1 reply; 6+ messages in thread
From: Bjorn Helgaas @ 2021-04-30 16:34 UTC (permalink / raw)
To: Christophe JAILLET
Cc: Colin King, Ryder Lee, Jianjun Wang, Lorenzo Pieralisi,
Rob Herring, Bjorn Helgaas, Matthias Brugger, linux-pci,
linux-mediatek, linux-arm-kernel, kernel-janitors, linux-kernel
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.
Seems like something for next cycle since we're in the middle of the
merge window.
> Also, which git repo are you using? On linux-next ([1)], your proposed patch
> is already part of "PCI: mediatek-gen3: Add MediaTek Gen3 driver for
> MT8192".
>
> [1]: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/log/drivers/pci/controller/pcie-mediatek-gen3.c
I think this is because Lorenzo already squashed Colin's change in.
Bjorn
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH][next] PCI: mediatek-gen3: Add missing null pointer check
2021-04-30 16:34 ` Bjorn Helgaas
@ 2021-05-03 7:03 ` Dan Carpenter
0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2021-05-03 7:03 UTC (permalink / raw)
To: Bjorn Helgaas
Cc: Christophe JAILLET, Colin King, Ryder Lee, Jianjun Wang,
Lorenzo Pieralisi, Rob Herring, Bjorn Helgaas, Matthias Brugger,
linux-pci, linux-mediatek, linux-arm-kernel, kernel-janitors,
linux-kernel
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
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-05-03 7:04 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2021-04-30 8:40 ` Lorenzo Pieralisi
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).