All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drivers: gpu: drm: i915: Replaced calls to kmalloc & memcpy with kmemdup
@ 2013-03-11 20:39 Alexandru Gheorghiu
  2013-03-11 21:19 ` Joe Perches
  0 siblings, 1 reply; 5+ messages in thread
From: Alexandru Gheorghiu @ 2013-03-11 20:39 UTC (permalink / raw)
  To: Daniel Vetter; +Cc: David Airlie, dri-devel, linux-kernel, Alexandru Gheorghiu

Replaced calls to kmalloc followed by memcpy with a single call to kmemdup.
Also removed a now redundant if statement.

Signed-off-by: Alexandru Gheorghiu <gheorghiuandru@gmail.com>
---
 drivers/gpu/drm/i915/intel_dp.c |    5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index f61cb79..3cf8aed 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -2335,11 +2335,8 @@ intel_dp_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter)
 			return NULL;
 
 		size = (intel_connector->edid->extensions + 1) * EDID_LENGTH;
-		edid = kmalloc(size, GFP_KERNEL);
-		if (!edid)
-			return NULL;
+		edid = kmemdup(intel_connector->edid, size, GFP_KERNEL);
 
-		memcpy(edid, intel_connector->edid, size);
 		return edid;
 	}
 
-- 
1.7.9.5


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

* Re: [PATCH] drivers: gpu: drm: i915: Replaced calls to kmalloc & memcpy with kmemdup
  2013-03-11 20:39 [PATCH] drivers: gpu: drm: i915: Replaced calls to kmalloc & memcpy with kmemdup Alexandru Gheorghiu
@ 2013-03-11 21:19 ` Joe Perches
  0 siblings, 0 replies; 5+ messages in thread
From: Joe Perches @ 2013-03-11 21:19 UTC (permalink / raw)
  To: Alexandru Gheorghiu; +Cc: Daniel Vetter, David Airlie, dri-devel, linux-kernel

On Mon, 2013-03-11 at 22:39 +0200, Alexandru Gheorghiu wrote:
> Replaced calls to kmalloc followed by memcpy with a single call to kmemdup.
> Also removed a now redundant if statement.
[]
> diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
[]
> @@ -2335,11 +2335,8 @@ intel_dp_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter)
>  			return NULL;
>  
>  		size = (intel_connector->edid->extensions + 1) * EDID_LENGTH;
> -		edid = kmalloc(size, GFP_KERNEL);
> -		if (!edid)
> -			return NULL;
> +		edid = kmemdup(intel_connector->edid, size, GFP_KERNEL);
>  
> -		memcpy(edid, intel_connector->edid, size);
>  		return edid;
>  	}
>  

Might as well get rid of the stack variable edid altogether.
Maybe get rid of size too and use:

	if (intel_connector->edid) {
		/* invalid edid */
		if (IS_ERR(intel_connector->edid))
			return NULL;

		return kmemdup(intel_connector->edid,
			       (intel_connector->edid->extensions + 1) * EDID_LENGTH,
			       GFP_KERNEL);
	}



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

* Re: [PATCH] drivers: gpu: drm: i915: Replaced calls to kmalloc & memcpy with kmemdup
  2013-03-11 20:25 ` Josh Triplett
@ 2013-03-11 20:31   ` Andru Gheorghiu
  0 siblings, 0 replies; 5+ messages in thread
From: Andru Gheorghiu @ 2013-03-11 20:31 UTC (permalink / raw)
  To: Josh Triplett; +Cc: Daniel Vetter, linux-kernel, dri-devel


[-- Attachment #1.1: Type: text/plain, Size: 1672 bytes --]

You are right. I shall resend :)

Thanks!

On Mon, Mar 11, 2013 at 10:25 PM, Josh Triplett <josh@joshtriplett.org>wrote:

> On Mon, Mar 11, 2013 at 09:30:40PM +0200, Alexandru Gheorghiu wrote:
> > Replaced calls to kmalloc followed by memcpy with a single call to
> kmemdup.
> > This patch was found using coccinelle.
> >
> > Signed-off-by: Alexandru Gheorghiu <gheorghiuandru@gmail.com>
> > ---
> >  drivers/gpu/drm/i915/intel_dp.c |    3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/i915/intel_dp.c
> b/drivers/gpu/drm/i915/intel_dp.c
> > index f61cb79..a3fdd65 100644
> > --- a/drivers/gpu/drm/i915/intel_dp.c
> > +++ b/drivers/gpu/drm/i915/intel_dp.c
> > @@ -2335,11 +2335,10 @@ intel_dp_get_edid(struct drm_connector
> *connector, struct i2c_adapter *adapter)
> >                       return NULL;
> >
> >               size = (intel_connector->edid->extensions + 1) *
> EDID_LENGTH;
> > -             edid = kmalloc(size, GFP_KERNEL);
> > +             edid = kmemdup(intel_connector->edid, size, GFP_KERNEL);
> >               if (!edid)
> >                       return NULL;
> >
> > -             memcpy(edid, intel_connector->edid, size);
> >               return edid;
> >       }
>
> With this change, the conditional no longer makes sense; this should
> just "return kmemdup(...);".
>
> That suggests an obvious further cleanup that coccinelle could easily
> handle:
>
> if (!foo)
>     return NULL;
> return foo;
>
> should become just "return foo;".  And you might then want to check for
> variables used *only* to capture a return value and immediately
> returned, and eliminate them.
>
> - Josh Triplett
>

[-- Attachment #1.2: Type: text/html, Size: 2326 bytes --]

[-- Attachment #2: Type: text/plain, Size: 159 bytes --]

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCH] drivers: gpu: drm: i915: Replaced calls to kmalloc & memcpy with kmemdup
  2013-03-11 19:30 Alexandru Gheorghiu
@ 2013-03-11 20:25 ` Josh Triplett
  2013-03-11 20:31   ` Andru Gheorghiu
  0 siblings, 1 reply; 5+ messages in thread
From: Josh Triplett @ 2013-03-11 20:25 UTC (permalink / raw)
  To: Alexandru Gheorghiu; +Cc: Daniel Vetter, David Airlie, dri-devel, linux-kernel

On Mon, Mar 11, 2013 at 09:30:40PM +0200, Alexandru Gheorghiu wrote:
> Replaced calls to kmalloc followed by memcpy with a single call to kmemdup.
> This patch was found using coccinelle.
> 
> Signed-off-by: Alexandru Gheorghiu <gheorghiuandru@gmail.com>
> ---
>  drivers/gpu/drm/i915/intel_dp.c |    3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
> index f61cb79..a3fdd65 100644
> --- a/drivers/gpu/drm/i915/intel_dp.c
> +++ b/drivers/gpu/drm/i915/intel_dp.c
> @@ -2335,11 +2335,10 @@ intel_dp_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter)
>  			return NULL;
>  
>  		size = (intel_connector->edid->extensions + 1) * EDID_LENGTH;
> -		edid = kmalloc(size, GFP_KERNEL);
> +		edid = kmemdup(intel_connector->edid, size, GFP_KERNEL);
>  		if (!edid)
>  			return NULL;
>  
> -		memcpy(edid, intel_connector->edid, size);
>  		return edid;
>  	}

With this change, the conditional no longer makes sense; this should
just "return kmemdup(...);".

That suggests an obvious further cleanup that coccinelle could easily
handle:

if (!foo)
    return NULL;
return foo;

should become just "return foo;".  And you might then want to check for
variables used *only* to capture a return value and immediately
returned, and eliminate them.

- Josh Triplett

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

* [PATCH] drivers: gpu: drm: i915: Replaced calls to kmalloc & memcpy with kmemdup
@ 2013-03-11 19:30 Alexandru Gheorghiu
  2013-03-11 20:25 ` Josh Triplett
  0 siblings, 1 reply; 5+ messages in thread
From: Alexandru Gheorghiu @ 2013-03-11 19:30 UTC (permalink / raw)
  To: Daniel Vetter; +Cc: David Airlie, dri-devel, linux-kernel, Alexandru Gheorghiu

Replaced calls to kmalloc followed by memcpy with a single call to kmemdup.
This patch was found using coccinelle.

Signed-off-by: Alexandru Gheorghiu <gheorghiuandru@gmail.com>
---
 drivers/gpu/drm/i915/intel_dp.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index f61cb79..a3fdd65 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -2335,11 +2335,10 @@ intel_dp_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter)
 			return NULL;
 
 		size = (intel_connector->edid->extensions + 1) * EDID_LENGTH;
-		edid = kmalloc(size, GFP_KERNEL);
+		edid = kmemdup(intel_connector->edid, size, GFP_KERNEL);
 		if (!edid)
 			return NULL;
 
-		memcpy(edid, intel_connector->edid, size);
 		return edid;
 	}
 
-- 
1.7.9.5


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

end of thread, other threads:[~2013-03-11 21:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-11 20:39 [PATCH] drivers: gpu: drm: i915: Replaced calls to kmalloc & memcpy with kmemdup Alexandru Gheorghiu
2013-03-11 21:19 ` Joe Perches
  -- strict thread matches above, loose matches on Subject: below --
2013-03-11 19:30 Alexandru Gheorghiu
2013-03-11 20:25 ` Josh Triplett
2013-03-11 20:31   ` Andru Gheorghiu

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.