uacce: publish the device in uacce_register()
Subsystems (2)
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.
---
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
@@ -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
Quoted 10 lines · Changyul Lee
uacce_alloc()publishes the device inuacce_xabefore 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 inuacce_register(), after initialization. Until then,xa_load()returns NULL andopen()returns-ENODEV.Fixes 015d239ac014 ("uacce: add uacce driver")Signed-off-by Changyul Lee <[email protected]>
Quoted 37 lines
---
Found with an in-development static analysis tool. Compile-tested only withx86_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@@ -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:
aebb7274476403040d582c61478df8f4a7bf9cd3Signature · 1 line
2.43.0