diff mbox series

[1/1] media: ipu6: Fix vmalloc memory allocation

Message ID 20240502061525.1004018-1-sakari.ailus@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series [1/1] media: ipu6: Fix vmalloc memory allocation | expand

Commit Message

Sakari Ailus May 2, 2024, 6:15 a.m. UTC
The driver was calling vmalloc() to allocate memory, something which isn't
available except when particular Kconfig settings are enabled.

Use kvmalloc() instead.

Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Fixes: 25fedc021985 ("media: intel/ipu6: add Intel IPU6 PCI device driver")
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
Hi Stephen,

Thanks for reporting this. I'm a bit surprised this wasn't catched
earlier. But it seems vmalloc() is defined in some configuration.

- Sakari

 drivers/media/pci/intel/ipu6/ipu6.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Mauro Carvalho Chehab May 2, 2024, 10:03 a.m. UTC | #1
Em Thu,  2 May 2024 09:15:25 +0300
Sakari Ailus <sakari.ailus@linux.intel.com> escreveu:

> The driver was calling vmalloc() to allocate memory, something which isn't
> available except when particular Kconfig settings are enabled.
> 
> Use kvmalloc() instead.
> 
> Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
> Fixes: 25fedc021985 ("media: intel/ipu6: add Intel IPU6 PCI device driver")
> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> ---
> Hi Stephen,
> 
> Thanks for reporting this. I'm a bit surprised this wasn't catched
> earlier. But it seems vmalloc() is defined in some configuration.
> 
> - Sakari
> 
>  drivers/media/pci/intel/ipu6/ipu6.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/media/pci/intel/ipu6/ipu6.c b/drivers/media/pci/intel/ipu6/ipu6.c
> index 4b1f69d14d71..082b1d6196be 100644
> --- a/drivers/media/pci/intel/ipu6/ipu6.c
> +++ b/drivers/media/pci/intel/ipu6/ipu6.c
> @@ -526,7 +526,7 @@ static int request_cpd_fw(const struct firmware **firmware_p, const char *name,
>  	}
>  
>  	dst->size = fw->size;
> -	dst->data = vmalloc(fw->size);
> +	dst->data = kvmalloc(fw->size, GFP_KERNEL);

Where are you freeing it? If I understood the code right, you're storing
dst at isp->cpd_fw, but I can't see any code freeing it nor cpw_fw->data
at device removal.

Also, there is a logic there at the same function checking for vmalloc:

	if (is_vmalloc_addr(fw->data)) {
		*firmware_p = fw;
		return 0;
	}

As now the memory may not be inside vmalloc space, shouldn't this
be changed as well?

Regards,
Mauro

>  	if (!dst->data) {
>  		kfree(dst);
>  		ret = -ENOMEM;
diff mbox series

Patch

diff --git a/drivers/media/pci/intel/ipu6/ipu6.c b/drivers/media/pci/intel/ipu6/ipu6.c
index 4b1f69d14d71..082b1d6196be 100644
--- a/drivers/media/pci/intel/ipu6/ipu6.c
+++ b/drivers/media/pci/intel/ipu6/ipu6.c
@@ -526,7 +526,7 @@  static int request_cpd_fw(const struct firmware **firmware_p, const char *name,
 	}
 
 	dst->size = fw->size;
-	dst->data = vmalloc(fw->size);
+	dst->data = kvmalloc(fw->size, GFP_KERNEL);
 	if (!dst->data) {
 		kfree(dst);
 		ret = -ENOMEM;