drm/amdkfd: Create file descriptor after client is added to smi_clients list
authorjsg <jsg@openbsd.org>
Thu, 14 Apr 2022 08:52:38 +0000 (08:52 +0000)
committerjsg <jsg@openbsd.org>
Thu, 14 Apr 2022 08:52:38 +0000 (08:52 +0000)
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

index ed4bc5f..766b366 100644 (file)
@@ -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;
 }