accel/habanalabs: add missing error flow in hl_sysfs_init()
authorTomer Tayar <ttayar@habana.ai>
Sun, 2 Apr 2023 10:42:35 +0000 (13:42 +0300)
committerOded Gabbay <ogabbay@kernel.org>
Sat, 8 Apr 2023 07:44:23 +0000 (10:44 +0300)
hl_sysfs_fini() is called only if hl_sysfs_init() completes
successfully. Therefore if hl_sysfs_init() fails, need to remove any
sysfs group that was added until that point.

Signed-off-by: Tomer Tayar <ttayar@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
drivers/accel/habanalabs/common/sysfs.c

index 735d8be..01f89f0 100644 (file)
@@ -497,10 +497,14 @@ int hl_sysfs_init(struct hl_device *hdev)
        if (rc) {
                dev_err(hdev->dev,
                        "Failed to add groups to device, error %d\n", rc);
-               return rc;
+               goto remove_groups;
        }
 
        return 0;
+
+remove_groups:
+       device_remove_groups(hdev->dev, hl_dev_attr_groups);
+       return rc;
 }
 
 void hl_sysfs_fini(struct hl_device *hdev)