Commit 32944855 authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

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.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent afdf5dd3
...@@ -32,7 +32,9 @@ ...@@ -32,7 +32,9 @@
static int hidraw_major; static int hidraw_major;
static struct cdev hidraw_cdev; static struct cdev hidraw_cdev;
static struct class *hidraw_class; static const struct class hidraw_class = {
.name = "hidraw",
};
static struct hidraw *hidraw_table[HIDRAW_MAX_DEVICES]; static struct hidraw *hidraw_table[HIDRAW_MAX_DEVICES];
static DECLARE_RWSEM(minors_rwsem); static DECLARE_RWSEM(minors_rwsem);
...@@ -329,7 +331,7 @@ static void drop_ref(struct hidraw *hidraw, int exists_bit) ...@@ -329,7 +331,7 @@ static void drop_ref(struct hidraw *hidraw, int exists_bit)
hid_hw_close(hidraw->hid); hid_hw_close(hidraw->hid);
wake_up_interruptible(&hidraw->wait); wake_up_interruptible(&hidraw->wait);
} }
device_destroy(hidraw_class, device_destroy(&hidraw_class,
MKDEV(hidraw_major, hidraw->minor)); MKDEV(hidraw_major, hidraw->minor));
} else { } else {
--hidraw->open; --hidraw->open;
...@@ -569,7 +571,7 @@ int hidraw_connect(struct hid_device *hid) ...@@ -569,7 +571,7 @@ int hidraw_connect(struct hid_device *hid)
goto out; goto out;
} }
dev->dev = device_create(hidraw_class, &hid->dev, MKDEV(hidraw_major, minor), dev->dev = device_create(&hidraw_class, &hid->dev, MKDEV(hidraw_major, minor),
NULL, "%s%d", "hidraw", minor); NULL, "%s%d", "hidraw", minor);
if (IS_ERR(dev->dev)) { if (IS_ERR(dev->dev)) {
...@@ -623,11 +625,9 @@ int __init hidraw_init(void) ...@@ -623,11 +625,9 @@ int __init hidraw_init(void)
hidraw_major = MAJOR(dev_id); hidraw_major = MAJOR(dev_id);
hidraw_class = class_create("hidraw"); result = class_register(&hidraw_class);
if (IS_ERR(hidraw_class)) { if (result)
result = PTR_ERR(hidraw_class);
goto error_cdev; goto error_cdev;
}
cdev_init(&hidraw_cdev, &hidraw_ops); cdev_init(&hidraw_cdev, &hidraw_ops);
result = cdev_add(&hidraw_cdev, dev_id, HIDRAW_MAX_DEVICES); result = cdev_add(&hidraw_cdev, dev_id, HIDRAW_MAX_DEVICES);
...@@ -639,7 +639,7 @@ int __init hidraw_init(void) ...@@ -639,7 +639,7 @@ int __init hidraw_init(void)
return result; return result;
error_class: error_class:
class_destroy(hidraw_class); class_unregister(&hidraw_class);
error_cdev: error_cdev:
unregister_chrdev_region(dev_id, HIDRAW_MAX_DEVICES); unregister_chrdev_region(dev_id, HIDRAW_MAX_DEVICES);
goto out; goto out;
...@@ -650,7 +650,7 @@ void hidraw_exit(void) ...@@ -650,7 +650,7 @@ void hidraw_exit(void)
dev_t dev_id = MKDEV(hidraw_major, 0); dev_t dev_id = MKDEV(hidraw_major, 0);
cdev_del(&hidraw_cdev); cdev_del(&hidraw_cdev);
class_destroy(hidraw_class); class_unregister(&hidraw_class);
unregister_chrdev_region(dev_id, HIDRAW_MAX_DEVICES); unregister_chrdev_region(dev_id, HIDRAW_MAX_DEVICES);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment