From f3d75da59fc7f9ac030ddb1e02b2f53756bb188a Mon Sep 17 00:00:00 2001 From: jsg Date: Thu, 14 Apr 2022 08:52:38 +0000 Subject: [PATCH] drm/amdkfd: Create file descriptor after client is added to smi_clients list From Lee Jones 3c8902bbf2ab5a15443f3daa73e8da18e7792172 in linux 5.15.y/5.15.34 e79a2398e1b2d47060474dca291542368183bc0f in mainline linux --- sys/dev/pci/drm/amd/amdkfd/kfd_smi_events.c | 24 +++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/sys/dev/pci/drm/amd/amdkfd/kfd_smi_events.c b/sys/dev/pci/drm/amd/amdkfd/kfd_smi_events.c index ed4bc5f844c..766b3660c8c 100644 --- a/sys/dev/pci/drm/amd/amdkfd/kfd_smi_events.c +++ b/sys/dev/pci/drm/amd/amdkfd/kfd_smi_events.c @@ -270,15 +270,6 @@ int kfd_smi_event_open(struct kfd_dev *dev, uint32_t *fd) return ret; } - ret = anon_inode_getfd(kfd_smi_name, &kfd_smi_ev_fops, (void *)client, - O_RDWR); - if (ret < 0) { - kfifo_free(&client->fifo); - kfree(client); - return ret; - } - *fd = ret; - init_waitqueue_head(&client->wait_queue); spin_lock_init(&client->lock); client->events = 0; @@ -288,5 +279,20 @@ int kfd_smi_event_open(struct kfd_dev *dev, uint32_t *fd) list_add_rcu(&client->list, &dev->smi_clients); spin_unlock(&dev->smi_lock); + ret = anon_inode_getfd(kfd_smi_name, &kfd_smi_ev_fops, (void *)client, + O_RDWR); + if (ret < 0) { + spin_lock(&dev->smi_lock); + list_del_rcu(&client->list); + spin_unlock(&dev->smi_lock); + + synchronize_rcu(); + + kfifo_free(&client->fifo); + kfree(client); + return ret; + } + *fd = ret; + return 0; } -- 2.20.1