diff mbox series

[2/2] midi: Fix random empty timestamp_high value

Message ID 20200619060153.65114-2-tedd.an@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series [1/2] midi: Fix SysEx parser in MIDI plugin | expand

Commit Message

Tedd Ho-Jeong An June 19, 2020, 6:01 a.m. UTC
From: Tedd Ho-Jeong An <tedd.an@intel.com>

The timestamp_high value is assigned from the monotonic time but there
is a chance that the value becomes zero becuase it reads the value
between bit8 and bit13.

This patch makes sure the timestamp_high value get a non-zero value.
---
 profiles/midi/libmidi.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

bluez.test.bot@gmail.com June 19, 2020, 6:09 a.m. UTC | #1
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.
While we are preparing for reviewing the patches, we found the following
issue/warning.

Test Result:
checkpatch Failed

Outputs:
WARNING:TYPO_SPELLING: 'becuase' may be misspelled - perhaps 'because'?
#7: 
is a chance that the value becomes zero becuase it reads the value

- total: 0 errors, 1 warnings, 15 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.

Your patch has style problems, please review.

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

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



---
Regards,
Linux Bluetooth
diff mbox series

Patch

diff --git a/profiles/midi/libmidi.c b/profiles/midi/libmidi.c
index cc5f079e7..fd40b038b 100644
--- a/profiles/midi/libmidi.c
+++ b/profiles/midi/libmidi.c
@@ -77,8 +77,13 @@  inline static void append_timestamp_high_maybe(struct midi_write_parser *parser)
 	if (midi_write_has_data(parser))
 		return;
 
-	parser->rtime = g_get_monotonic_time() / 1000; /* convert µs to ms */
-	timestamp_high |= (parser->rtime & 0x1F80) >> 7;
+	/* Make sure timesampt_high is assigned a non-zero value */
+	do {
+		/* convert µs to ms */
+		parser->rtime = g_get_monotonic_time() / 1000;
+		timestamp_high |= (parser->rtime & 0x1F80) >> 7;
+	} while (timestamp_high == 0x80);
+
 	/* set timestampHigh */
 	buffer_append_byte(&parser->midi_stream, timestamp_high);
 }