* [PATCH v3] staging: mmal-vchiq: add a check for the return of vmalloc()
@ 2022-03-15 16:39 ` xkernel.wang
0 siblings, 0 replies; 4+ messages in thread
From: xkernel.wang @ 2022-03-15 16:39 UTC (permalink / raw)
To: gregkh, dan.carpenter, 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.
v2->v3 fix the mistake bring by version 2.
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..24cc0fe 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;
+ }
instance->vchiq_instance = vchiq_instance;
mutex_init(&instance->context_map_lock);
@@ -1940,6 +1944,7 @@ int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance)
destroy_workqueue(instance->bulk_wq);
err_free:
vfree(instance->bulk_scratch);
+err_free_instance:
kfree(instance);
err_shutdown_vchiq:
vchiq_shutdown(vchiq_instance);
--
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v3] staging: mmal-vchiq: add a check for the return of vmalloc()
@ 2022-03-15 16:39 ` xkernel.wang
0 siblings, 0 replies; 4+ messages in thread
From: xkernel.wang @ 2022-03-15 16:39 UTC (permalink / raw)
To: gregkh, dan.carpenter, 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.
v2->v3 fix the mistake bring by version 2.
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..24cc0fe 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;
+ }
instance->vchiq_instance = vchiq_instance;
mutex_init(&instance->context_map_lock);
@@ -1940,6 +1944,7 @@ int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance)
destroy_workqueue(instance->bulk_wq);
err_free:
vfree(instance->bulk_scratch);
+err_free_instance:
kfree(instance);
err_shutdown_vchiq:
vchiq_shutdown(vchiq_instance);
--
_______________________________________________
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] 4+ messages in thread
* Re: [PATCH v3] staging: mmal-vchiq: add a check for the return of vmalloc()
2022-03-15 16:39 ` xkernel.wang
@ 2022-03-15 17:05 ` Dan Carpenter
-1 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2022-03-15 17:05 UTC (permalink / raw)
To: xkernel.wang
Cc: gregkh, nsaenz, bcm-kernel-feedback-list, linux-rpi-kernel,
linux-arm-kernel, linux-staging, linux-kernel
On Wed, Mar 16, 2022 at 12:39:13AM +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.
> v2->v3 fix the mistake bring by version 2.
> 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..24cc0fe 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) {
Just delete ->bulk_scratch. It is not used anywhere.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] staging: mmal-vchiq: add a check for the return of vmalloc()
@ 2022-03-15 17:05 ` Dan Carpenter
0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2022-03-15 17:05 UTC (permalink / raw)
To: xkernel.wang
Cc: gregkh, nsaenz, bcm-kernel-feedback-list, linux-rpi-kernel,
linux-arm-kernel, linux-staging, linux-kernel
On Wed, Mar 16, 2022 at 12:39:13AM +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.
> v2->v3 fix the mistake bring by version 2.
> 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..24cc0fe 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) {
Just delete ->bulk_scratch. It is not 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] 4+ messages in thread
end of thread, other threads:[~2022-03-15 17:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-15 16:39 [PATCH v3] staging: mmal-vchiq: add a check for the return of vmalloc() xkernel.wang
2022-03-15 16:39 ` xkernel.wang
2022-03-15 17:05 ` Dan Carpenter
2022-03-15 17:05 ` Dan Carpenter
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.