Skip to content

Commit fadfcf3

Browse files
ivanorlov2206Jiri Kosina
authored andcommitted
HID: roccat: make all 'class' structures 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: Stefan Achatz <[email protected]> Cc: Jiri Kosina <[email protected]> Cc: Benjamin Tissoires <[email protected]> Cc: [email protected] Suggested-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Ivan Orlov <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 1d75460 commit fadfcf3

11 files changed

+108
-89
lines changed

drivers/hid/hid-roccat-arvo.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
#include "hid-roccat-common.h"
2424
#include "hid-roccat-arvo.h"
2525

26-
static struct class *arvo_class;
27-
2826
static ssize_t arvo_sysfs_show_mode_key(struct device *dev,
2927
struct device_attribute *attr, char *buf)
3028
{
@@ -268,6 +266,11 @@ static const struct attribute_group *arvo_groups[] = {
268266
NULL,
269267
};
270268

269+
static const struct class arvo_class = {
270+
.name = "arvo",
271+
.dev_groups = arvo_groups,
272+
};
273+
271274
static int arvo_init_arvo_device_struct(struct usb_device *usb_dev,
272275
struct arvo_device *arvo)
273276
{
@@ -309,7 +312,7 @@ static int arvo_init_specials(struct hid_device *hdev)
309312
goto exit_free;
310313
}
311314

312-
retval = roccat_connect(arvo_class, hdev,
315+
retval = roccat_connect(&arvo_class, hdev,
313316
sizeof(struct arvo_roccat_report));
314317
if (retval < 0) {
315318
hid_err(hdev, "couldn't init char dev\n");
@@ -433,21 +436,20 @@ static int __init arvo_init(void)
433436
{
434437
int retval;
435438

436-
arvo_class = class_create("arvo");
437-
if (IS_ERR(arvo_class))
438-
return PTR_ERR(arvo_class);
439-
arvo_class->dev_groups = arvo_groups;
439+
retval = class_register(&arvo_class);
440+
if (retval)
441+
return retval;
440442

441443
retval = hid_register_driver(&arvo_driver);
442444
if (retval)
443-
class_destroy(arvo_class);
445+
class_unregister(&arvo_class);
444446
return retval;
445447
}
446448

447449
static void __exit arvo_exit(void)
448450
{
449451
hid_unregister_driver(&arvo_driver);
450-
class_destroy(arvo_class);
452+
class_unregister(&arvo_class);
451453
}
452454

453455
module_init(arvo_init);

drivers/hid/hid-roccat-isku.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
#include "hid-roccat-common.h"
2424
#include "hid-roccat-isku.h"
2525

26-
static struct class *isku_class;
27-
2826
static void isku_profile_activated(struct isku_device *isku, uint new_profile)
2927
{
3028
isku->actual_profile = new_profile;
@@ -248,6 +246,11 @@ static const struct attribute_group *isku_groups[] = {
248246
NULL,
249247
};
250248

249+
static const struct class isku_class = {
250+
.name = "isku",
251+
.dev_groups = isku_groups,
252+
};
253+
251254
static int isku_init_isku_device_struct(struct usb_device *usb_dev,
252255
struct isku_device *isku)
253256
{
@@ -289,7 +292,7 @@ static int isku_init_specials(struct hid_device *hdev)
289292
goto exit_free;
290293
}
291294

292-
retval = roccat_connect(isku_class, hdev,
295+
retval = roccat_connect(&isku_class, hdev,
293296
sizeof(struct isku_roccat_report));
294297
if (retval < 0) {
295298
hid_err(hdev, "couldn't init char dev\n");
@@ -435,21 +438,21 @@ static struct hid_driver isku_driver = {
435438
static int __init isku_init(void)
436439
{
437440
int retval;
438-
isku_class = class_create("isku");
439-
if (IS_ERR(isku_class))
440-
return PTR_ERR(isku_class);
441-
isku_class->dev_groups = isku_groups;
441+
442+
retval = class_register(&isku_class);
443+
if (retval)
444+
return retval;
442445

443446
retval = hid_register_driver(&isku_driver);
444447
if (retval)
445-
class_destroy(isku_class);
448+
class_unregister(&isku_class);
446449
return retval;
447450
}
448451

449452
static void __exit isku_exit(void)
450453
{
451454
hid_unregister_driver(&isku_driver);
452-
class_destroy(isku_class);
455+
class_unregister(&isku_class);
453456
}
454457

455458
module_init(isku_init);

drivers/hid/hid-roccat-kone.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ static int kone_send(struct usb_device *usb_dev, uint usb_command,
8989
return ((len < 0) ? len : ((len != size) ? -EIO : 0));
9090
}
9191

92-
/* kone_class is used for creating sysfs attributes via roccat char device */
93-
static struct class *kone_class;
94-
9592
static void kone_set_settings_checksum(struct kone_settings *settings)
9693
{
9794
uint16_t checksum = 0;
@@ -657,6 +654,12 @@ static const struct attribute_group *kone_groups[] = {
657654
NULL,
658655
};
659656

657+
/* kone_class is used for creating sysfs attributes via roccat char device */
658+
static const struct class kone_class = {
659+
.name = "kone",
660+
.dev_groups = kone_groups,
661+
};
662+
660663
static int kone_init_kone_device_struct(struct usb_device *usb_dev,
661664
struct kone_device *kone)
662665
{
@@ -712,8 +715,8 @@ static int kone_init_specials(struct hid_device *hdev)
712715
goto exit_free;
713716
}
714717

715-
retval = roccat_connect(kone_class, hdev,
716-
sizeof(struct kone_roccat_report));
718+
retval = roccat_connect(&kone_class, hdev,
719+
sizeof(struct kone_roccat_report));
717720
if (retval < 0) {
718721
hid_err(hdev, "couldn't init char dev\n");
719722
/* be tolerant about not getting chrdev */
@@ -890,21 +893,20 @@ static int __init kone_init(void)
890893
int retval;
891894

892895
/* class name has to be same as driver name */
893-
kone_class = class_create("kone");
894-
if (IS_ERR(kone_class))
895-
return PTR_ERR(kone_class);
896-
kone_class->dev_groups = kone_groups;
896+
retval = class_register(&kone_class);
897+
if (retval)
898+
return retval;
897899

898900
retval = hid_register_driver(&kone_driver);
899901
if (retval)
900-
class_destroy(kone_class);
902+
class_unregister(&kone_class);
901903
return retval;
902904
}
903905

904906
static void __exit kone_exit(void)
905907
{
906908
hid_unregister_driver(&kone_driver);
907-
class_destroy(kone_class);
909+
class_unregister(&kone_class);
908910
}
909911

910912
module_init(kone_init);

drivers/hid/hid-roccat-koneplus.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626

2727
static uint profile_numbers[5] = {0, 1, 2, 3, 4};
2828

29-
static struct class *koneplus_class;
30-
3129
static void koneplus_profile_activated(struct koneplus_device *koneplus,
3230
uint new_profile)
3331
{
@@ -356,6 +354,11 @@ static const struct attribute_group *koneplus_groups[] = {
356354
NULL,
357355
};
358356

357+
static const struct class koneplus_class = {
358+
.name = "koneplus",
359+
.dev_groups = koneplus_groups,
360+
};
361+
359362
static int koneplus_init_koneplus_device_struct(struct usb_device *usb_dev,
360363
struct koneplus_device *koneplus)
361364
{
@@ -394,8 +397,8 @@ static int koneplus_init_specials(struct hid_device *hdev)
394397
goto exit_free;
395398
}
396399

397-
retval = roccat_connect(koneplus_class, hdev,
398-
sizeof(struct koneplus_roccat_report));
400+
retval = roccat_connect(&koneplus_class, hdev,
401+
sizeof(struct koneplus_roccat_report));
399402
if (retval < 0) {
400403
hid_err(hdev, "couldn't init char dev\n");
401404
} else {
@@ -549,21 +552,20 @@ static int __init koneplus_init(void)
549552
int retval;
550553

551554
/* class name has to be same as driver name */
552-
koneplus_class = class_create("koneplus");
553-
if (IS_ERR(koneplus_class))
554-
return PTR_ERR(koneplus_class);
555-
koneplus_class->dev_groups = koneplus_groups;
555+
retval = class_register(&koneplus_class);
556+
if (retval)
557+
return retval;
556558

557559
retval = hid_register_driver(&koneplus_driver);
558560
if (retval)
559-
class_destroy(koneplus_class);
561+
class_unregister(&koneplus_class);
560562
return retval;
561563
}
562564

563565
static void __exit koneplus_exit(void)
564566
{
565567
hid_unregister_driver(&koneplus_driver);
566-
class_destroy(koneplus_class);
568+
class_unregister(&koneplus_class);
567569
}
568570

569571
module_init(koneplus_init);

drivers/hid/hid-roccat-konepure.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ struct konepure_mouse_report_button {
3636
uint8_t unknown[2];
3737
} __packed;
3838

39-
static struct class *konepure_class;
40-
4139
ROCCAT_COMMON2_BIN_ATTRIBUTE_W(control, 0x04, 0x03);
4240
ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(actual_profile, 0x05, 0x03);
4341
ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(profile_settings, 0x06, 0x1f);
@@ -72,6 +70,11 @@ static const struct attribute_group *konepure_groups[] = {
7270
NULL,
7371
};
7472

73+
static const struct class konepure_class = {
74+
.name = "konepure",
75+
.dev_groups = konepure_groups,
76+
};
77+
7578
static int konepure_init_specials(struct hid_device *hdev)
7679
{
7780
struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
@@ -98,8 +101,8 @@ static int konepure_init_specials(struct hid_device *hdev)
98101
goto exit_free;
99102
}
100103

101-
retval = roccat_connect(konepure_class, hdev,
102-
sizeof(struct konepure_mouse_report_button));
104+
retval = roccat_connect(&konepure_class, hdev,
105+
sizeof(struct konepure_mouse_report_button));
103106
if (retval < 0) {
104107
hid_err(hdev, "couldn't init char dev\n");
105108
} else {
@@ -207,21 +210,20 @@ static int __init konepure_init(void)
207210
{
208211
int retval;
209212

210-
konepure_class = class_create("konepure");
211-
if (IS_ERR(konepure_class))
212-
return PTR_ERR(konepure_class);
213-
konepure_class->dev_groups = konepure_groups;
213+
retval = class_register(&konepure_class);
214+
if (retval)
215+
return retval;
214216

215217
retval = hid_register_driver(&konepure_driver);
216218
if (retval)
217-
class_destroy(konepure_class);
219+
class_unregister(&konepure_class);
218220
return retval;
219221
}
220222

221223
static void __exit konepure_exit(void)
222224
{
223225
hid_unregister_driver(&konepure_driver);
224-
class_destroy(konepure_class);
226+
class_unregister(&konepure_class);
225227
}
226228

227229
module_init(konepure_init);

drivers/hid/hid-roccat-kovaplus.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424

2525
static uint profile_numbers[5] = {0, 1, 2, 3, 4};
2626

27-
static struct class *kovaplus_class;
28-
2927
static uint kovaplus_convert_event_cpi(uint value)
3028
{
3129
return (value == 7 ? 4 : (value == 4 ? 3 : value));
@@ -409,6 +407,11 @@ static const struct attribute_group *kovaplus_groups[] = {
409407
NULL,
410408
};
411409

410+
static const struct class kovaplus_class = {
411+
.name = "kovaplus",
412+
.dev_groups = kovaplus_groups,
413+
};
414+
412415
static int kovaplus_init_kovaplus_device_struct(struct usb_device *usb_dev,
413416
struct kovaplus_device *kovaplus)
414417
{
@@ -463,8 +466,8 @@ static int kovaplus_init_specials(struct hid_device *hdev)
463466
goto exit_free;
464467
}
465468

466-
retval = roccat_connect(kovaplus_class, hdev,
467-
sizeof(struct kovaplus_roccat_report));
469+
retval = roccat_connect(&kovaplus_class, hdev,
470+
sizeof(struct kovaplus_roccat_report));
468471
if (retval < 0) {
469472
hid_err(hdev, "couldn't init char dev\n");
470473
} else {
@@ -638,21 +641,20 @@ static int __init kovaplus_init(void)
638641
{
639642
int retval;
640643

641-
kovaplus_class = class_create("kovaplus");
642-
if (IS_ERR(kovaplus_class))
643-
return PTR_ERR(kovaplus_class);
644-
kovaplus_class->dev_groups = kovaplus_groups;
644+
retval = class_register(&kovaplus_class);
645+
if (retval)
646+
return retval;
645647

646648
retval = hid_register_driver(&kovaplus_driver);
647649
if (retval)
648-
class_destroy(kovaplus_class);
650+
class_unregister(&kovaplus_class);
649651
return retval;
650652
}
651653

652654
static void __exit kovaplus_exit(void)
653655
{
654656
hid_unregister_driver(&kovaplus_driver);
655-
class_destroy(kovaplus_class);
657+
class_unregister(&kovaplus_class);
656658
}
657659

658660
module_init(kovaplus_init);

0 commit comments

Comments
 (0)