All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] staging: bcm2835-camera: replace kmalloc with kzalloc
@ 2017-03-06  7:21 Aishwarya Pant
  2017-03-06 12:53 ` [Outreachy kernel] " Greg Kroah-Hartman
  0 siblings, 1 reply; 2+ messages in thread
From: Aishwarya Pant @ 2017-03-06  7:21 UTC (permalink / raw)
  To: Stephen Warren, Lee Jones, Eric Anholt, Greg Kroah-Hartman,
	Florian Fainelli, Ray Jui, Scott Branden,
	bcm-kernel-feedback-list
  Cc: outreachy-kernel

This patch replaces two instances of kmalloc and memset with kzalloc
and refactors function get_msg_context(..)

Signed-off-by: Aishwarya Pant <aishpant@gmail.com>

---
Changes in v2:
	- Return out of memory error number when kzalloc fails
	- Refactor get_msg_context

 drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
index 0f96ac8..87d7681 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
+++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
@@ -166,13 +166,9 @@ struct vchiq_mmal_instance {
 static struct mmal_msg_context *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 */
+	return kzalloc(sizeof(*msg_context), GFP_KERNEL);
 
-	return msg_context;
 }
 
 static void release_msg_context(struct mmal_msg_context *msg_context)
@@ -1881,8 +1877,9 @@ 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;
 
 	mutex_init(&instance->vchiq_mutex);
 	mutex_init(&instance->bulk_mutex);
-- 
2.7.4



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

* Re: [Outreachy kernel] [PATCH v2] staging: bcm2835-camera: replace kmalloc with kzalloc
  2017-03-06  7:21 [PATCH v2] staging: bcm2835-camera: replace kmalloc with kzalloc Aishwarya Pant
@ 2017-03-06 12:53 ` Greg Kroah-Hartman
  0 siblings, 0 replies; 2+ messages in thread
From: Greg Kroah-Hartman @ 2017-03-06 12:53 UTC (permalink / raw)
  To: Aishwarya Pant
  Cc: Stephen Warren, Lee Jones, Eric Anholt, Florian Fainelli, Ray Jui,
	Scott Branden, bcm-kernel-feedback-list, outreachy-kernel

On Mon, Mar 06, 2017 at 12:51:36PM +0530, Aishwarya Pant wrote:
> This patch replaces two instances of kmalloc and memset with kzalloc
> and refactors function get_msg_context(..)

What did you refactor?  Why do two things at once?

> 
> Signed-off-by: Aishwarya Pant <aishpant@gmail.com>
> 
> ---
> Changes in v2:
> 	- Return out of memory error number when kzalloc fails
> 	- Refactor get_msg_context
> 
>  drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c | 13 +++++--------
>  1 file changed, 5 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
> index 0f96ac8..87d7681 100644
> --- a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
> +++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
> @@ -166,13 +166,9 @@ struct vchiq_mmal_instance {
>  static struct mmal_msg_context *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 */
> +	return kzalloc(sizeof(*msg_context), GFP_KERNEL);

Why is this function even needed anymore?  Why not just call kzalloc()
instead of this one?

thanks,

greg k-h


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

end of thread, other threads:[~2017-03-06 12:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-06  7:21 [PATCH v2] staging: bcm2835-camera: replace kmalloc with kzalloc Aishwarya Pant
2017-03-06 12:53 ` [Outreachy kernel] " Greg Kroah-Hartman

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.