Skip to contentSkip to conversation

ALSA: Use priority list for managing device list

PATCH New Takashi Iwai 1 participant 2 messages Feb 24, 2014 Sound

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 ALSA: Use priority list for managing device list

Basically, the device type specifies the priority of the device to be registered / freed, too. However, the priority value isn't well utilized but only it's checked as a group. This results in inconsistent register and free order (where each of them should be in reversed direction).

This patch simplifies the device list management code by simply inserting a list entry at creation time in an incremental order for the priority value. Since we can just follow the link for register, disconnect and free calls, we don't have to specify the group; so the whole enum definitions are also simplified as well.

The visible change to outside is that the priorities of some object types are revisited. For example, now the SNDRV_DEV_LOWLEVEL object is registered before others (control, PCM, etc) and, in return, released after others. Similarly, SNDRV_DEV_CODEC is in a lower priority than SNDRV_DEV_BUS for ensuring the dependency.

Also, the unused SNDRV_DEV_TOPLEVEL, SNDRV_DEV_LOWLEVEL_PRE and SNDRV_DEV_LOWLEVEL_NORMAL are removed as a cleanup.

---
 include/sound/core.h | 28 ++++++++--------------
 sound/core/device.c  | 66 +++++++++++++++++++++++++++++-----------------------
 sound/core/init.c    | 14 +++--------
 3 files changed, 50 insertions(+), 58 deletions(-)
include/sound/core.h +10 -18
index a3e3e89b63b6..5927378dc692 100644
@@ -46,24 +46,22 @@ struct completion;
 
 /* device allocation stuff */
 
-#define SNDRV_DEV_TYPE_RANGE_SIZE		0x1000
-
+/* type of the object used in snd_device_*()
+ * this also defines the calling order
+ */
 enum snd_device_type {
-	SNDRV_DEV_TOPLEVEL	= 0,
-	SNDRV_DEV_CONTROL	= 1,
-	SNDRV_DEV_LOWLEVEL_PRE	= 2,
-	SNDRV_DEV_LOWLEVEL_NORMAL = 0x1000,
+	SNDRV_DEV_LOWLEVEL,
+	SNDRV_DEV_CONTROL,
+	SNDRV_DEV_INFO,
+	SNDRV_DEV_BUS,
+	SNDRV_DEV_CODEC,
 	SNDRV_DEV_PCM,
+	SNDRV_DEV_COMPRESS,
 	SNDRV_DEV_RAWMIDI,
 	SNDRV_DEV_TIMER,
 	SNDRV_DEV_SEQUENCER,
 	SNDRV_DEV_HWDEP,
-	SNDRV_DEV_INFO,
-	SNDRV_DEV_BUS,
-	SNDRV_DEV_CODEC,
 	SNDRV_DEV_JACK,
-	SNDRV_DEV_COMPRESS,
-	SNDRV_DEV_LOWLEVEL	= 0x2000,
 };
 
 enum snd_device_state {
@@ -72,12 +70,6 @@ enum snd_device_state {
 	SNDRV_DEV_DISCONNECTED,
 };
 
-enum snd_device_cmd {
-	SNDRV_DEV_CMD_PRE,
-	SNDRV_DEV_CMD_NORMAL,
-	SNDRV_DEV_CMD_POST,
-};
-
 struct snd_device;
 
 struct snd_device_ops {
@@ -321,7 +313,7 @@ int snd_device_register_all(struct snd_card *card);
 int snd_device_disconnect(struct snd_card *card, void *device_data);
 int snd_device_disconnect_all(struct snd_card *card);
 int snd_device_free(struct snd_card *card, void *device_data);
-int snd_device_free_all(struct snd_card *card, enum snd_device_cmd cmd);
+int snd_device_free_all(struct snd_card *card);
 
 /* isadma.c */
 
sound/core/device.c +37 -29

132 lines not on this page · raw message

sound/core/init.c +3 -11
index b7085eb19079..9e7f17b72fb6 100644
@@ -266,7 +266,7 @@ int snd_card_new(struct device *parent, int idx, const char *xid,
 	return 0;
 
       __error_ctl:
-	snd_device_free_all(card, SNDRV_DEV_CMD_PRE);
+	snd_device_free_all(card);
       __error:
 	put_device(&card->card_dev);
   	return err;
@@ -454,16 +454,8 @@ static int snd_card_do_free(struct snd_card *card)
 	if (snd_mixer_oss_notify_callback)
 		snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_FREE);
 #endif
-	if (snd_device_free_all(card, SNDRV_DEV_CMD_PRE) < 0) {
-		dev_err(card->dev, "unable to free all devices (pre)\n");
-		/* Fatal, but this situation should never occur */
-	}
-	if (snd_device_free_all(card, SNDRV_DEV_CMD_NORMAL) < 0) {
-		dev_err(card->dev, "unable to free all devices (normal)\n");
-		/* Fatal, but this situation should never occur */
-	}
-	if (snd_device_free_all(card, SNDRV_DEV_CMD_POST) < 0) {
-		dev_err(card->dev, "unable to free all devices (post)\n");
+	if (snd_device_free_all(card) < 0) {
+		dev_err(card->dev, "unable to free all devices\n");
 		/* Fatal, but this situation should never occur */
 	}
 	if (card->private_free)
Signature · 1 line
1.8.5.2
#1 lore raw

PATCH v2 2/2 ALSA: Clean up snd_device_*() codes

A few code cleanups and optimizations. In addition, drop snd_device_disconnect() that isn't used at all, and drop the return values from snd_device_free*().

Another slight difference by this change is that now the device state will become always SNDRV_DEV_REGISTERED no matter whether dev_register ops is present or not. It's for better consistency. There should be no impact for the current tree, as the state isn't checked.

---
 include/sound/core.h |   5 +-
 sound/core/device.c  | 128 ++++++++++++++++++++-------------------------------
 sound/core/init.c    |   5 +-
 3 files changed, 52 insertions(+), 86 deletions(-)
include/sound/core.h +2 -3
index 5927378dc692..8508c20ee420 100644
@@ -310,10 +310,9 @@ int snd_device_new(struct snd_card *card, enum snd_device_type type,
 		   void *device_data, struct snd_device_ops *ops);
 int snd_device_register(struct snd_card *card, void *device_data);
 int snd_device_register_all(struct snd_card *card);
-int snd_device_disconnect(struct snd_card *card, void *device_data);
 int snd_device_disconnect_all(struct snd_card *card);
-int snd_device_free(struct snd_card *card, void *device_data);
-int snd_device_free_all(struct snd_card *card);
+void snd_device_free(struct snd_card *card, void *device_data);
+void snd_device_free_all(struct snd_card *card);
 
 /* isadma.c */
 
sound/core/device.c +49 -79

182 lines not on this page · raw message

sound/core/init.c +1 -4
index 9e7f17b72fb6..5ee83845c5de 100644
@@ -454,10 +454,7 @@ static int snd_card_do_free(struct snd_card *card)
 	if (snd_mixer_oss_notify_callback)
 		snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_FREE);
 #endif
-	if (snd_device_free_all(card) < 0) {
-		dev_err(card->dev, "unable to free all devices\n");
-		/* Fatal, but this situation should never occur */
-	}
+	snd_device_free_all(card);
 	if (card->private_free)
 		card->private_free(card);
 	snd_info_free_entry(card->proc_id);
Signature · 1 line
1.8.5.2