mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] uacce: publish the device in uacce_register()
@ 2026-11-19  1:59 Changyul Lee
  2026-11-19 15:48 ` Jean-Philippe Brucker
  0 siblings, 1 reply; 2+ messages in thread
From: Changyul Lee @ 2026-11-19  1:59 UTC (permalink / raw)
  To: Zhangfei Gao, Zhou Wang, Arnd Bergmann, Greg Kroah-Hartman
  Cc: Jean-Philippe Brucker, Herbert Xu, linux-accelerators,
	linux-kernel, 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")
Signed-off-by: Changyul Lee <lcy8047@gmail.com>
---
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(-)

diff --git a/drivers/misc/uacce/uacce.c b/drivers/misc/uacce/uacce.c
index 45521d4a56d1..026f076fa0be 100644
--- a/drivers/misc/uacce/uacce.c
+++ b/drivers/misc/uacce/uacce.c
@@ -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
-- 
2.43.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] uacce: publish the device in uacce_register()
  2026-11-19  1:59 [PATCH] uacce: publish the device in uacce_register() Changyul Lee
@ 2026-11-19 15:48 ` Jean-Philippe Brucker
  0 siblings, 0 replies; 2+ messages in thread
From: Jean-Philippe Brucker @ 2026-11-19 15:48 UTC (permalink / raw)
  To: Changyul Lee
  Cc: Zhangfei Gao, Zhou Wang, Arnd Bergmann, Greg Kroah-Hartman,
	Herbert Xu, linux-accelerators, linux-kernel

On Wed, Nov 18, 2026 at 08:59:31PM -0500, Changyul Lee wrote:
> 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")
> Signed-off-by: Changyul Lee <lcy8047@gmail.com>

Reviewed-by: Jean-Philippe Brucker <jpb@kernel.org>

> ---
> 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(-)
> 
> diff --git a/drivers/misc/uacce/uacce.c b/drivers/misc/uacce/uacce.c
> index 45521d4a56d1..026f076fa0be 100644
> --- a/drivers/misc/uacce/uacce.c
> +++ b/drivers/misc/uacce/uacce.c
> @@ -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
> -- 
> 2.43.0
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-19 15:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19  1:59 [PATCH] uacce: publish the device in uacce_register() Changyul Lee
2026-11-19 15:48 ` Jean-Philippe Brucker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®