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

ocxl: make ocxl_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: Andrew Donnellan <ajd@linux.ibm.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: linuxppc-dev@lists.ozlabs.org
Acked-by: Frederic Barrat <fbarrat@linux.ibm.com>
Link: https://lore.kernel.org/r/2023102403-squirt-defraud-6c0c@gregkh
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

+15 -12
+15 -12
drivers/misc/ocxl/file.c
··· 14 14 #define OCXL_NUM_MINORS 256 /* Total to reserve */ 15 15 16 16 static dev_t ocxl_dev; 17 - static struct class *ocxl_class; 18 17 static DEFINE_MUTEX(minors_idr_lock); 19 18 static struct idr minors_idr; 20 19 ··· 508 509 cdev_del(&info->cdev); 509 510 } 510 511 512 + static char *ocxl_devnode(const struct device *dev, umode_t *mode) 513 + { 514 + return kasprintf(GFP_KERNEL, "ocxl/%s", dev_name(dev)); 515 + } 516 + 517 + static const struct class ocxl_class = { 518 + .name = "ocxl", 519 + .devnode = ocxl_devnode, 520 + }; 521 + 511 522 int ocxl_file_register_afu(struct ocxl_afu *afu) 512 523 { 513 524 int minor; ··· 538 529 539 530 info->dev.parent = &fn->dev; 540 531 info->dev.devt = MKDEV(MAJOR(ocxl_dev), minor); 541 - info->dev.class = ocxl_class; 532 + info->dev.class = &ocxl_class; 542 533 info->dev.release = info_release; 543 534 544 535 info->afu = afu; ··· 593 584 device_unregister(&info->dev); 594 585 } 595 586 596 - static char *ocxl_devnode(const struct device *dev, umode_t *mode) 597 - { 598 - return kasprintf(GFP_KERNEL, "ocxl/%s", dev_name(dev)); 599 - } 600 - 601 587 int ocxl_file_init(void) 602 588 { 603 589 int rc; ··· 605 601 return rc; 606 602 } 607 603 608 - ocxl_class = class_create("ocxl"); 609 - if (IS_ERR(ocxl_class)) { 604 + rc = class_register(&ocxl_class); 605 + if (rc) { 610 606 pr_err("Unable to create ocxl class\n"); 611 607 unregister_chrdev_region(ocxl_dev, OCXL_NUM_MINORS); 612 - return PTR_ERR(ocxl_class); 608 + return rc; 613 609 } 614 610 615 - ocxl_class->devnode = ocxl_devnode; 616 611 return 0; 617 612 } 618 613 619 614 void ocxl_file_exit(void) 620 615 { 621 - class_destroy(ocxl_class); 616 + class_unregister(&ocxl_class); 622 617 unregister_chrdev_region(ocxl_dev, OCXL_NUM_MINORS); 623 618 idr_destroy(&minors_idr); 624 619 }