Skip to content

Commit 6e14ade

Browse files
Aurabindo Pillaialexdeucher
authored andcommitted
drm/amd/amdkfd: Fix large framesize for kfd_smi_ev_read()
The buffer allocated is of 1024 bytes. Allocate this from heap instead of stack. Also remove check for stack size since we're allocating from heap Signed-off-by: Aurabindo Pillai <[email protected]> Tested-by: Amber Lin <[email protected]> Reviewed-by: Felix Kuehling <[email protected]> Reviewed-by: Alex Deucher <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent 91e2c19 commit 6e14ade

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,11 @@ static ssize_t kfd_smi_ev_read(struct file *filep, char __user *user,
7878
int ret;
7979
size_t to_copy;
8080
struct kfd_smi_client *client = filep->private_data;
81-
unsigned char buf[MAX_KFIFO_SIZE];
81+
unsigned char *buf;
8282

83-
BUILD_BUG_ON(MAX_KFIFO_SIZE > 1024);
83+
buf = kmalloc(MAX_KFIFO_SIZE * sizeof(*buf), GFP_KERNEL);
84+
if (!buf)
85+
return -ENOMEM;
8486

8587
/* kfifo_to_user can sleep so we can't use spinlock protection around
8688
* it. Instead, we kfifo out as spinlocked then copy them to the user.
@@ -89,19 +91,29 @@ static ssize_t kfd_smi_ev_read(struct file *filep, char __user *user,
8991
to_copy = kfifo_len(&client->fifo);
9092
if (!to_copy) {
9193
spin_unlock(&client->lock);
92-
return -EAGAIN;
94+
ret = -EAGAIN;
95+
goto ret_err;
9396
}
9497
to_copy = min3(size, sizeof(buf), to_copy);
9598
ret = kfifo_out(&client->fifo, buf, to_copy);
9699
spin_unlock(&client->lock);
97-
if (ret <= 0)
98-
return -EAGAIN;
100+
if (ret <= 0) {
101+
ret = -EAGAIN;
102+
goto ret_err;
103+
}
99104

100105
ret = copy_to_user(user, buf, to_copy);
101-
if (ret)
102-
return -EFAULT;
106+
if (ret) {
107+
ret = -EFAULT;
108+
goto ret_err;
109+
}
103110

111+
kfree(buf);
104112
return to_copy;
113+
114+
ret_err:
115+
kfree(buf);
116+
return ret;
105117
}
106118

107119
static ssize_t kfd_smi_ev_write(struct file *filep, const char __user *user,

0 commit comments

Comments
 (0)