Commit 8225489d authored by Artem Lytkin's avatar Artem Lytkin Committed by Greg Kroah-Hartman
Browse files

staging: sm750fb: add missing pci_release_region on error and removal



hw_sm750_map() calls pci_request_region() but never releases the
region on error paths or in lynxfb_pci_remove(). This causes a
resource leak that prevents the PCI region from being mapped again
after driver removal or a failed probe. A TODO comment in the code
acknowledges this missing cleanup.

Restructure the error handling in hw_sm750_map() to properly release
the PCI region on ioremap failures, and add pci_release_region() to
lynxfb_pci_remove().

Signed-off-by: default avatarArtem Lytkin <iprintercanon@gmail.com>
Cc: stable <stable@kernel.org>
Link: https://patch.msgid.link/20260216202038.1828-1-iprintercanon@gmail.com


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 6de23f81
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1123,6 +1123,7 @@ static void lynxfb_pci_remove(struct pci_dev *pdev)

	iounmap(sm750_dev->pvReg);
	iounmap(sm750_dev->pvMem);
	pci_release_region(pdev, 1);
	kfree(g_settings);
}

+11 −11
Original line number Diff line number Diff line
@@ -36,16 +36,11 @@ int hw_sm750_map(struct sm750_dev *sm750_dev, struct pci_dev *pdev)

	pr_info("mmio phyAddr = %lx\n", sm750_dev->vidreg_start);

	/*
	 * reserve the vidreg space of smi adaptor
	 * if you do this, you need to add release region code
	 * in lynxfb_remove, or memory will not be mapped again
	 * successfully
	 */
	/* reserve the vidreg space of smi adaptor */
	ret = pci_request_region(pdev, 1, "sm750fb");
	if (ret) {
		pr_err("Can not request PCI regions.\n");
		goto exit;
		return ret;
	}

	/* now map mmio and vidmem */
@@ -54,7 +49,7 @@ int hw_sm750_map(struct sm750_dev *sm750_dev, struct pci_dev *pdev)
	if (!sm750_dev->pvReg) {
		pr_err("mmio failed\n");
		ret = -EFAULT;
		goto exit;
		goto err_release_region;
	}
	pr_info("mmio virtual addr = %p\n", sm750_dev->pvReg);

@@ -79,13 +74,18 @@ int hw_sm750_map(struct sm750_dev *sm750_dev, struct pci_dev *pdev)
	sm750_dev->pvMem =
		ioremap_wc(sm750_dev->vidmem_start, sm750_dev->vidmem_size);
	if (!sm750_dev->pvMem) {
		iounmap(sm750_dev->pvReg);
		pr_err("Map video memory failed\n");
		ret = -EFAULT;
		goto exit;
		goto err_unmap_reg;
	}
	pr_info("video memory vaddr = %p\n", sm750_dev->pvMem);
exit:

	return 0;

err_unmap_reg:
	iounmap(sm750_dev->pvReg);
err_release_region:
	pci_release_region(pdev, 1);
	return ret;
}