Skip to content

Commit 21168bd

Browse files
gregkhJiri Kosina
authored andcommitted
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 <[email protected]> Cc: Benjamin Tissoires <[email protected]> Cc: [email protected] Cc: Ivan Orlov <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent fadfcf3 commit 21168bd

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

drivers/hid/hidraw.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232

3333
static int hidraw_major;
3434
static struct cdev hidraw_cdev;
35-
static struct class *hidraw_class;
35+
static const struct class hidraw_class = {
36+
.name = "hidraw",
37+
};
3638
static struct hidraw *hidraw_table[HIDRAW_MAX_DEVICES];
3739
static DECLARE_RWSEM(minors_rwsem);
3840

@@ -329,7 +331,7 @@ static void drop_ref(struct hidraw *hidraw, int exists_bit)
329331
hid_hw_close(hidraw->hid);
330332
wake_up_interruptible(&hidraw->wait);
331333
}
332-
device_destroy(hidraw_class,
334+
device_destroy(&hidraw_class,
333335
MKDEV(hidraw_major, hidraw->minor));
334336
} else {
335337
--hidraw->open;
@@ -569,7 +571,7 @@ int hidraw_connect(struct hid_device *hid)
569571
goto out;
570572
}
571573

572-
dev->dev = device_create(hidraw_class, &hid->dev, MKDEV(hidraw_major, minor),
574+
dev->dev = device_create(&hidraw_class, &hid->dev, MKDEV(hidraw_major, minor),
573575
NULL, "%s%d", "hidraw", minor);
574576

575577
if (IS_ERR(dev->dev)) {
@@ -623,11 +625,9 @@ int __init hidraw_init(void)
623625

624626
hidraw_major = MAJOR(dev_id);
625627

626-
hidraw_class = class_create("hidraw");
627-
if (IS_ERR(hidraw_class)) {
628-
result = PTR_ERR(hidraw_class);
628+
result = class_register(&hidraw_class);
629+
if (result)
629630
goto error_cdev;
630-
}
631631

632632
cdev_init(&hidraw_cdev, &hidraw_ops);
633633
result = cdev_add(&hidraw_cdev, dev_id, HIDRAW_MAX_DEVICES);
@@ -639,7 +639,7 @@ int __init hidraw_init(void)
639639
return result;
640640

641641
error_class:
642-
class_destroy(hidraw_class);
642+
class_unregister(&hidraw_class);
643643
error_cdev:
644644
unregister_chrdev_region(dev_id, HIDRAW_MAX_DEVICES);
645645
goto out;
@@ -650,7 +650,7 @@ void hidraw_exit(void)
650650
dev_t dev_id = MKDEV(hidraw_major, 0);
651651

652652
cdev_del(&hidraw_cdev);
653-
class_destroy(hidraw_class);
653+
class_unregister(&hidraw_class);
654654
unregister_chrdev_region(dev_id, HIDRAW_MAX_DEVICES);
655655

656656
}

0 commit comments

Comments
 (0)