* [PATCH 1/3] staging: bcm2835-camera: add check to avoid null pointer dereference
2017-03-09 18:13 [PATCH 0/3] staging: bcm2835-camera: fix coding style issues Aishwarya Pant
@ 2017-03-09 18:13 ` Aishwarya Pant
2017-03-09 18:39 ` Greg KH
2017-03-09 18:13 ` [PATCH 2/3] staging: bcm2835-camera: replace kmalloc with kzalloc Aishwarya Pant
2017-03-09 18:14 ` [PATCH 3/3] staging: bcm2835-camera: use kernel preferred style for handling errors Aishwarya Pant
2 siblings, 1 reply; 6+ messages in thread
From: Aishwarya Pant @ 2017-03-09 18:13 UTC (permalink / raw)
To: outreachy-kernel; +Cc: gregkh
This patch adds checks after memory allocation to avoid possible null
pointer dereferences.
Signed-off-by: Aishwarya Pant <aishpant@gmail.com>
---
drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
index 6126919..a258a72 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
+++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
@@ -263,6 +263,9 @@ get_msg_context(struct vchiq_mmal_instance *instance)
msg_context = kmalloc(sizeof(*msg_context), GFP_KERNEL);
memset(msg_context, 0, sizeof(*msg_context));
+ if (!msg_context)
+ return NULL;
+
msg_context->instance = instance;
msg_context->handle =
mmal_context_map_create_handle(&instance->context_map,
@@ -2008,6 +2011,9 @@ int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance)
instance = kmalloc(sizeof(*instance), GFP_KERNEL);
memset(instance, 0, sizeof(*instance));
+ if (!instance)
+ return -ENOMEM;
+
mutex_init(&instance->vchiq_mutex);
mutex_init(&instance->bulk_mutex);
--
2.7.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/3] staging: bcm2835-camera: add check to avoid null pointer dereference
2017-03-09 18:13 ` [PATCH 1/3] staging: bcm2835-camera: add check to avoid null pointer dereference Aishwarya Pant
@ 2017-03-09 18:39 ` Greg KH
0 siblings, 0 replies; 6+ messages in thread
From: Greg KH @ 2017-03-09 18:39 UTC (permalink / raw)
To: Aishwarya Pant; +Cc: outreachy-kernel
On Thu, Mar 09, 2017 at 11:43:28PM +0530, Aishwarya Pant wrote:
> This patch adds checks after memory allocation to avoid possible null
> pointer dereferences.
>
> Signed-off-by: Aishwarya Pant <aishpant@gmail.com>
> ---
> drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
> index 6126919..a258a72 100644
> --- a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
> +++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
> @@ -263,6 +263,9 @@ get_msg_context(struct vchiq_mmal_instance *instance)
> msg_context = kmalloc(sizeof(*msg_context), GFP_KERNEL);
> memset(msg_context, 0, sizeof(*msg_context));
>
> + if (!msg_context)
> + return NULL;
But you just crashed one line above!
not good :(
greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/3] staging: bcm2835-camera: replace kmalloc with kzalloc
2017-03-09 18:13 [PATCH 0/3] staging: bcm2835-camera: fix coding style issues Aishwarya Pant
2017-03-09 18:13 ` [PATCH 1/3] staging: bcm2835-camera: add check to avoid null pointer dereference Aishwarya Pant
@ 2017-03-09 18:13 ` Aishwarya Pant
2017-03-09 18:39 ` Greg KH
2017-03-09 18:14 ` [PATCH 3/3] staging: bcm2835-camera: use kernel preferred style for handling errors Aishwarya Pant
2 siblings, 1 reply; 6+ messages in thread
From: Aishwarya Pant @ 2017-03-09 18:13 UTC (permalink / raw)
To: outreachy-kernel; +Cc: gregkh
This patch replaces kmalloc and memset with kzalloc
Signed-off-by: Aishwarya Pant <aishpant@gmail.com>
---
drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
index a258a72..f795137 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
+++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
@@ -259,9 +259,8 @@ get_msg_context(struct vchiq_mmal_instance *instance)
{
struct mmal_msg_context *msg_context;
- /* todo: should this be allocated from a pool to avoid kmalloc */
- msg_context = kmalloc(sizeof(*msg_context), GFP_KERNEL);
- memset(msg_context, 0, sizeof(*msg_context));
+ /* todo: should this be allocated from a pool to avoid kzalloc */
+ msg_context = kzalloc(sizeof(*msg_context), GFP_KERNEL);
if (!msg_context)
return NULL;
@@ -2008,8 +2007,7 @@ int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance)
return -EIO;
}
- instance = kmalloc(sizeof(*instance), GFP_KERNEL);
- memset(instance, 0, sizeof(*instance));
+ instance = kzalloc(sizeof(*instance), GFP_KERNEL);
if (!instance)
return -ENOMEM;
--
2.7.4
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH 2/3] staging: bcm2835-camera: replace kmalloc with kzalloc
2017-03-09 18:13 ` [PATCH 2/3] staging: bcm2835-camera: replace kmalloc with kzalloc Aishwarya Pant
@ 2017-03-09 18:39 ` Greg KH
0 siblings, 0 replies; 6+ messages in thread
From: Greg KH @ 2017-03-09 18:39 UTC (permalink / raw)
To: Aishwarya Pant; +Cc: outreachy-kernel
On Thu, Mar 09, 2017 at 11:43:48PM +0530, Aishwarya Pant wrote:
> This patch replaces kmalloc and memset with kzalloc
>
> Signed-off-by: Aishwarya Pant <aishpant@gmail.com>
> ---
> drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c | 8 +++-----
> 1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
> index a258a72..f795137 100644
> --- a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
> +++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
> @@ -259,9 +259,8 @@ get_msg_context(struct vchiq_mmal_instance *instance)
> {
> struct mmal_msg_context *msg_context;
>
> - /* todo: should this be allocated from a pool to avoid kmalloc */
> - msg_context = kmalloc(sizeof(*msg_context), GFP_KERNEL);
> - memset(msg_context, 0, sizeof(*msg_context));
> + /* todo: should this be allocated from a pool to avoid kzalloc */
> + msg_context = kzalloc(sizeof(*msg_context), GFP_KERNEL);
>
> if (!msg_context)
> return NULL;
> @@ -2008,8 +2007,7 @@ int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance)
> return -EIO;
> }
>
> - instance = kmalloc(sizeof(*instance), GFP_KERNEL);
> - memset(instance, 0, sizeof(*instance));
> + instance = kzalloc(sizeof(*instance), GFP_KERNEL);
>
> if (!instance)
> return -ENOMEM;
Does not apply to my tree :(
Please rebase and resend.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/3] staging: bcm2835-camera: use kernel preferred style for handling errors
2017-03-09 18:13 [PATCH 0/3] staging: bcm2835-camera: fix coding style issues Aishwarya Pant
2017-03-09 18:13 ` [PATCH 1/3] staging: bcm2835-camera: add check to avoid null pointer dereference Aishwarya Pant
2017-03-09 18:13 ` [PATCH 2/3] staging: bcm2835-camera: replace kmalloc with kzalloc Aishwarya Pant
@ 2017-03-09 18:14 ` Aishwarya Pant
2 siblings, 0 replies; 6+ messages in thread
From: Aishwarya Pant @ 2017-03-09 18:14 UTC (permalink / raw)
To: outreachy-kernel; +Cc: gregkh
This patch replaces NULL error values with error pointer values.
Signed-off-by: Aishwarya Pant <aishpant@gmail.com>
---
drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
index f795137..d87e2df 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
+++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
@@ -263,7 +263,7 @@ get_msg_context(struct vchiq_mmal_instance *instance)
msg_context = kzalloc(sizeof(*msg_context), GFP_KERNEL);
if (!msg_context)
- return NULL;
+ return ERR_PTR(-ENOMEM);
msg_context->instance = instance;
msg_context->handle =
@@ -273,7 +273,7 @@ get_msg_context(struct vchiq_mmal_instance *instance)
if (!msg_context->handle) {
kfree(msg_context);
- return NULL;
+ return ERR_PTR(-ENOMEM);
}
return msg_context;
@@ -508,8 +508,8 @@ buffer_from_host(struct vchiq_mmal_instance *instance,
/* get context */
msg_context = get_msg_context(instance);
- if (!msg_context) {
- ret = -ENOMEM;
+ if (IS_ERR(msg_context)) {
+ ret = PTR_ERR(msg_context);
goto unlock;
}
@@ -836,8 +836,8 @@ static int send_synchronous_mmal_msg(struct vchiq_mmal_instance *instance,
}
msg_context = get_msg_context(instance);
- if (!msg_context)
- return -ENOMEM;
+ if (IS_ERR(msg_context))
+ return PTR_ERR(msg_context);
init_completion(&msg_context->u.sync.cmplt);
--
2.7.4
^ permalink raw reply related [flat|nested] 6+ messages in thread