lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:	Mon, 11 Mar 2013 13:25:12 -0700
From:	Josh Triplett <josh@...htriplett.org>
To:	Alexandru Gheorghiu <gheorghiuandru@...il.com>
Cc:	Daniel Vetter <daniel.vetter@...ll.ch>,
	David Airlie <airlied@...ux.ie>,
	dri-devel@...ts.freedesktop.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] drivers: gpu: drm: i915: Replaced calls to kmalloc &
 memcpy with kmemdup

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@...il.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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ