Skip to content

Commit 8d0cf15

Browse files
ivanorlov2206tiwai
authored andcommitted
sound: 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: Jaroslav Kysela <[email protected]> Cc: Takashi Iwai <[email protected]> Cc: Ivan Orlov <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: Geoff Levand <[email protected]> Cc: Thierry Reding <[email protected]> Cc: "Uwe Kleine-König" <[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]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent 7ea9ee0 commit 8d0cf15

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

include/sound/core.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ static inline struct device *snd_card_get_device_link(struct snd_card *card)
232232

233233
extern int snd_major;
234234
extern int snd_ecards_limit;
235-
extern struct class *sound_class;
235+
extern const struct class sound_class;
236236
#ifdef CONFIG_SND_DEBUG
237237
extern struct dentry *sound_debugfs_root;
238238
#endif

sound/core/control_led.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ static int __init snd_ctl_led_init(void)
737737
unsigned int group;
738738

739739
device_initialize(&snd_ctl_led_dev);
740-
snd_ctl_led_dev.class = sound_class;
740+
snd_ctl_led_dev.class = &sound_class;
741741
snd_ctl_led_dev.release = snd_ctl_led_dev_release;
742742
dev_set_name(&snd_ctl_led_dev, "ctl-led");
743743
if (device_add(&snd_ctl_led_dev)) {

sound/core/init.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ void snd_device_initialize(struct device *dev, struct snd_card *card)
129129
device_initialize(dev);
130130
if (card)
131131
dev->parent = &card->card_dev;
132-
dev->class = sound_class;
132+
dev->class = &sound_class;
133133
dev->release = default_release;
134134
}
135135
EXPORT_SYMBOL_GPL(snd_device_initialize);
@@ -331,7 +331,7 @@ static int snd_card_init(struct snd_card *card, struct device *parent,
331331

332332
device_initialize(&card->card_dev);
333333
card->card_dev.parent = parent;
334-
card->card_dev.class = sound_class;
334+
card->card_dev.class = &sound_class;
335335
card->card_dev.release = release_card_device;
336336
card->card_dev.groups = card->dev_groups;
337337
card->dev_groups[0] = &card_dev_attr_group;

sound/sound_core.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ static inline int init_oss_soundcore(void) { return 0; }
2323
static inline void cleanup_oss_soundcore(void) { }
2424
#endif
2525

26-
struct class *sound_class;
27-
EXPORT_SYMBOL(sound_class);
28-
2926
MODULE_DESCRIPTION("Core sound module");
3027
MODULE_AUTHOR("Alan Cox");
3128
MODULE_LICENSE("GPL");
@@ -37,6 +34,12 @@ static char *sound_devnode(const struct device *dev, umode_t *mode)
3734
return kasprintf(GFP_KERNEL, "snd/%s", dev_name(dev));
3835
}
3936

37+
const struct class sound_class = {
38+
.name = "sound",
39+
.devnode = sound_devnode,
40+
};
41+
EXPORT_SYMBOL(sound_class);
42+
4043
static int __init init_soundcore(void)
4144
{
4245
int rc;
@@ -45,21 +48,19 @@ static int __init init_soundcore(void)
4548
if (rc)
4649
return rc;
4750

48-
sound_class = class_create("sound");
49-
if (IS_ERR(sound_class)) {
51+
rc = class_register(&sound_class);
52+
if (rc) {
5053
cleanup_oss_soundcore();
51-
return PTR_ERR(sound_class);
54+
return rc;
5255
}
5356

54-
sound_class->devnode = sound_devnode;
55-
5657
return 0;
5758
}
5859

5960
static void __exit cleanup_soundcore(void)
6061
{
6162
cleanup_oss_soundcore();
62-
class_destroy(sound_class);
63+
class_unregister(&sound_class);
6364
}
6465

6566
subsys_initcall(init_soundcore);
@@ -276,7 +277,7 @@ static int sound_insert_unit(struct sound_unit **list, const struct file_operati
276277
}
277278
}
278279

279-
device_create(sound_class, dev, MKDEV(SOUND_MAJOR, s->unit_minor),
280+
device_create(&sound_class, dev, MKDEV(SOUND_MAJOR, s->unit_minor),
280281
NULL, "%s", s->name+6);
281282
return s->unit_minor;
282283

@@ -302,7 +303,7 @@ static void sound_remove_unit(struct sound_unit **list, int unit)
302303
if (!preclaim_oss)
303304
__unregister_chrdev(SOUND_MAJOR, p->unit_minor, 1,
304305
p->name);
305-
device_destroy(sound_class, MKDEV(SOUND_MAJOR, p->unit_minor));
306+
device_destroy(&sound_class, MKDEV(SOUND_MAJOR, p->unit_minor));
306307
kfree(p);
307308
}
308309
}

0 commit comments

Comments
 (0)