msm: kgsl: Don't allocate memory dynamically for drawobj sync structs

The memory allocated dynamically here is just used to store a single
instance of a struct. Allocate both possible structs on the stack
instead of allocating them dynamically to improve performance.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
Signed-off-by: Ruchit <ruchitmarathe@gmail.com>
fourteen
Sultan Alsawaf 4 years ago committed by Jenna
parent 5e51cea6b2
commit 1e86c65339
  1. 21
      drivers/gpu/msm/kgsl_drawobj.c

@ -483,8 +483,12 @@ int kgsl_drawobj_sync_add_sync(struct kgsl_device *device,
struct kgsl_drawobj_sync *syncobj, struct kgsl_drawobj_sync *syncobj,
struct kgsl_cmd_syncpoint *sync) struct kgsl_cmd_syncpoint *sync)
{ {
union {
struct kgsl_cmd_syncpoint_timestamp sync_timestamp;
struct kgsl_cmd_syncpoint_fence sync_fence;
} data;
void *priv; void *priv;
int ret, psize; int psize;
struct kgsl_drawobj *drawobj = DRAWOBJ(syncobj); struct kgsl_drawobj *drawobj = DRAWOBJ(syncobj);
int (*func)(struct kgsl_device *device, int (*func)(struct kgsl_device *device,
struct kgsl_drawobj_sync *syncobj, struct kgsl_drawobj_sync *syncobj,
@ -494,10 +498,12 @@ int kgsl_drawobj_sync_add_sync(struct kgsl_device *device,
case KGSL_CMD_SYNCPOINT_TYPE_TIMESTAMP: case KGSL_CMD_SYNCPOINT_TYPE_TIMESTAMP:
psize = sizeof(struct kgsl_cmd_syncpoint_timestamp); psize = sizeof(struct kgsl_cmd_syncpoint_timestamp);
func = drawobj_add_sync_timestamp; func = drawobj_add_sync_timestamp;
priv = &data.sync_timestamp;
break; break;
case KGSL_CMD_SYNCPOINT_TYPE_FENCE: case KGSL_CMD_SYNCPOINT_TYPE_FENCE:
psize = sizeof(struct kgsl_cmd_syncpoint_fence); psize = sizeof(struct kgsl_cmd_syncpoint_fence);
func = drawobj_add_sync_fence; func = drawobj_add_sync_fence;
priv = &data.sync_fence;
break; break;
default: default:
KGSL_DRV_ERR(device, KGSL_DRV_ERR(device,
@ -513,19 +519,10 @@ int kgsl_drawobj_sync_add_sync(struct kgsl_device *device,
return -EINVAL; return -EINVAL;
} }
priv = kzalloc(sync->size, GFP_KERNEL); if (copy_from_user(priv, sync->priv, sync->size))
if (priv == NULL)
return -ENOMEM;
if (copy_from_user(priv, sync->priv, sync->size)) {
kfree(priv);
return -EFAULT; return -EFAULT;
}
ret = func(device, syncobj, priv); return func(device, syncobj, priv);
kfree(priv);
return ret;
} }
static void add_profiling_buffer(struct kgsl_device *device, static void add_profiling_buffer(struct kgsl_device *device,

Loading…
Cancel
Save