All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
To: clemens@ladisch.de, tiwai@suse.de
Cc: alsa-devel@alsa-project.org
Subject: [PATCH 5/5] ALSA: firewire-tascam: clear extra MIDI bytes in an asynchronous transaction
Date: Tue, 20 Oct 2015 23:46:59 +0900	[thread overview]
Message-ID: <1445352419-21827-6-git-send-email-o-takashi@sakamocchi.jp> (raw)
In-Reply-To: <1445352419-21827-1-git-send-email-o-takashi@sakamocchi.jp>

When MIDI buffer stores two or more MIDI messages, TASCAM driver
transfers asynchronous transactions including one MIDI message and
extra bytes from second MIDI message.

This commit fixes this bug by clearing needless bytes in the buffer. The
consumed bytes are already calculated correctly, thus the sequence of
transactions is already correct.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 sound/firewire/tascam/tascam-transaction.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/sound/firewire/tascam/tascam-transaction.c b/sound/firewire/tascam/tascam-transaction.c
index 99098aa..904ce03 100644
--- a/sound/firewire/tascam/tascam-transaction.c
+++ b/sound/firewire/tascam/tascam-transaction.c
@@ -93,8 +93,10 @@ static int fill_message(struct snd_rawmidi_substream *substream, u8 *buf)
 			*label = (port << 4) | 0x04;
 		/* We need to fill whole 3 bytes. Go to next change. */
 		} else {
-			consume = 0;
+			return 0;
 		}
+
+		len = consume;
 	} else {
 		/* The beginning of exclusives. */
 		if (msg[0] == 0xf0) {
@@ -115,24 +117,30 @@ static int fill_message(struct snd_rawmidi_substream *substream, u8 *buf)
 
 			/* On running-status. */
 			if ((msg[0] & 0x80) != 0x80) {
+				/* Enough MIDI bytes were not retrieved. */
+				if (consume < len - 1)
+					return 0;
+				consume = len - 1;
+
 				msg[2] = msg[1];
 				msg[1] = msg[0];
 				msg[0] = tscm->running_status[port];
-				consume--;
 			} else {
+				/* Enough MIDI bytes were not retrieved. */
+				if (consume < len)
+					return 0;
+				consume = len;
+
 				tscm->running_status[port] = msg[0];
 			}
-
-			/* Confirm length. */
-			if (consume < len)
-				return 0;
-			if (consume > len)
-				consume = len;
 		}
 
 		*label = (port << 4) | (msg[0] >> 4);
 	}
 
+	if (len > 0 && len < 3)
+		memset(msg + len, 0, 3 - len);
+
 	return consume;
 }
 
-- 
2.1.4

  parent reply	other threads:[~2015-10-20 14:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-20 14:46 [PATCH 0/5 v2] ALSA: firewire-tascam: fix sending the same MIDI bytes in two transactions Takashi Sakamoto
2015-10-20 14:46 ` [PATCH 1/5] ALSA: firewire-tascam: remove buffer initialization in driver side Takashi Sakamoto
2015-10-20 14:46 ` [PATCH 2/5] ALSA: firewire-tascam: change type of valiables according to function prototype Takashi Sakamoto
2015-10-20 14:46 ` [PATCH 3/5] ALSA: firewire-tascam: use better name for local variables to describe their intension Takashi Sakamoto
2015-10-20 14:46 ` [PATCH 4/5] ALSA: firewire-tascam: fix loop condition with some readable variables Takashi Sakamoto
2015-10-20 14:46 ` Takashi Sakamoto [this message]
2015-10-20 18:11 ` [PATCH 0/5 v2] ALSA: firewire-tascam: fix sending the same MIDI bytes in two transactions Takashi Iwai
2015-10-20 22:46   ` Takashi Sakamoto

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1445352419-21827-6-git-send-email-o-takashi@sakamocchi.jp \
    --to=o-takashi@sakamocchi.jp \
    --cc=alsa-devel@alsa-project.org \
    --cc=clemens@ladisch.de \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.