* [PATCH] media: saa7164: fix cleanup on resource allocation failure
@ 2026-07-08 7:21 Guangshuo Li
2026-07-15 11:40 ` Hans Verkuil
0 siblings, 1 reply; 2+ messages in thread
From: Guangshuo Li @ 2026-07-08 7:21 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Kees Cook, Wang Jun, Guangshuo Li,
Hans Verkuil, Steven Toth, linux-media, linux-kernel
saa7164_dev_setup() adds the device to the global saa7164_devlist before
requesting the PCI BAR memory regions.
If get_resources() fails, saa7164_dev_setup() decrements the device count
and returns an error, but leaves the device on saa7164_devlist. The probe
error path then frees the device, leaving a dangling entry on the global
list.
Remove the device from saa7164_devlist before returning from the
get_resources() failure path, matching the cleanup done by the ioremap
failure paths.
Also release BAR0 if BAR0 was successfully requested but the BAR2
request fails.
Fixes: 443c1228d505 ("V4L/DVB (12923): SAA7164: Add support for the NXP SAA7164 silicon")
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
drivers/media/pci/saa7164/saa7164-core.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/media/pci/saa7164/saa7164-core.c b/drivers/media/pci/saa7164/saa7164-core.c
index 6bcde506adf5..225dbd3650da 100644
--- a/drivers/media/pci/saa7164/saa7164-core.c
+++ b/drivers/media/pci/saa7164/saa7164-core.c
@@ -878,6 +878,9 @@ static int get_resources(struct saa7164_dev *dev)
if (request_mem_region(pci_resource_start(dev->pci, 2),
pci_resource_len(dev->pci, 2), dev->name))
return 0;
+
+ release_mem_region(pci_resource_start(dev->pci, 0),
+ pci_resource_len(dev->pci, 0));
}
printk(KERN_ERR "%s: can't get MMIO memory @ 0x%llx or 0x%llx\n",
@@ -999,6 +1002,9 @@ static int saa7164_dev_setup(struct saa7164_dev *dev)
printk(KERN_ERR "CORE %s No more PCIe resources for subsystem: %04x:%04x\n",
dev->name, dev->pci->subsystem_vendor,
dev->pci->subsystem_device);
+ scoped_guard(mutex, &devlist) {
+ list_del(&dev->devlist);
+ }
saa7164_devcount--;
return -ENODEV;
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] media: saa7164: fix cleanup on resource allocation failure
2026-07-08 7:21 [PATCH] media: saa7164: fix cleanup on resource allocation failure Guangshuo Li
@ 2026-07-15 11:40 ` Hans Verkuil
0 siblings, 0 replies; 2+ messages in thread
From: Hans Verkuil @ 2026-07-15 11:40 UTC (permalink / raw)
To: Guangshuo Li, Mauro Carvalho Chehab, Kees Cook, Wang Jun,
Steven Toth, linux-media, linux-kernel
On 08/07/2026 09:21, Guangshuo Li wrote:
> saa7164_dev_setup() adds the device to the global saa7164_devlist before
> requesting the PCI BAR memory regions.
>
> If get_resources() fails, saa7164_dev_setup() decrements the device count
> and returns an error, but leaves the device on saa7164_devlist. The probe
> error path then frees the device, leaving a dangling entry on the global
> list.
>
> Remove the device from saa7164_devlist before returning from the
> get_resources() failure path, matching the cleanup done by the ioremap
> failure paths.
>
> Also release BAR0 if BAR0 was successfully requested but the BAR2
> request fails.
>
> Fixes: 443c1228d505 ("V4L/DVB (12923): SAA7164: Add support for the NXP SAA7164 silicon")
> Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
> ---
> drivers/media/pci/saa7164/saa7164-core.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/drivers/media/pci/saa7164/saa7164-core.c b/drivers/media/pci/saa7164/saa7164-core.c
> index 6bcde506adf5..225dbd3650da 100644
> --- a/drivers/media/pci/saa7164/saa7164-core.c
> +++ b/drivers/media/pci/saa7164/saa7164-core.c
> @@ -878,6 +878,9 @@ static int get_resources(struct saa7164_dev *dev)
> if (request_mem_region(pci_resource_start(dev->pci, 2),
> pci_resource_len(dev->pci, 2), dev->name))
> return 0;
> +
> + release_mem_region(pci_resource_start(dev->pci, 0),
> + pci_resource_len(dev->pci, 0));
> }
>
> printk(KERN_ERR "%s: can't get MMIO memory @ 0x%llx or 0x%llx\n",
> @@ -999,6 +1002,9 @@ static int saa7164_dev_setup(struct saa7164_dev *dev)
> printk(KERN_ERR "CORE %s No more PCIe resources for subsystem: %04x:%04x\n",
> dev->name, dev->pci->subsystem_vendor,
> dev->pci->subsystem_device);
> + scoped_guard(mutex, &devlist) {
> + list_del(&dev->devlist);
> + }
>
> saa7164_devcount--;
This should just be a goto into the error handling. You just need to add a new goto label
right after the 'release_resources' call.
> return -ENODEV;
This patch looks good otherwise.
Regards,
Hans
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-15 11:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-08 7:21 [PATCH] media: saa7164: fix cleanup on resource allocation failure Guangshuo Li
2026-07-15 11:40 ` Hans Verkuil
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.