Skip to contentSkip to conversation

drivers: gpu: drm: i915: Replaced calls to kmalloc & memcpy with kmemdup

PATCH In review Alexandru Gheorghiu 2 participants 2 messages Mar 11, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers: gpu: drm: i915: Replaced calls to kmalloc & memcpy with kmemdup

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

---
 drivers/gpu/drm/i915/intel_dp.c |    5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/gpu/drm/i915/intel_dp.c +1 -4
index f61cb79..3cf8aed 100644
@@ -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;
 	}
 
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 2 lines · Alexandru Gheorghiu

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

[]

drivers/gpu/drm/i915/intel_dp.c

Quoted 1 line
drivers/gpu/drm/i915/intel_dp.c +0 -0

[]

drivers/gpu/drm/i915/intel_dp.c intel_dp_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter) · line 2342

Quoted 13 lines
drivers/gpu/drm/i915/intel_dp.c +1 -4
@@ -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);
	}