[bug report] ALSA: ump: Add legacy raw MIDI support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Takashi Iwai,

The patch 0b5288f5fe63: "ALSA: ump: Add legacy raw MIDI support" from
May 23, 2023, leads to the following Smatch static checker warning:

	sound/core/ump_convert.c:460 do_convert_to_ump()
	warn: right shifting more than type allows 8 vs 8

sound/core/ump_convert.c
    419 static int do_convert_to_ump(struct snd_ump_endpoint *ump,
    420                              unsigned char group, unsigned char c, u32 *data)
    421 {
    422         /* bytes for 0x80-0xf0 */
    423         static unsigned char cmd_bytes[8] = {
    424                 3, 3, 3, 3, 2, 2, 3, 0
    425         };
    426         /* bytes for 0xf0-0xff */
    427         static unsigned char system_bytes[16] = {
    428                 0, 2, 3, 2, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1
    429         };
    430         struct ump_cvt_to_ump *cvt = &ump->out_cvts[group];
    431         unsigned char bytes;
    432 
    433         if (c == UMP_MIDI1_MSG_SYSEX_START) {
    434                 cvt->in_sysex = 1;
    435                 cvt->len = 0;
    436                 return 0;
    437         }
    438         if (c == UMP_MIDI1_MSG_SYSEX_END) {
    439                 if (!cvt->in_sysex)
    440                         return 0; /* skip */
    441                 return cvt_legacy_sysex_to_ump(cvt, group, data, true);
    442         }
    443 
    444         if ((c & 0xf0) == UMP_MIDI1_MSG_REALTIME) {
    445                 bytes = system_bytes[c & 0x0f];
    446                 if (!bytes)
    447                         return 0; /* skip */
    448                 if (bytes == 1) {
    449                         data[0] = ump_compose(UMP_MSG_TYPE_SYSTEM, group, 0, c);
    450                         return 4;
    451                 }
    452                 cvt->buf[0] = c;
    453                 cvt->len = 1;
    454                 cvt->cmd_bytes = bytes;
    455                 cvt->in_sysex = 0; /* abort SysEx */
    456                 return 0;
    457         }
    458 
    459         if (c & 0x80) {
--> 460                 bytes = cmd_bytes[(c >> 8) & 7];
                                           ^^^^^^
Based on the if statement, it looks like c >> 4 was intended.

    461                 cvt->buf[0] = c;
    462                 cvt->len = 1;
    463                 cvt->cmd_bytes = bytes;
    464                 cvt->in_sysex = 0; /* abort SysEx */
    465                 return 0;
    466         }
    467 
    468         if (cvt->in_sysex) {
    469                 cvt->buf[cvt->len++] = c;
    470                 if (cvt->len == 6)
    471                         return cvt_legacy_sysex_to_ump(cvt, group, data, false);
    472                 return 0;
    473         }
    474 
    475         if (!cvt->len)
    476                 return 0;
    477 
    478         cvt->buf[cvt->len++] = c;
    479         if (cvt->len < cvt->cmd_bytes)
    480                 return 0;
    481         cvt->len = 1;
    482         if ((cvt->buf[0] & 0xf0) == UMP_MIDI1_MSG_REALTIME)
    483                 return cvt_legacy_system_to_ump(cvt, group, data);
    484         return cvt_legacy_cmd_to_ump(ump, cvt, group, data, cvt->cmd_bytes);
    485 }

regards,
dan carpenter



[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Pulse Audio]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux