* [PATCH] mtd: ck804xrom: fix missing pci device put in error paths
@ 2020-08-21 7:05 James Bond
2020-08-27 12:46 ` Miquel Raynal
0 siblings, 1 reply; 4+ messages in thread
From: James Bond @ 2020-08-21 7:05 UTC (permalink / raw)
To: jameslouisebond
Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
Arnd Bergmann, Ryan Jackson, David Woodhouse, linux-mtd,
linux-kernel
pci_dev_get increases the refcount of "pdev".
In the error paths, pci_dev_put should be called
to handle the "pdev" and decrease the corresponding refcount.
Fixes: 90afffc8bd79 ("[MTD] [MAPS] Support for BIOS flash chips on the nvidia ck804 southbridge")
Signed-off-by: James Bond <jameslouisebond@gmail.com>
---
drivers/mtd/maps/ck804xrom.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/mtd/maps/ck804xrom.c b/drivers/mtd/maps/ck804xrom.c
index 460494212f6a..16af8b5ee653 100644
--- a/drivers/mtd/maps/ck804xrom.c
+++ b/drivers/mtd/maps/ck804xrom.c
@@ -195,6 +195,7 @@ static int __init ck804xrom_init_one(struct pci_dev *pdev,
if (!window->virt) {
printk(KERN_ERR MOD_NAME ": ioremap(%08lx, %08lx) failed\n",
window->phys, window->size);
+ pci_dev_put(pdev);
goto out;
}
@@ -222,6 +223,7 @@ static int __init ck804xrom_init_one(struct pci_dev *pdev,
if (!map) {
printk(KERN_ERR MOD_NAME ": kmalloc failed");
+ pci_dev_put(pdev);
goto out;
}
memset(map, 0, sizeof(*map));
@@ -295,6 +297,7 @@ static int __init ck804xrom_init_one(struct pci_dev *pdev,
if (mtd_device_register(map->mtd, NULL, 0)) {
map_destroy(map->mtd);
map->mtd = NULL;
+ pci_dev_put(pdev);
goto out;
}
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] mtd: ck804xrom: fix missing pci device put in error paths
2020-08-21 7:05 [PATCH] mtd: ck804xrom: fix missing pci device put in error paths James Bond
@ 2020-08-27 12:46 ` Miquel Raynal
2020-08-29 2:28 ` James Bond
0 siblings, 1 reply; 4+ messages in thread
From: Miquel Raynal @ 2020-08-27 12:46 UTC (permalink / raw)
To: James Bond
Cc: Vignesh Raghavendra, Arnd Bergmann, Ryan Jackson,
Richard Weinberger, linux-kernel, linux-mtd, David Woodhouse
Hi James,
James Bond <jameslouisebond@gmail.com> wrote on Fri, 21 Aug 2020
02:05:36 -0500:
> pci_dev_get increases the refcount of "pdev".
> In the error paths, pci_dev_put should be called
> to handle the "pdev" and decrease the corresponding refcount.
>
> Fixes: 90afffc8bd79 ("[MTD] [MAPS] Support for BIOS flash chips on the nvidia ck804 southbridge")
> Signed-off-by: James Bond <jameslouisebond@gmail.com>
> ---
> drivers/mtd/maps/ck804xrom.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/mtd/maps/ck804xrom.c b/drivers/mtd/maps/ck804xrom.c
> index 460494212f6a..16af8b5ee653 100644
> --- a/drivers/mtd/maps/ck804xrom.c
> +++ b/drivers/mtd/maps/ck804xrom.c
> @@ -195,6 +195,7 @@ static int __init ck804xrom_init_one(struct pci_dev *pdev,
> if (!window->virt) {
> printk(KERN_ERR MOD_NAME ": ioremap(%08lx, %08lx) failed\n",
> window->phys, window->size);
> + pci_dev_put(pdev);
> goto out;
> }
>
> @@ -222,6 +223,7 @@ static int __init ck804xrom_init_one(struct pci_dev *pdev,
>
> if (!map) {
> printk(KERN_ERR MOD_NAME ": kmalloc failed");
> + pci_dev_put(pdev);
> goto out;
> }
> memset(map, 0, sizeof(*map));
> @@ -295,6 +297,7 @@ static int __init ck804xrom_init_one(struct pci_dev *pdev,
> if (mtd_device_register(map->mtd, NULL, 0)) {
> map_destroy(map->mtd);
> map->mtd = NULL;
> + pci_dev_put(pdev);
> goto out;
> }
>
I suppose in these three cases, the window->maps list will be empty and
you will end up returning -ENODEV and the bottom of the function? If
yes, it woudl probably be better to move these pci_dev_put() calls to
this location.
Otherwise, it might bit interesting to clean up a little bit the error
path and perhaps have a distinct success vs. failure path.
Thanks,
Miquèl
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mtd: ck804xrom: fix missing pci device put in error paths
2020-08-27 12:46 ` Miquel Raynal
@ 2020-08-29 2:28 ` James Bond
2020-08-31 12:00 ` Miquel Raynal
0 siblings, 1 reply; 4+ messages in thread
From: James Bond @ 2020-08-29 2:28 UTC (permalink / raw)
To: Miquel Raynal
Cc: Vignesh Raghavendra, Arnd Bergmann, Ryan Jackson,
Richard Weinberger, linux-kernel, linux-mtd, David Woodhouse
Hi Miquèl,
Thanks for your feedback.
I have just rechecked this function and find that "pdev" currently is
already put
inside ck804xrom_cleanup, so my previous patch is meaningless...
The current calling order is like:
window->pdev = pci_dev_get(pdev);
...
ck804xrom_cleanup(window)
->
pci_dev_put(window->pdev);
And sorry for bothering you.
Thanks,
James
On Thu, Aug 27, 2020 at 7:46 AM Miquel Raynal <miquel.raynal@bootlin.com> wrote:
>
> Hi James,
>
> James Bond <jameslouisebond@gmail.com> wrote on Fri, 21 Aug 2020
> 02:05:36 -0500:
>
> > pci_dev_get increases the refcount of "pdev".
> > In the error paths, pci_dev_put should be called
> > to handle the "pdev" and decrease the corresponding refcount.
> >
> > Fixes: 90afffc8bd79 ("[MTD] [MAPS] Support for BIOS flash chips on the nvidia ck804 southbridge")
> > Signed-off-by: James Bond <jameslouisebond@gmail.com>
> > ---
> > drivers/mtd/maps/ck804xrom.c | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> > diff --git a/drivers/mtd/maps/ck804xrom.c b/drivers/mtd/maps/ck804xrom.c
> > index 460494212f6a..16af8b5ee653 100644
> > --- a/drivers/mtd/maps/ck804xrom.c
> > +++ b/drivers/mtd/maps/ck804xrom.c
> > @@ -195,6 +195,7 @@ static int __init ck804xrom_init_one(struct pci_dev *pdev,
> > if (!window->virt) {
> > printk(KERN_ERR MOD_NAME ": ioremap(%08lx, %08lx) failed\n",
> > window->phys, window->size);
> > + pci_dev_put(pdev);
> > goto out;
> > }
> >
> > @@ -222,6 +223,7 @@ static int __init ck804xrom_init_one(struct pci_dev *pdev,
> >
> > if (!map) {
> > printk(KERN_ERR MOD_NAME ": kmalloc failed");
> > + pci_dev_put(pdev);
> > goto out;
> > }
> > memset(map, 0, sizeof(*map));
> > @@ -295,6 +297,7 @@ static int __init ck804xrom_init_one(struct pci_dev *pdev,
> > if (mtd_device_register(map->mtd, NULL, 0)) {
> > map_destroy(map->mtd);
> > map->mtd = NULL;
> > + pci_dev_put(pdev);
> > goto out;
> > }
> >
>
> I suppose in these three cases, the window->maps list will be empty and
> you will end up returning -ENODEV and the bottom of the function? If
> yes, it woudl probably be better to move these pci_dev_put() calls to
> this location.
>
> Otherwise, it might bit interesting to clean up a little bit the error
> path and perhaps have a distinct success vs. failure path.
>
>
> Thanks,
> Miquèl
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mtd: ck804xrom: fix missing pci device put in error paths
2020-08-29 2:28 ` James Bond
@ 2020-08-31 12:00 ` Miquel Raynal
0 siblings, 0 replies; 4+ messages in thread
From: Miquel Raynal @ 2020-08-31 12:00 UTC (permalink / raw)
To: James Bond
Cc: Vignesh Raghavendra, Arnd Bergmann, Ryan Jackson,
Richard Weinberger, linux-kernel, linux-mtd, David Woodhouse
Hi James,
James Bond <jameslouisebond@gmail.com> wrote on Fri, 28 Aug 2020
21:28:40 -0500:
> Hi Miquèl,
> Thanks for your feedback.
> I have just rechecked this function and find that "pdev" currently is
> already put
> inside ck804xrom_cleanup, so my previous patch is meaningless...
> The current calling order is like:
>
> window->pdev = pci_dev_get(pdev);
> ...
> ck804xrom_cleanup(window)
> ->
> pci_dev_put(window->pdev);
> And sorry for bothering you.
Ok that's fine, thanks anyway!
Miquèl
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-08-31 12:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-21 7:05 [PATCH] mtd: ck804xrom: fix missing pci device put in error paths James Bond
2020-08-27 12:46 ` Miquel Raynal
2020-08-29 2:28 ` James Bond
2020-08-31 12:00 ` Miquel Raynal
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).