FAILED: patch "[PATCH] media: saa7164: add ioremap return checks and cleanups" failed to apply to 5.15-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x d51c60a498e83c9a79884c8e420f97e3885c9583
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026051559-refresh-willow-e717@gregkh' --subject-prefix 'PATCH 5.15.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From d51c60a498e83c9a79884c8e420f97e3885c9583 Mon Sep 17 00:00:00 2001
From: Wang Jun <[email protected]>
Date: Mon, 16 Mar 2026 20:24:01 +0800
Subject: [PATCH] media: saa7164: add ioremap return checks and cleanups
Add checks for ioremap return values in saa7164_dev_setup(). If ioremap for BAR0 or BAR2 fails, release the already allocated PCI memory regions, remove the device from the global list, decrement the device count, and return -ENODEV.
This prevents potential null pointer dereferences and ensures proper cleanup on memory mapping failures.
drivers/media/pci/saa7164/saa7164-core.c +35 -12
@@ -888,6 +888,15 @@ static int get_resources(struct saa7164_dev *dev)return -EBUSY ; } +static void release_resources (struct saa7164_dev *dev) +{ +release_mem_region (pci_resource_start (dev->pci,0 ), +pci_resource_len (dev->pci,0 )); + +release_mem_region (pci_resource_start (dev->pci,2 ), +pci_resource_len (dev->pci,2 )); +} +static int saa7164_port_init (struct saa7164_dev *dev,int portnr) {struct saa7164_port *port =NULL ;
@@ -947,9 +956,9 @@ static int saa7164_dev_setup(struct saa7164_dev *dev)snprintf (dev->name,sizeof (dev->name),"saa7164[%d]" , dev->nr); -mutex_lock (&devlist); -list_add_tail (&dev->devlist, &saa7164_devlist); -mutex_unlock (&devlist); + scoped_guard(mutex, &devlist) { +list_add_tail (&dev->devlist, &saa7164_devlist); + }/* board config */ dev->board =UNSET ;
@@ -996,11 +1005,17 @@ static int saa7164_dev_setup(struct saa7164_dev *dev) }/* PCI/e allocations */ - dev->lmmio =ioremap (pci_resource_start (dev->pci,0 ), -pci_resource_len (dev->pci,0 )); + dev->lmmio =pci_ioremap_bar (dev->pci,0 ); +if (!dev->lmmio) { +dev_err (&dev->pci->dev,"Failed to remap MMIO BAR 0\n" ); + goto err_ioremap_bar0; + } - dev->lmmio2 =ioremap (pci_resource_start (dev->pci,2 ), -pci_resource_len (dev->pci,2 )); + dev->lmmio2 =pci_ioremap_bar (dev->pci,2 ); +if (!dev->lmmio2) { +dev_err (&dev->pci->dev,"Failed to remap MMIO BAR 2\n" ); + goto err_ioremap_bar2; + } dev->bmmio = (u8 __iomem *)dev->lmmio; dev->bmmio2 = (u8 __iomem *)dev->lmmio2;
@@ -1019,17 +1034,25 @@ static int saa7164_dev_setup(struct saa7164_dev *dev)saa7164_pci_quirks (dev);return 0 ; + +err_ioremap_bar2: +iounmap (dev->lmmio); +err_ioremap_bar0: +release_resources (dev); + + scoped_guard(mutex, &devlist) { +list_del (&dev->devlist); + } + saa7164_devcount--; + +return -ENODEV ; }static void saa7164_dev_unregister (struct saa7164_dev *dev) {dprintk (1 ,"%s()\n" , __func__); -release_mem_region (pci_resource_start (dev->pci,0 ), -pci_resource_len (dev->pci,0 )); - -release_mem_region (pci_resource_start (dev->pci,2 ), -pci_resource_len (dev->pci,2 )); +release_resources (dev);if (!atomic_dec_and_test (&dev->refcount))return ;