Skip to content

Commit 40ea89f

Browse files
committed
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: Zhangfei Gao <zhangfei.gao@linaro.org> Link: https://lore.kernel.org/r/2023102458-designate-vicinity-4c86@gregkh Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent cf3c415 commit 40ea89f

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

drivers/misc/uacce/uacce.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
#include <linux/slab.h>
88
#include <linux/uacce.h>
99

10-
static struct class *uacce_class;
1110
static dev_t uacce_devt;
1211
static DEFINE_XARRAY_ALLOC(uacce_xa);
1312

13+
static const struct class uacce_class = {
14+
.name = UACCE_NAME,
15+
};
16+
1417
/*
1518
* If the parent driver or the device disappears, the queue state is invalid and
1619
* ops are not usable anymore.
@@ -530,7 +533,7 @@ struct uacce_device *uacce_alloc(struct device *parent,
530533
mutex_init(&uacce->mutex);
531534
device_initialize(&uacce->dev);
532535
uacce->dev.devt = MKDEV(MAJOR(uacce_devt), uacce->dev_id);
533-
uacce->dev.class = uacce_class;
536+
uacce->dev.class = &uacce_class;
534537
uacce->dev.groups = uacce_dev_groups;
535538
uacce->dev.parent = uacce->parent;
536539
uacce->dev.release = uacce_release;
@@ -623,21 +626,21 @@ static int __init uacce_init(void)
623626
{
624627
int ret;
625628

626-
uacce_class = class_create(UACCE_NAME);
627-
if (IS_ERR(uacce_class))
628-
return PTR_ERR(uacce_class);
629+
ret = class_register(&uacce_class);
630+
if (ret)
631+
return ret;
629632

630633
ret = alloc_chrdev_region(&uacce_devt, 0, MINORMASK, UACCE_NAME);
631634
if (ret)
632-
class_destroy(uacce_class);
635+
class_unregister(&uacce_class);
633636

634637
return ret;
635638
}
636639

637640
static __exit void uacce_exit(void)
638641
{
639642
unregister_chrdev_region(uacce_devt, MINORMASK);
640-
class_destroy(uacce_class);
643+
class_unregister(&uacce_class);
641644
}
642645

643646
subsys_initcall(uacce_init);

0 commit comments

Comments
 (0)