[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:343 cvt_legacy_cmd_to_ump()
	warn: duplicate check 'buf[2]' (previous on line 333)

sound/core/ump_convert.c
    305 static int cvt_legacy_cmd_to_ump(struct snd_ump_endpoint *ump,
    306                                  struct ump_cvt_to_ump *cvt,
    307                                  unsigned char group, u32 *data,
    308                                  unsigned char bytes)
    309 {
    310         const unsigned char *buf = cvt->buf;
    311         struct ump_cvt_to_ump_bank *cc;
    312         union snd_ump_midi2_msg *midi2 = (union snd_ump_midi2_msg *)data;
    313         unsigned char status, channel;
    314 
    315         BUILD_BUG_ON(sizeof(union snd_ump_midi1_msg) != 4);
    316         BUILD_BUG_ON(sizeof(union snd_ump_midi2_msg) != 8);
    317 
    318         /* for MIDI 1.0 UMP, it's easy, just pack it into UMP */
    319         if (ump->info.protocol & SNDRV_UMP_EP_INFO_PROTO_MIDI1) {
    320                 data[0] = ump_compose(UMP_MSG_TYPE_MIDI1_CHANNEL_VOICE,
    321                                       group, 0, buf[0]);
    322                 data[0] |= buf[1] << 8;
    323                 if (bytes > 2)
    324                         data[0] |= buf[2];
    325                 return 4;
    326         }
    327 
    328         status = *buf >> 4;
    329         channel = *buf & 0x0f;
    330         cc = &cvt->bank[channel];
    331 
    332         /* special handling: treat note-on with 0 velocity as note-off */
    333         if (status == UMP_MSG_STATUS_NOTE_ON && !buf[2])
    334                 status = UMP_MSG_STATUS_NOTE_OFF;

This if statment

    335 
    336         /* initialize the packet */
    337         data[0] = ump_compose(UMP_MSG_TYPE_MIDI2_CHANNEL_VOICE,
    338                               group, status, channel);
    339         data[1] = 0;
    340 
    341         switch (status) {
    342         case UMP_MSG_STATUS_NOTE_ON:
--> 343                 if (!buf[2])
    344                         status = UMP_MSG_STATUS_NOTE_OFF;

and this one are the same.  One could be deleted.

    345                 fallthrough;
    346         case UMP_MSG_STATUS_NOTE_OFF:
    347                 midi2->note.note = buf[1];
    348                 midi2->note.velocity = upscale_7_to_16bit(buf[2]);
    349                 break;
    350         case UMP_MSG_STATUS_POLY_PRESSURE:
    351                 midi2->paf.note = buf[1];
    352                 midi2->paf.data = upscale_7_to_32bit(buf[2]);
    353                 break;
    354         case UMP_MSG_STATUS_CC:
    355                 switch (buf[1]) {
    356                 case UMP_CC_RPN_MSB:
    357                         cc->rpn_set = 1;
    358                         cc->cc_rpn_msb = buf[2];
    359                         return 0; // skip
    360                 case UMP_CC_RPN_LSB:
    361                         cc->rpn_set = 1;
    362                         cc->cc_rpn_lsb = buf[2];
    363                         return 0; // skip
    364                 case UMP_CC_NRPN_MSB:
    365                         cc->nrpn_set = 1;
    366                         cc->cc_nrpn_msb = buf[2];
    367                         return 0; // skip
    368                 case UMP_CC_NRPN_LSB:
    369                         cc->nrpn_set = 1;
    370                         cc->cc_nrpn_lsb = buf[2];
    371                         return 0; // skip
    372                 case UMP_CC_DATA:
    373                         cc->cc_data_msb = buf[2];
    374                         return 0; // skip
    375                 case UMP_CC_BANK_SELECT:
    376                         cc->bank_set = 1;
    377                         cc->cc_bank_msb = buf[2];
    378                         return 0; // skip
    379                 case UMP_CC_BANK_SELECT_LSB:
    380                         cc->bank_set = 1;
    381                         cc->cc_bank_lsb = buf[2];
    382                         return 0; // skip
    383                 case UMP_CC_DATA_LSB:
    384                         cc->cc_data_lsb = buf[2];
    385                         if (cc->rpn_set || cc->nrpn_set)
    386                                 fill_rpn(cc, midi2);
    387                         else
    388                                 return 0; // skip
    389                         break;
    390                 default:
    391                         midi2->cc.index = buf[1];
    392                         midi2->cc.data = upscale_7_to_32bit(buf[2]);
    393                         break;
    394                 }
    395                 break;
    396         case UMP_MSG_STATUS_PROGRAM:
    397                 midi2->pg.program = buf[1];
    398                 if (cc->bank_set) {
    399                         midi2->pg.bank_valid = 1;
    400                         midi2->pg.bank_msb = cc->cc_bank_msb;
    401                         midi2->pg.bank_lsb = cc->cc_bank_lsb;
    402                         cc->bank_set = 0;
    403                         cc->cc_bank_msb = cc->cc_bank_lsb = 0;
    404                 }
    405                 break;
    406         case UMP_MSG_STATUS_CHANNEL_PRESSURE:
    407                 midi2->caf.data = upscale_7_to_32bit(buf[1]);
    408                 break;
    409         case UMP_MSG_STATUS_PITCH_BEND:
    410                 midi2->pb.data = upscale_14_to_32bit(buf[1] | (buf[2] << 7));
    411                 break;
    412         default:
    413                 return 0;
    414         }
    415 
    416         return 8;
    417 }

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