Skip to contentSkip to conversation

drm/amd/display: use kvmalloc for dc_state (v2)

PATCH In review Alex Deucher 2 participants 2 messages Aug 9, 2019 1 message not in the archive

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

PATCH 1/1 drm/amd/display: use kvmalloc for dc_state (v2)

It's large and doesn't need contiguous memory. Fixes allocation failures in some cases.

v2: kvfree the memory.

---
 drivers/gpu/drm/amd/display/dc/core/dc.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/display/dc/core/dc.c +6 -5
index 252b621d93a9..21fb7ee17c9c 100644
@@ -23,6 +23,7 @@
  */
 
 #include <linux/slab.h>
+#include <linux/mm.h>
 
 #include "dm_services.h"
 
@@ -1183,8 +1184,8 @@ bool dc_post_update_surfaces_to_stream(struct dc *dc)
 
 struct dc_state *dc_create_state(struct dc *dc)
 {
-	struct dc_state *context = kzalloc(sizeof(struct dc_state),
-					   GFP_KERNEL);
+	struct dc_state *context = kvzalloc(sizeof(struct dc_state),
+					    GFP_KERNEL);
 
 	if (!context)
 		return NULL;
@@ -1204,11 +1205,11 @@ struct dc_state *dc_create_state(struct dc *dc)
 struct dc_state *dc_copy_state(struct dc_state *src_ctx)
 {
 	int i, j;
-	struct dc_state *new_ctx = kmemdup(src_ctx,
-			sizeof(struct dc_state), GFP_KERNEL);
+	struct dc_state *new_ctx = kvmalloc(sizeof(struct dc_state), GFP_KERNEL);
 
 	if (!new_ctx)
 		return NULL;
+	memcpy(new_ctx, src_ctx, sizeof(struct dc_state));
 
 	for (i = 0; i < MAX_PIPES; i++) {
 			struct pipe_ctx *cur_pipe = &new_ctx->res_ctx.pipe_ctx[i];
@@ -1242,7 +1243,7 @@ static void dc_state_free(struct kref *kref)
 {
 	struct dc_state *context = container_of(kref, struct dc_state, refcount);
 	dc_resource_state_destruct(context);
-	kfree(context);
+	kvfree(context);
 }
 
 void dc_release_state(struct dc_state *context)
Signature · 6 lines
2.20.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 20190809185952.3656-1-alexander.deucher-5C7GfCeVMHo@public.gmane.org

Reviewed-by Andrey Grodzovsky
#2 lore raw

Andrey

Quoted 48 lines · Alex Deucher

It's large and doesn't need contiguous memory. Fixes allocation failures in some cases.

v2: kvfree the memory.

---
  drivers/gpu/drm/amd/display/dc/core/dc.c | 11 ++++++-----
  1 file changed, 6 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/display/dc/core/dc.c +5 -4
index 252b621d93a9..21fb7ee17c9c 100644
@@ -23,6 +23,7 @@
   */
 
  #include <linux/slab.h>
+#include <linux/mm.h>
 
  #include "dm_services.h"
 
@@ -1183,8 +1184,8 @@ bool dc_post_update_surfaces_to_stream(struct dc *dc)
 
  struct dc_state *dc_create_state(struct dc *dc)
  {
-	struct dc_state *context = kzalloc(sizeof(struct dc_state),
-					   GFP_KERNEL);
+	struct dc_state *context = kvzalloc(sizeof(struct dc_state),
+					    GFP_KERNEL);
 
  	if (!context)
  		return NULL;
@@ -1204,11 +1205,11 @@ struct dc_state *dc_create_state(struct dc *dc)
  struct dc_state *dc_copy_state(struct dc_state *src_ctx)
  {
  	int i, j;
-	struct dc_state *new_ctx = kmemdup(src_ctx,
-			sizeof(struct dc_state), GFP_KERNEL);
+	struct dc_state *new_ctx = kvmalloc(sizeof(struct dc_state), GFP_KERNEL);
 
  	if (!new_ctx)
  		return NULL;
+	memcpy(new_ctx, src_ctx, sizeof(struct dc_state));
 
  	for (i = 0; i < MAX_PIPES; i++) {
  			struct pipe_ctx *cur_pipe = &new_ctx->res_ctx.pipe_ctx[i];

drivers/gpu/drm/amd/display/dc/core/dc.c static void dc_state_free(struct kref *kref) · line 1249

Quoted 8 lines
drivers/gpu/drm/amd/display/dc/core/dc.c +1 -1
@@ -1242,7 +1243,7 @@ static void dc_state_free(struct kref *kref)
  {
  	struct dc_state *context = container_of(kref, struct dc_state, refcount);
  	dc_resource_state_destruct(context);
-	kfree(context);
+	kvfree(context);
  }
 
  void dc_release_state(struct dc_state *context)

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx