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

HID: hidraw: make hidraw_class structure const

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.

Cc: Jiri Kosina <jikos@kernel.org>
Cc: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Cc: linux-input@vger.kernel.org
Cc: Ivan Orlov <ivan.orlov0322@gmail.com>
Link: https://lore.kernel.org/r/20230620183141.681353-4-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

+9 -9
+9 -9
drivers/hid/hidraw.c
··· 32 32 33 33 static int hidraw_major; 34 34 static struct cdev hidraw_cdev; 35 - static struct class *hidraw_class; 35 + static const struct class hidraw_class = { 36 + .name = "hidraw", 37 + }; 36 38 static struct hidraw *hidraw_table[HIDRAW_MAX_DEVICES]; 37 39 static DECLARE_RWSEM(minors_rwsem); 38 40 ··· 331 329 hid_hw_close(hidraw->hid); 332 330 wake_up_interruptible(&hidraw->wait); 333 331 } 334 - device_destroy(hidraw_class, 332 + device_destroy(&hidraw_class, 335 333 MKDEV(hidraw_major, hidraw->minor)); 336 334 } else { 337 335 --hidraw->open; ··· 571 569 goto out; 572 570 } 573 571 574 - dev->dev = device_create(hidraw_class, &hid->dev, MKDEV(hidraw_major, minor), 572 + dev->dev = device_create(&hidraw_class, &hid->dev, MKDEV(hidraw_major, minor), 575 573 NULL, "%s%d", "hidraw", minor); 576 574 577 575 if (IS_ERR(dev->dev)) { ··· 625 623 626 624 hidraw_major = MAJOR(dev_id); 627 625 628 - hidraw_class = class_create("hidraw"); 629 - if (IS_ERR(hidraw_class)) { 630 - result = PTR_ERR(hidraw_class); 626 + result = class_register(&hidraw_class); 627 + if (result) 631 628 goto error_cdev; 632 - } 633 629 634 630 cdev_init(&hidraw_cdev, &hidraw_ops); 635 631 result = cdev_add(&hidraw_cdev, dev_id, HIDRAW_MAX_DEVICES); ··· 639 639 return result; 640 640 641 641 error_class: 642 - class_destroy(hidraw_class); 642 + class_unregister(&hidraw_class); 643 643 error_cdev: 644 644 unregister_chrdev_region(dev_id, HIDRAW_MAX_DEVICES); 645 645 goto out; ··· 650 650 dev_t dev_id = MKDEV(hidraw_major, 0); 651 651 652 652 cdev_del(&hidraw_cdev); 653 - class_destroy(hidraw_class); 653 + class_unregister(&hidraw_class); 654 654 unregister_chrdev_region(dev_id, HIDRAW_MAX_DEVICES); 655 655 656 656 }