Skip to contentSkip to conversation

ALSA: mark all struct bus_type as const

PATCH Applied Greg Kroah-Hartman 2 participants 2 messages Dec 19, 2023 – Dec 30, 2023 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: mark all struct bus_type as const

Now that the driver core can properly handle constant struct bus_type, move all of the sound subsystem struct bus_type structures as const, placing them into read-only memory which can not be modified at runtime.

Note, this fixes a duplicate definition of ac97_bus_type, which somehow was declared extern in a .h file, and then static as a prototype in a .c file, and then properly later on in the same .c file. Amazing that no compiler warning ever showed up for this.

Cc Jaroslav Kysela <[email protected]>
Cc Takashi Iwai <[email protected]>
Cc Dawei Li <[email protected]>
Cc Yu Liao <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Hans de Goede <[email protected]>
---
 include/sound/ac97_codec.h | 2 +-
 include/sound/hdaudio.h    | 2 +-
 sound/ac97/bus.c           | 2 --
 sound/ac97_bus.c           | 2 +-
 sound/hda/hda_bus_type.c   | 2 +-
 5 files changed, 4 insertions(+), 6 deletions(-)
include/sound/ac97_codec.h +1 -1
index c495c6d5fbe0..4bd3be3a3192 100644
@@ -410,7 +410,7 @@ int snd_ac97_pcm_close(struct ac97_pcm *pcm);
 int snd_ac97_pcm_double_rate_rules(struct snd_pcm_runtime *runtime);
 
 /* ad hoc AC97 device driver access */
-extern struct bus_type ac97_bus_type;
+extern const struct bus_type ac97_bus_type;
 
 /* AC97 platform_data adding function */
 static inline void snd_ac97_dev_add_pdata(struct snd_ac97 *ac97, void *data)
include/sound/hdaudio.h +1 -1
index dd7c87bbc613..1517d752f750 100644
@@ -33,7 +33,7 @@ struct hda_device_id;
 /*
  * exported bus type
  */
-extern struct bus_type snd_hda_bus_type;
+extern const struct bus_type snd_hda_bus_type;
 
 /*
  * generic arrays
sound/ac97/bus.c +0 -2
index 3173e9d98927..1dc7965eb14b 100644
@@ -28,8 +28,6 @@ static DEFINE_MUTEX(ac97_controllers_mutex);
 static DEFINE_IDR(ac97_adapter_idr);
 static LIST_HEAD(ac97_controllers);
 
-static struct bus_type ac97_bus_type;
-
 static inline struct ac97_controller*
 to_ac97_controller(struct device *ac97_adapter)
 {
sound/ac97_bus.c +1 -1
index c7aee8c42c55..7ea274c55900 100644
@@ -75,7 +75,7 @@ int snd_ac97_reset(struct snd_ac97 *ac97, bool try_warm, unsigned int id,
 }
 EXPORT_SYMBOL_GPL(snd_ac97_reset);
 
-struct bus_type ac97_bus_type = {
+const struct bus_type ac97_bus_type = {
 	.name		= "ac97",
 };
 
sound/hda/hda_bus_type.c +1 -1
index 4cd94178df9f..cce2c30511a2 100644
@@ -76,7 +76,7 @@ static int hda_uevent(const struct device *dev, struct kobj_uevent_env *env)
 	return 0;
 }
 
-struct bus_type snd_hda_bus_type = {
+const struct bus_type snd_hda_bus_type = {
 	.name = "hdaudio",
 	.match = hda_bus_match,
 	.uevent = hda_uevent,
Signature · 1 line
2.43.0
Applied
#1 lore raw
Quoted 10 lines · Greg Kroah-Hartman

Now that the driver core can properly handle constant struct bus_type, move all of the sound subsystem struct bus_type structures as const, placing them into read-only memory which can not be modified at runtime.

Note, this fixes a duplicate definition of ac97_bus_type, which somehow was declared extern in a .h file, and then static as a prototype in a .c file, and then properly later on in the same .c file. Amazing that no compiler warning ever showed up for this.

Quoted 8 lines
Cc Jaroslav Kysela <[email protected]>
Cc Takashi Iwai <[email protected]>
Cc Dawei Li <[email protected]>
Cc Yu Liao <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Hans de Goede <[email protected]>

Applied to for-next branch now. Thanks.

Takashi