Commit 40ea89fb authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

uacce: make uacce_class constant

Now that the driver core allows for struct class to be in read-only
memory, we should make all 'class' structures declared at build time
placing them into read-only memory, instead of having to be dynamically
allocated at runtime.

Cc: Zhou Wang <wangzhou1@hisilicon.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: linux-accelerators@lists.ozlabs.org
Tested-by: default avatarZhangfei Gao <zhangfei.gao@linaro.org>
Link: https://lore.kernel.org/r/2023102458-designate-vicinity-4c86@gregkhSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent cf3c415d
...@@ -7,10 +7,13 @@ ...@@ -7,10 +7,13 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/uacce.h> #include <linux/uacce.h>
static struct class *uacce_class;
static dev_t uacce_devt; static dev_t uacce_devt;
static DEFINE_XARRAY_ALLOC(uacce_xa); static DEFINE_XARRAY_ALLOC(uacce_xa);
static const struct class uacce_class = {
.name = UACCE_NAME,
};
/* /*
* If the parent driver or the device disappears, the queue state is invalid and * If the parent driver or the device disappears, the queue state is invalid and
* ops are not usable anymore. * ops are not usable anymore.
...@@ -530,7 +533,7 @@ struct uacce_device *uacce_alloc(struct device *parent, ...@@ -530,7 +533,7 @@ struct uacce_device *uacce_alloc(struct device *parent,
mutex_init(&uacce->mutex); mutex_init(&uacce->mutex);
device_initialize(&uacce->dev); device_initialize(&uacce->dev);
uacce->dev.devt = MKDEV(MAJOR(uacce_devt), uacce->dev_id); uacce->dev.devt = MKDEV(MAJOR(uacce_devt), uacce->dev_id);
uacce->dev.class = uacce_class; uacce->dev.class = &uacce_class;
uacce->dev.groups = uacce_dev_groups; uacce->dev.groups = uacce_dev_groups;
uacce->dev.parent = uacce->parent; uacce->dev.parent = uacce->parent;
uacce->dev.release = uacce_release; uacce->dev.release = uacce_release;
...@@ -623,13 +626,13 @@ static int __init uacce_init(void) ...@@ -623,13 +626,13 @@ static int __init uacce_init(void)
{ {
int ret; int ret;
uacce_class = class_create(UACCE_NAME); ret = class_register(&uacce_class);
if (IS_ERR(uacce_class)) if (ret)
return PTR_ERR(uacce_class); return ret;
ret = alloc_chrdev_region(&uacce_devt, 0, MINORMASK, UACCE_NAME); ret = alloc_chrdev_region(&uacce_devt, 0, MINORMASK, UACCE_NAME);
if (ret) if (ret)
class_destroy(uacce_class); class_unregister(&uacce_class);
return ret; return ret;
} }
...@@ -637,7 +640,7 @@ static int __init uacce_init(void) ...@@ -637,7 +640,7 @@ static int __init uacce_init(void)
static __exit void uacce_exit(void) static __exit void uacce_exit(void)
{ {
unregister_chrdev_region(uacce_devt, MINORMASK); unregister_chrdev_region(uacce_devt, MINORMASK);
class_destroy(uacce_class); class_unregister(&uacce_class);
} }
subsys_initcall(uacce_init); subsys_initcall(uacce_init);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment