git: 142aca25b07c - main - sound: Sort channels by unit number as well

From: Christos Margiolis <christos_at_FreeBSD.org>
Date: Fri, 18 Oct 2024 08:44:52 UTC
The branch main has been updated by christos:

URL: https://cgit.FreeBSD.org/src/commit/?id=142aca25b07c9a7067d8040ea98812c54b253bbf

commit 142aca25b07c9a7067d8040ea98812c54b253bbf
Author:     Christos Margiolis <christos@FreeBSD.org>
AuthorDate: 2024-10-18 08:39:00 +0000
Commit:     Christos Margiolis <christos@FreeBSD.org>
CommitDate: 2024-10-18 08:39:00 +0000

    sound: Sort channels by unit number as well
    
    Refactor CHN_INSERT_SORT() to also take into account the unit number of
    each channel, while still prioritizing the type, to make the channel
    list easier to work with.
    
    Sponsored by:   The FreeBSD Foundation
    MFC after:      2 days
    Reviewed by:    dev_submerge.ch
    Differential Revision:  https://reviews.freebsd.org/D46549
---
 sys/dev/sound/pcm/channel.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/sys/dev/sound/pcm/channel.h b/sys/dev/sound/pcm/channel.h
index 445882a62f0a..d146f51120d8 100644
--- a/sys/dev/sound/pcm/channel.h
+++ b/sys/dev/sound/pcm/channel.h
@@ -225,7 +225,8 @@ struct pcm_channel {
 #define CHN_INSERT_SORT(w, x, y, z)		do {			\
 	struct pcm_channel *t, *a = NULL;				\
 	CHN_FOREACH(t, x, z) {						\
-		if ((y)->type w t->type)				\
+		if (((y)->type w t->type) ||				\
+		    (((y)->type == t->type) && ((y)->unit w t->unit)))	\
 			a = t;						\
 		else							\
 			break;						\
@@ -236,7 +237,7 @@ struct pcm_channel {
 		CHN_INSERT_HEAD(x, y, z);				\
 } while (0)
 
-#define CHN_INSERT_SORT_ASCEND(x, y, z)		CHN_INSERT_SORT(>=, x, y, z)
+#define CHN_INSERT_SORT_ASCEND(x, y, z)		CHN_INSERT_SORT(>, x, y, z)
 #define CHN_INSERT_SORT_DESCEND(x, y, z)	CHN_INSERT_SORT(<, x, y, z)
 
 #define CHN_BUF_PARENT(x, y)						\