Re: [PATCH] staging: mmal-vchiq: add a check for the return of vmalloc()

From: Greg KH
Date: Tue Mar 15 2022 - 10:22:14 EST


On Fri, Mar 04, 2022 at 04:17:41PM +0800, xkernel.wang@xxxxxxxxxxx wrote:
> From: Xiaoke Wang <xkernel.wang@xxxxxxxxxxx>
>
> vmalloc() is a memory allocation API which can return NULL when some
> internal memory errors happen. So it is better to check the return
> value of it to catch the error in time.
>
> Signed-off-by: Xiaoke Wang <xkernel.wang@xxxxxxxxxxx>
> ---
> drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
> index 76d3f03..1bbd301 100644
> --- a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
> +++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
> @@ -1909,6 +1909,11 @@ int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance)
> mutex_init(&instance->vchiq_mutex);
>
> instance->bulk_scratch = vmalloc(PAGE_SIZE);
> + if (!instance->bulk_scratch) {
> + err = -ENOMEM;
> + kfree(instance);

This is called in the error section, please just jump to the proper
location and then this line will not be needed.

thanks,

greg k-h