Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+10 -7
+10 -7
drivers/misc/uacce/uacce.c
··· 7 7 #include <linux/slab.h> 8 8 #include <linux/uacce.h> 9 9 10 - static struct class *uacce_class; 11 10 static dev_t uacce_devt; 12 11 static DEFINE_XARRAY_ALLOC(uacce_xa); 12 + 13 + static const struct class uacce_class = { 14 + .name = UACCE_NAME, 15 + }; 13 16 14 17 /* 15 18 * If the parent driver or the device disappears, the queue state is invalid and ··· 533 530 mutex_init(&uacce->mutex); 534 531 device_initialize(&uacce->dev); 535 532 uacce->dev.devt = MKDEV(MAJOR(uacce_devt), uacce->dev_id); 536 - uacce->dev.class = uacce_class; 533 + uacce->dev.class = &uacce_class; 537 534 uacce->dev.groups = uacce_dev_groups; 538 535 uacce->dev.parent = uacce->parent; 539 536 uacce->dev.release = uacce_release; ··· 626 623 { 627 624 int ret; 628 625 629 - uacce_class = class_create(UACCE_NAME); 630 - if (IS_ERR(uacce_class)) 631 - return PTR_ERR(uacce_class); 626 + ret = class_register(&uacce_class); 627 + if (ret) 628 + return ret; 632 629 633 630 ret = alloc_chrdev_region(&uacce_devt, 0, MINORMASK, UACCE_NAME); 634 631 if (ret) 635 - class_destroy(uacce_class); 632 + class_unregister(&uacce_class); 636 633 637 634 return ret; 638 635 } ··· 640 637 static __exit void uacce_exit(void) 641 638 { 642 639 unregister_chrdev_region(uacce_devt, MINORMASK); 643 - class_destroy(uacce_class); 640 + class_unregister(&uacce_class); 644 641 } 645 642 646 643 subsys_initcall(uacce_init);