Skip to contentSkip to conversation

uacce: publish the device in uacce_register()

PATCH In review Changyul Lee 2 participants 2 messages Nov 19

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 uacce: publish the device in uacce_register()

uacce_alloc() publishes the device in uacce_xa before initialization is complete. If a minor is reused, open() can find the new device before its queue list, mutex, or driver-private data is ready.

Reserve the minor in uacce_alloc() and publish the device in uacce_register(), after initialization. Until then, xa_load() returns NULL and open() returns -ENODEV.

Fixes 015d239ac014 ("uacce: add uacce driver")

---
Found with an in-development static analysis tool. Compile-tested only with x86_64_defconfig, INTEL_IOMMU=y, UACCE enabled, and W=1.

 drivers/misc/uacce/uacce.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/misc/uacce/uacce.c +5 -1
index 45521d4a56d1..026f076fa0be 100644
@@ -514,7 +514,7 @@ struct uacce_device *uacce_alloc(struct device *parent,
 	uacce->flags = flags;
 	uacce->ops = interface->ops;
 
-	ret = xa_alloc(&uacce_xa, &uacce->dev_id, uacce, xa_limit_32b,
+	ret = xa_alloc(&uacce_xa, &uacce->dev_id, NULL, xa_limit_32b,
 		       GFP_KERNEL);
 	if (ret < 0)
 		goto err_with_uacce;
@@ -550,6 +550,10 @@ int uacce_register(struct uacce_device *uacce)
 	if (!uacce)
 		return -ENODEV;
 
+	ret = xa_err(xa_store(&uacce_xa, uacce->dev_id, uacce, GFP_KERNEL));
+	if (ret)
+		return ret;
+
 	uacce->cdev = cdev_alloc();
 	if (!uacce->cdev)
 		return -ENOMEM;

base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3

Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Changyul Lee

uacce_alloc() publishes the device in uacce_xa before initialization is complete. If a minor is reused, open() can find the new device before its queue list, mutex, or driver-private data is ready.

Reserve the minor in uacce_alloc() and publish the device in uacce_register(), after initialization. Until then, xa_load() returns NULL and open() returns -ENODEV.

Fixes 015d239ac014 ("uacce: add uacce driver")
Quoted 37 lines

---
Found with an in-development static analysis tool. Compile-tested only with x86_64_defconfig, INTEL_IOMMU=y, UACCE enabled, and W=1.

 drivers/misc/uacce/uacce.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/misc/uacce/uacce.c +5 -1
index 45521d4a56d1..026f076fa0be 100644
@@ -514,7 +514,7 @@ struct uacce_device *uacce_alloc(struct device *parent,
 	uacce->flags = flags;
 	uacce->ops = interface->ops;
 
-	ret = xa_alloc(&uacce_xa, &uacce->dev_id, uacce, xa_limit_32b,
+	ret = xa_alloc(&uacce_xa, &uacce->dev_id, NULL, xa_limit_32b,
 		       GFP_KERNEL);
 	if (ret < 0)
 		goto err_with_uacce;
@@ -550,6 +550,10 @@ int uacce_register(struct uacce_device *uacce)
 	if (!uacce)
 		return -ENODEV;
 
+	ret = xa_err(xa_store(&uacce_xa, uacce->dev_id, uacce, GFP_KERNEL));
+	if (ret)
+		return ret;
+
 	uacce->cdev = cdev_alloc();
 	if (!uacce->cdev)
 		return -ENOMEM;

base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3

Signature · 1 line
2.43.0