]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
accel/habanalabs: split cdev creation to separate function
authorOded Gabbay <ogabbay@kernel.org>
Sun, 22 Jan 2023 12:59:11 +0000 (14:59 +0200)
committerOded Gabbay <ogabbay@kernel.org>
Wed, 15 Mar 2023 11:29:11 +0000 (13:29 +0200)
Move the cdev creation code from the main hdev init function to
a separate function. This will make the code more readable once we
add the accel registration code (instead/in addition to legacy
cdev).

Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
Reviewed-by: Tomer Tayar <ttayar@habana.ai>
Reviewed-by: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com>
drivers/accel/habanalabs/common/device.c

index 9933e5858a36330c172a89d39bf3134efb1c80a5..ed26b7d20d1979ce623256166384b3e9312e6e62 100644 (file)
@@ -1939,27 +1939,17 @@ void hl_notifier_event_send_all(struct hl_device *hdev, u64 event_mask)
        mutex_unlock(&hdev->fpriv_ctrl_list_lock);
 }
 
-/*
- * hl_device_init - main initialization function for habanalabs device
- *
- * @hdev: pointer to habanalabs device structure
- *
- * Allocate an id for the device, do early initialization and then call the
- * ASIC specific initialization functions. Finally, create the cdev and the
- * Linux device to expose it to the user
- */
-int hl_device_init(struct hl_device *hdev, struct class *hclass)
+static int create_cdev(struct hl_device *hdev, struct class *hclass)
 {
-       int i, rc, cq_cnt, user_interrupt_cnt, cq_ready_cnt;
        char *name;
-       bool add_cdev_sysfs_on_err = false;
+       int rc;
 
        hdev->cdev_idx = hdev->id / 2;
 
        name = kasprintf(GFP_KERNEL, "hl%d", hdev->cdev_idx);
        if (!name) {
                rc = -ENOMEM;
-               goto out_disabled;
+               goto out_err;
        }
 
        /* Initialize cdev and device structures */
@@ -1969,7 +1959,7 @@ int hl_device_init(struct hl_device *hdev, struct class *hclass)
        kfree(name);
 
        if (rc)
-               goto out_disabled;
+               goto out_err;
 
        name = kasprintf(GFP_KERNEL, "hl_controlD%d", hdev->cdev_idx);
        if (!name) {
@@ -1986,10 +1976,36 @@ int hl_device_init(struct hl_device *hdev, struct class *hclass)
        if (rc)
                goto free_dev;
 
+       return 0;
+
+free_dev:
+       put_device(hdev->dev);
+out_err:
+       return rc;
+}
+
+/*
+ * hl_device_init - main initialization function for habanalabs device
+ *
+ * @hdev: pointer to habanalabs device structure
+ *
+ * Allocate an id for the device, do early initialization and then call the
+ * ASIC specific initialization functions. Finally, create the cdev and the
+ * Linux device to expose it to the user
+ */
+int hl_device_init(struct hl_device *hdev, struct class *hclass)
+{
+       int i, rc, cq_cnt, user_interrupt_cnt, cq_ready_cnt;
+       bool add_cdev_sysfs_on_err = false;
+
+       rc = create_cdev(hdev, hclass);
+       if (rc)
+               goto out_disabled;
+
        /* Initialize ASIC function pointers and perform early init */
        rc = device_early_init(hdev);
        if (rc)
-               goto free_dev_ctrl;
+               goto free_dev;
 
        user_interrupt_cnt = hdev->asic_prop.user_dec_intr_count +
                                hdev->asic_prop.user_interrupt_count;
@@ -2241,9 +2257,8 @@ free_usr_intr_mem:
        kfree(hdev->user_interrupt);
 early_fini:
        device_early_fini(hdev);
-free_dev_ctrl:
-       put_device(hdev->dev_ctrl);
 free_dev:
+       put_device(hdev->dev_ctrl);
        put_device(hdev->dev);
 out_disabled:
        hdev->disabled = true;