Skip to contentSkip to conversation

profiles/midi: Fix zero timestampHigh

PATCH Superseded Matthew Cash 2 participants 2 messages Jun 27 Bluetooth drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 profiles/midi: Fix zero timestampHigh

BLE-MIDI timestampHigh can legitimately be zero. The MIDI parser used timestamp_high == 0 to decide whether it had already consumed the packet header, so packets starting with 0x80 0x80 caused the next running-status payload byte to be consumed as another timestamp header.

Track whether timestampHigh has been read separately from its value so packed MIDI events with zero timestampHigh are parsed correctly.

---
 profiles/midi/libmidi.c | 5 ++++-
 profiles/midi/libmidi.h | 2 ++
 2 files changed, 6 insertions(+), 1 deletion(-)
profiles/midi/libmidi.c +4 -1
index 6f2914a8c..ef33f7dfd 100644
@@ -110,6 +110,7 @@ int midi_read_init(struct midi_read_parser *parser)
 	parser->timestamp = 0;
 	parser->timestamp_low = 0;
 	parser->timestamp_high = 0;
+	parser->timestamp_high_set = false;
 
 	parser->sysex_stream.data = malloc(MIDI_SYSEX_MAX_SIZE);
 	if (!parser->sysex_stream.data)
@@ -355,8 +356,10 @@ size_t midi_read_raw(struct midi_read_parser *parser, const uint8_t *data,
 	size_t i = 0;
 	bool err = false;
 
-	if (parser->timestamp_high == 0)
+	if (!parser->timestamp_high_set) {
 		parser->timestamp_high = data[i++] & 0x3F;
+		parser->timestamp_high_set = true;
+	}
 
 	snd_midi_event_reset_encode(parser->midi_ev);
 
profiles/midi/libmidi.h +2 -0
index 41f522dd4..9d314cc11 100644
@@ -83,6 +83,7 @@ struct midi_read_parser {
 	int16_t timestamp;               /* last MIDI-BLE timestamp */
 	int8_t timestamp_low;            /* MIDI-BLE timestampLow from the current packet */
 	int8_t timestamp_high;           /* MIDI-BLE timestampHigh from the current packet */
+	bool timestamp_high_set;         /* timestampHigh read for current packet */
 	struct midi_buffer sysex_stream; /* SysEx stream */
 	snd_midi_event_t *midi_ev;       /* midi<->seq event */
 };
@@ -100,6 +101,7 @@ static inline void midi_read_reset(struct midi_read_parser *parser)
 	parser->rstatus = 0;
 	parser->timestamp_low = 0;
 	parser->timestamp_high = 0;
+	parser->timestamp_high_set = false;
 }
 
 /* Parses raw BLE-MIDI messages and populates a sequencer event representing the
Signature · 1 line
2.54.0
#1 lore raw

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=1117512

---Test result---

Test Summary:

CheckPatch                    FAIL      0.87 seconds
GitLint                       PASS      0.48 seconds
BuildEll                      PASS      20.81 seconds
BluezMake                     PASS      557.39 seconds
MakeCheck                     PASS      1.01 seconds
MakeDistcheck                 PASS      159.80 seconds
CheckValgrind                 PASS      159.07 seconds
CheckSmatch                   PASS      313.75 seconds
bluezmakeextell               PASS      104.20 seconds
IncrementalBuild              PASS      554.95 seconds
ScanBuild                     PASS      991.64 seconds

Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script
Output:
[BlueZ] profiles/midi: Fix zero timestampHigh WARNING:LONG_LINE_COMMENT: line length of 84 exceeds 80 columns #123: FILE: profiles/midi/libmidi.h:86:
+ bool timestamp_high_set; /* timestampHigh read for current packet */

/github/workspace/src/patch/14648381.patch total: 0 errors, 1 warnings, 32 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.

/github/workspace/src/patch/14648381.patch has style problems, please review.

NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.

https://github.com/bluez/bluez/pull/2255

---
Regards,
Linux Bluetooth