midi: Fix random empty timestamp_high value
authorTedd Ho-Jeong An <tedd.an@intel.com>
Fri, 19 Jun 2020 18:34:56 +0000 (11:34 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 12 Apr 2021 09:00:49 +0000 (14:30 +0530)
The timestamp_high value is assigned from the monotonic time but there
is a chance that the value becomes zero because it reads the value
between bit8 and bit13.

This patch makes sure the timestamp_high value get a non-zero value.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
profiles/midi/libmidi.c

index 18506c6..cd25992 100644 (file)
@@ -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);
 }