OSDN Git Service

staging: sync: Use an on-stack allocation for fence info ioctl
authorSultan Alsawaf <sultan@kerneltoast.com>
Wed, 31 Jul 2019 06:56:18 +0000 (23:56 -0700)
committer0ranko0P <ranko0p@outlook.com>
Sat, 7 Dec 2019 10:22:18 +0000 (18:22 +0800)
Since the fence info ioctl limits output data length to 4096 bytes, we
can just use a 4096-byte on-stack buffer for it (which is confirmed to
be safe via runtime stack usage measurements). This ioctl is used for
every frame rendered to the display, so eliminating dynamic memory
allocation overhead here improves frame rendering performance.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
drivers/staging/android/sync.c

index 11ad6c4..24e5bf3 100644 (file)
@@ -670,7 +670,8 @@ static int sync_fill_pt_info(struct fence *fence, void *data, int size)
 static long sync_fence_ioctl_fence_info(struct sync_fence *fence,
                                        unsigned long arg)
 {
-       struct sync_fence_info_data *data;
+       u8 data_buf[4096] __aligned(sizeof(long));
+       struct sync_fence_info_data *data = (typeof(data))data_buf;
        __u32 size;
        __u32 len = 0;
        int ret, i;
@@ -684,10 +685,6 @@ static long sync_fence_ioctl_fence_info(struct sync_fence *fence,
        if (size > 4096)
                size = 4096;
 
-       data = kzalloc(size, GFP_KERNEL);
-       if (data == NULL)
-               return -ENOMEM;
-
 #ifdef CONFIG_SYNC_DEBUG
        strlcpy(data->name, fence->name, sizeof(data->name));
 #endif
@@ -716,7 +713,6 @@ static long sync_fence_ioctl_fence_info(struct sync_fence *fence,
                ret = 0;
 
 out:
-       kfree(data);
 
        return ret;
 }