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

staging: vme_user: make vme_user_sysfs_class constant

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

Link: https://lore.kernel.org/r/2023100523-throwback-oak-a164@gregkh
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

+13 -13
+13 -13
drivers/staging/vme_user/vme_user.c
··· 37 37 #include "vme.h" 38 38 #include "vme_user.h" 39 39 40 - static const char driver_name[] = "vme_user"; 40 + #define DRIVER_NAME "vme_user" 41 41 42 42 static int bus[VME_USER_BUS_MAX]; 43 43 static unsigned int bus_num; ··· 101 101 static struct image_desc image[VME_DEVS]; 102 102 103 103 static struct cdev *vme_user_cdev; /* Character device */ 104 - static struct class *vme_user_sysfs_class; /* Sysfs class */ 105 104 static struct vme_dev *vme_user_bridge; /* Pointer to user device */ 106 105 106 + static const struct class vme_user_sysfs_class = { 107 + .name = DRIVER_NAME, 108 + }; 107 109 static const int type[VME_DEVS] = { MASTER_MINOR, MASTER_MINOR, 108 110 MASTER_MINOR, MASTER_MINOR, 109 111 SLAVE_MINOR, SLAVE_MINOR, ··· 542 540 } 543 541 544 542 /* Assign major and minor numbers for the driver */ 545 - err = register_chrdev_region(MKDEV(VME_MAJOR, 0), VME_DEVS, 546 - driver_name); 543 + err = register_chrdev_region(MKDEV(VME_MAJOR, 0), VME_DEVS, DRIVER_NAME); 547 544 if (err) { 548 545 dev_warn(&vdev->dev, "Error getting Major Number %d for driver.\n", 549 546 VME_MAJOR); ··· 615 614 } 616 615 617 616 /* Create sysfs entries - on udev systems this creates the dev files */ 618 - vme_user_sysfs_class = class_create(driver_name); 619 - if (IS_ERR(vme_user_sysfs_class)) { 617 + err = class_register(&vme_user_sysfs_class); 618 + if (err) { 620 619 dev_err(&vdev->dev, "Error creating vme_user class.\n"); 621 - err = PTR_ERR(vme_user_sysfs_class); 622 620 goto err_master; 623 621 } 624 622 ··· 641 641 } 642 642 643 643 num = (type[i] == SLAVE_MINOR) ? i - (MASTER_MAX + 1) : i; 644 - image[i].device = device_create(vme_user_sysfs_class, NULL, 644 + image[i].device = device_create(&vme_user_sysfs_class, NULL, 645 645 MKDEV(VME_MAJOR, i), NULL, 646 646 name, num); 647 647 if (IS_ERR(image[i].device)) { ··· 656 656 err_sysfs: 657 657 while (i > 0) { 658 658 i--; 659 - device_destroy(vme_user_sysfs_class, MKDEV(VME_MAJOR, i)); 659 + device_destroy(&vme_user_sysfs_class, MKDEV(VME_MAJOR, i)); 660 660 } 661 - class_destroy(vme_user_sysfs_class); 661 + class_unregister(&vme_user_sysfs_class); 662 662 663 663 /* Ensure counter set correctly to unalloc all master windows */ 664 664 i = MASTER_MAX + 1; ··· 696 696 /* Remove sysfs Entries */ 697 697 for (i = 0; i < VME_DEVS; i++) { 698 698 mutex_destroy(&image[i].mutex); 699 - device_destroy(vme_user_sysfs_class, MKDEV(VME_MAJOR, i)); 699 + device_destroy(&vme_user_sysfs_class, MKDEV(VME_MAJOR, i)); 700 700 } 701 - class_destroy(vme_user_sysfs_class); 701 + class_unregister(&vme_user_sysfs_class); 702 702 703 703 for (i = MASTER_MINOR; i < (MASTER_MAX + 1); i++) { 704 704 kfree(image[i].kern_buf); ··· 720 720 } 721 721 722 722 static struct vme_driver vme_user_driver = { 723 - .name = driver_name, 723 + .name = DRIVER_NAME, 724 724 .match = vme_user_match, 725 725 .probe = vme_user_probe, 726 726 .remove = vme_user_remove,