Linux kernel staging patches
 help / color / mirror / Atom feed
* [PATCH] staging: media: ipu7: add NULL checks before ipu7_mmu_cleanup() in remove
@ 2026-07-13 17:21 Alfie Varghese
  2026-07-14  7:12 ` Dan Carpenter
  0 siblings, 1 reply; 2+ messages in thread
From: Alfie Varghese @ 2026-07-13 17:21 UTC (permalink / raw)
  To: sakari.ailus, gregkh
  Cc: bingbu.cao, linux-media, linux-staging, linux-kernel,
	Alfie Varghese

ipu7_pci_remove() calls ipu7_mmu_cleanup() on isp->isys->mmu and
isp->psys->mmu without checking whether isys or psys are valid
pointers. If ipu7_pci_probe() partially failed and left isys or psys
as NULL or an error pointer, the remove path will dereference a bad
pointer and crash the kernel.

The probe error cleanup path already guards these calls correctly with
IS_ERR_OR_NULL() checks. Apply the same guards in ipu7_pci_remove().

Signed-off-by: Alfie Varghese <alfievarghese22@gmail.com>
---
 drivers/staging/media/ipu7/ipu7.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/media/ipu7/ipu7.c b/drivers/staging/media/ipu7/ipu7.c
index 310e3f24e571..41436f22c684 100644
--- a/drivers/staging/media/ipu7/ipu7.c
+++ b/drivers/staging/media/ipu7/ipu7.c
@@ -2637,8 +2637,10 @@ static void ipu7_pci_remove(struct pci_dev *pdev)
 	if (!IS_ERR_OR_NULL(isp->fw_code_region))
 		vfree(isp->fw_code_region);
 
-	ipu7_mmu_cleanup(isp->isys->mmu);
-	ipu7_mmu_cleanup(isp->psys->mmu);
+	if (!IS_ERR_OR_NULL(isp->isys) && !IS_ERR_OR_NULL(isp->isys->mmu))
+		ipu7_mmu_cleanup(isp->isys->mmu);
+	if (!IS_ERR_OR_NULL(isp->psys) && !IS_ERR_OR_NULL(isp->psys->mmu))
+		ipu7_mmu_cleanup(isp->psys->mmu);
 
 	ipu7_bus_del_devices(pdev);
 


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] staging: media: ipu7: add NULL checks before ipu7_mmu_cleanup() in remove
  2026-07-13 17:21 [PATCH] staging: media: ipu7: add NULL checks before ipu7_mmu_cleanup() in remove Alfie Varghese
@ 2026-07-14  7:12 ` Dan Carpenter
  0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2026-07-14  7:12 UTC (permalink / raw)
  To: Alfie Varghese
  Cc: sakari.ailus, gregkh, bingbu.cao, linux-media, linux-staging,
	linux-kernel

On Mon, Jul 13, 2026 at 10:51:27PM +0530, Alfie Varghese wrote:
> ipu7_pci_remove() calls ipu7_mmu_cleanup() on isp->isys->mmu and
> isp->psys->mmu without checking whether isys or psys are valid
> pointers. If ipu7_pci_probe() partially failed and left isys or psys
> as NULL or an error pointer, the remove path will dereference a bad
> pointer and crash the kernel.
> 
> The probe error cleanup path already guards these calls correctly with
> IS_ERR_OR_NULL() checks. Apply the same guards in ipu7_pci_remove().
> 
> Signed-off-by: Alfie Varghese <alfievarghese22@gmail.com>
> ---
>  drivers/staging/media/ipu7/ipu7.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/media/ipu7/ipu7.c b/drivers/staging/media/ipu7/ipu7.c
> index 310e3f24e571..41436f22c684 100644
> --- a/drivers/staging/media/ipu7/ipu7.c
> +++ b/drivers/staging/media/ipu7/ipu7.c
> @@ -2637,8 +2637,10 @@ static void ipu7_pci_remove(struct pci_dev *pdev)
>  	if (!IS_ERR_OR_NULL(isp->fw_code_region))
>  		vfree(isp->fw_code_region);
>  
> -	ipu7_mmu_cleanup(isp->isys->mmu);
> -	ipu7_mmu_cleanup(isp->psys->mmu);
> +	if (!IS_ERR_OR_NULL(isp->isys) && !IS_ERR_OR_NULL(isp->isys->mmu))
> +		ipu7_mmu_cleanup(isp->isys->mmu);
> +	if (!IS_ERR_OR_NULL(isp->psys) && !IS_ERR_OR_NULL(isp->psys->mmu))
> +		ipu7_mmu_cleanup(isp->psys->mmu);

The original code here is fine.  It is the probe() function which is
is wrong.  See my blog on how to fix the probe() function.

https://staticthinking.wordpress.com/2022/04/28/free-the-last-thing-style/

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-14  7:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-13 17:21 [PATCH] staging: media: ipu7: add NULL checks before ipu7_mmu_cleanup() in remove Alfie Varghese
2026-07-14  7:12 ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox