git: 8f8b8e4af91d - main - sound: Fix revents in midi_poll()

From: Christos Margiolis <christos_at_FreeBSD.org>
Date: Mon, 24 Nov 2025 13:35:37 UTC
The branch main has been updated by christos:

URL: https://cgit.FreeBSD.org/src/commit/?id=8f8b8e4af91d4e158caf6ba4b728482311bfc7c3

commit 8f8b8e4af91d4e158caf6ba4b728482311bfc7c3
Author:     Nicolas Provost <dev@nicolas-provost.fr>
AuthorDate: 2025-11-24 13:35:08 +0000
Commit:     Christos Margiolis <christos@FreeBSD.org>
CommitDate: 2025-11-24 13:35:08 +0000

    sound: Fix revents in midi_poll()
    
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Reviewed by:    christos
    Pull Request:   https://github.com/freebsd/freebsd-src/pull/1887
---
 sys/dev/sound/midi/midi.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/sys/dev/sound/midi/midi.c b/sys/dev/sound/midi/midi.c
index e14a28557406..cca7b93abf5f 100644
--- a/sys/dev/sound/midi/midi.c
+++ b/sys/dev/sound/midi/midi.c
@@ -658,21 +658,19 @@ midi_poll(struct cdev *i_dev, int events, struct thread *td)
 	mtx_lock(&m->lock);
 	mtx_lock(&m->qlock);
 
-	if (events & (POLLIN | POLLRDNORM))
+	if (events & (POLLIN | POLLRDNORM)) {
 		if (!MIDIQ_EMPTY(m->inq))
-			events |= events & (POLLIN | POLLRDNORM);
-
-	if (events & (POLLOUT | POLLWRNORM))
-		if (MIDIQ_AVAIL(m->outq) < m->hiwat)
-			events |= events & (POLLOUT | POLLWRNORM);
-
-	if (revents == 0) {
-		if (events & (POLLIN | POLLRDNORM))
+			revents |= events & (POLLIN | POLLRDNORM);
+		else
 			selrecord(td, &m->rsel);
-
-		if (events & (POLLOUT | POLLWRNORM))
+	}
+	if (events & (POLLOUT | POLLWRNORM)) {
+		if (MIDIQ_AVAIL(m->outq) < m->hiwat)
+			revents |= events & (POLLOUT | POLLWRNORM);
+		else
 			selrecord(td, &m->wsel);
 	}
+
 	mtx_unlock(&m->lock);
 	mtx_unlock(&m->qlock);