linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] staging: mmal-vchiq: add a check for the return of vmalloc()
@ 2022-03-15 14:42 xkernel.wang
  2022-03-15 15:27 ` Greg KH
  0 siblings, 1 reply; 5+ messages in thread
From: xkernel.wang @ 2022-03-15 14:42 UTC (permalink / raw)
  To: gregkh, nsaenz
  Cc: bcm-kernel-feedback-list, linux-rpi-kernel, linux-arm-kernel,
	linux-staging, linux-kernel, Xiaoke Wang

From: Xiaoke Wang <xkernel.wang@foxmail.com>

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@foxmail.com>
---
ChangeLog:
v1->v2  jump to the proper location and remove redundant instruction.
 drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c | 4 ++++
 1 file changed, 4 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..ff4b484 100644
--- a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
+++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
@@ -1909,6 +1909,10 @@ 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;
+		goto err_free;
+	}
 	instance->vchiq_instance = vchiq_instance;
 
 	mutex_init(&instance->context_map_lock);
-- 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2] staging: mmal-vchiq: add a check for the return of vmalloc()
  2022-03-15 14:42 [PATCH v2] staging: mmal-vchiq: add a check for the return of vmalloc() xkernel.wang
@ 2022-03-15 15:27 ` Greg KH
  2022-03-15 15:53   ` Dan Carpenter
  2022-03-15 16:23   ` Xiaoke Wang
  0 siblings, 2 replies; 5+ messages in thread
From: Greg KH @ 2022-03-15 15:27 UTC (permalink / raw)
  To: xkernel.wang
  Cc: nsaenz, bcm-kernel-feedback-list, linux-rpi-kernel,
	linux-arm-kernel, linux-staging, linux-kernel

On Tue, Mar 15, 2022 at 10:42:07PM +0800, xkernel.wang@foxmail.com wrote:
> From: Xiaoke Wang <xkernel.wang@foxmail.com>
> 
> 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@foxmail.com>
> ---
> ChangeLog:
> v1->v2  jump to the proper location and remove redundant instruction.
>  drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c | 4 ++++
>  1 file changed, 4 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..ff4b484 100644
> --- a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
> +++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
> @@ -1909,6 +1909,10 @@ 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;
> +		goto err_free;
> +	}
>  	instance->vchiq_instance = vchiq_instance;
>  
>  	mutex_init(&instance->context_map_lock);
> -- 

Your change just crashed the kernel :(

Please be more careful.

greg k-h

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2] staging: mmal-vchiq: add a check for the return of vmalloc()
  2022-03-15 15:27 ` Greg KH
@ 2022-03-15 15:53   ` Dan Carpenter
  2022-03-15 16:23   ` Xiaoke Wang
  1 sibling, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2022-03-15 15:53 UTC (permalink / raw)
  To: Greg KH
  Cc: xkernel.wang, nsaenz, bcm-kernel-feedback-list, linux-rpi-kernel,
	linux-arm-kernel, linux-staging, linux-kernel

On Tue, Mar 15, 2022 at 04:27:38PM +0100, Greg KH wrote:
> On Tue, Mar 15, 2022 at 10:42:07PM +0800, xkernel.wang@foxmail.com wrote:
> > From: Xiaoke Wang <xkernel.wang@foxmail.com>
> > 
> > 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@foxmail.com>
> > ---
> > ChangeLog:
> > v1->v2  jump to the proper location and remove redundant instruction.
> >  drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c | 4 ++++
> >  1 file changed, 4 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..ff4b484 100644
> > --- a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
> > +++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
> > @@ -1909,6 +1909,10 @@ 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) {

Is ->bulk_scratch even used anywhere?

regards,
dan carpenter


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2] staging: mmal-vchiq: add a check for the return of vmalloc()
  2022-03-15 15:27 ` Greg KH
  2022-03-15 15:53   ` Dan Carpenter
@ 2022-03-15 16:23   ` Xiaoke Wang
  2022-03-16 14:08     ` gregkh
  1 sibling, 1 reply; 5+ messages in thread
From: Xiaoke Wang @ 2022-03-15 16:23 UTC (permalink / raw)
  To: gregkh, dan.carpenter
  Cc: nsaenz, bcm-kernel-feedback-list, linux-rpi-kernel,
	linux-arm-kernel, linux-staging, linux-kernel

On Tue, 15 Mar 2022 16:27:38 +0100, Greg KH wrote:
&gt; Your change just crashed the kernel :(
&gt;
&gt; Please be more careful

I am sorry. I ever been told that vfree(NULL) or kfree(NULL) is safe,
so I just jump to the tag `err_free` in this version.
I will resend one by adding a new proper tag.
And in fact, I did not find where -&gt;bulk_scratch is used.

Regards,
Xiaoke Wang
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2] staging: mmal-vchiq: add a check for the return of vmalloc()
  2022-03-15 16:23   ` Xiaoke Wang
@ 2022-03-16 14:08     ` gregkh
  0 siblings, 0 replies; 5+ messages in thread
From: gregkh @ 2022-03-16 14:08 UTC (permalink / raw)
  To: Xiaoke Wang
  Cc: dan.carpenter, nsaenz, bcm-kernel-feedback-list,
	linux-rpi-kernel, linux-arm-kernel, linux-staging, linux-kernel

On Wed, Mar 16, 2022 at 12:23:05AM +0800, Xiaoke Wang wrote:
> On Tue, 15 Mar 2022 16:27:38 +0100, Greg KH wrote:
> &gt; Your change just crashed the kernel :(
> &gt;
> &gt; Please be more careful
> 
> I am sorry. I ever been told that vfree(NULL) or kfree(NULL) is safe,

Sorry, you are right, I was thinking that there would be an error value
there.  My mistake.

greg k-h

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2022-03-16 14:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-15 14:42 [PATCH v2] staging: mmal-vchiq: add a check for the return of vmalloc() xkernel.wang
2022-03-15 15:27 ` Greg KH
2022-03-15 15:53   ` Dan Carpenter
2022-03-15 16:23   ` Xiaoke Wang
2022-03-16 14:08     ` gregkh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).