Re: [PATCH 1/1] ALSA: usb: initial USB Audio Device Class 3.0 support

From: kbuild test robot
Date: Wed Nov 08 2017 - 11:47:29 EST


Hi Ruslan,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on sound/for-next]
[also build test WARNING on v4.14-rc8 next-20171108]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Ruslan-Bilovol/USB-Audio-Device-Class-3-0-support/20171108-235800
base: https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-next
config: mips-allyesconfig (attached as .config)
compiler: mips-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=mips

Note: it may well be a FALSE warning. FWIW you are at least aware of it now.
http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings

All warnings (new ones prefixed by >>):

sound/usb/stream.c: In function 'snd_usb_parse_audio_interface':
>> sound/usb/stream.c:917:8: warning: 'fmt' may be used uninitialized in this function [-Wmaybe-uninitialized]
if (snd_usb_parse_audio_format(chip, fp, format,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fmt, stream) < 0) {
~~~~~~~~~~~~

vim +/fmt +917 sound/usb/stream.c

561
562 int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
563 {
564 struct usb_device *dev;
565 struct usb_interface *iface;
566 struct usb_host_interface *alts;
567 struct usb_interface_descriptor *altsd;
568 int i, altno, err, stream;
569 u64 format = 0;
570 unsigned int num_channels = 0;
571 struct audioformat *fp = NULL;
572 int num, protocol, clock = 0;
573 struct uac_format_type_i_continuous_descriptor *fmt;
574 struct snd_pcm_chmap_elem *chmap_v3 = NULL;
575 unsigned int chconfig;
576
577 dev = chip->dev;
578
579 /* parse the interface's altsettings */
580 iface = usb_ifnum_to_if(dev, iface_no);
581
582 num = iface->num_altsetting;
583
584 /*
585 * Dallas DS4201 workaround: It presents 5 altsettings, but the last
586 * one misses syncpipe, and does not produce any sound.
587 */
588 if (chip->usb_id == USB_ID(0x04fa, 0x4201))
589 num = 4;
590
591 for (i = 0; i < num; i++) {
592 alts = &iface->altsetting[i];
593 altsd = get_iface_desc(alts);
594 protocol = altsd->bInterfaceProtocol;
595 /* skip invalid one */
596 if (((altsd->bInterfaceClass != USB_CLASS_AUDIO ||
597 (altsd->bInterfaceSubClass != USB_SUBCLASS_AUDIOSTREAMING &&
598 altsd->bInterfaceSubClass != USB_SUBCLASS_VENDOR_SPEC)) &&
599 altsd->bInterfaceClass != USB_CLASS_VENDOR_SPEC) ||
600 altsd->bNumEndpoints < 1 ||
601 le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) == 0)
602 continue;
603 /* must be isochronous */
604 if ((get_endpoint(alts, 0)->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) !=
605 USB_ENDPOINT_XFER_ISOC)
606 continue;
607 /* check direction */
608 stream = (get_endpoint(alts, 0)->bEndpointAddress & USB_DIR_IN) ?
609 SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
610 altno = altsd->bAlternateSetting;
611
612 if (snd_usb_apply_interface_quirk(chip, iface_no, altno))
613 continue;
614
615 /*
616 * Roland audio streaming interfaces are marked with protocols
617 * 0/1/2, but are UAC 1 compatible.
618 */
619 if (USB_ID_VENDOR(chip->usb_id) == 0x0582 &&
620 altsd->bInterfaceClass == USB_CLASS_VENDOR_SPEC &&
621 protocol <= 2)
622 protocol = UAC_VERSION_1;
623
624 chconfig = 0;
625 /* get audio formats */
626 switch (protocol) {
627 default:
628 dev_dbg(&dev->dev, "%u:%d: unknown interface protocol %#02x, assuming v1\n",
629 iface_no, altno, protocol);
630 protocol = UAC_VERSION_1;
631 /* fall through */
632
633 case UAC_VERSION_1: {
634 struct uac1_as_header_descriptor *as =
635 snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_AS_GENERAL);
636 struct uac_input_terminal_descriptor *iterm;
637
638 if (!as) {
639 dev_err(&dev->dev,
640 "%u:%d : UAC_AS_GENERAL descriptor not found\n",
641 iface_no, altno);
642 continue;
643 }
644
645 if (as->bLength < sizeof(*as)) {
646 dev_err(&dev->dev,
647 "%u:%d : invalid UAC_AS_GENERAL desc\n",
648 iface_no, altno);
649 continue;
650 }
651
652 format = le16_to_cpu(as->wFormatTag); /* remember the format value */
653
654 iterm = snd_usb_find_input_terminal_descriptor(chip->ctrl_intf,
655 as->bTerminalLink);
656 if (iterm) {
657 num_channels = iterm->bNrChannels;
658 chconfig = le16_to_cpu(iterm->wChannelConfig);
659 }
660
661 break;
662 }
663
664 case UAC_VERSION_2: {
665 struct uac2_input_terminal_descriptor *input_term;
666 struct uac2_output_terminal_descriptor *output_term;
667 struct uac2_as_header_descriptor *as =
668 snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_AS_GENERAL);
669
670 if (!as) {
671 dev_err(&dev->dev,
672 "%u:%d : UAC_AS_GENERAL descriptor not found\n",
673 iface_no, altno);
674 continue;
675 }
676
677 if (as->bLength < sizeof(*as)) {
678 dev_err(&dev->dev,
679 "%u:%d : invalid UAC_AS_GENERAL desc\n",
680 iface_no, altno);
681 continue;
682 }
683
684 num_channels = as->bNrChannels;
685 format = le32_to_cpu(as->bmFormats);
686 chconfig = le32_to_cpu(as->bmChannelConfig);
687
688 /* lookup the terminal associated to this interface
689 * to extract the clock */
690 input_term = snd_usb_find_input_terminal_descriptor(chip->ctrl_intf,
691 as->bTerminalLink);
692 if (input_term) {
693 clock = input_term->bCSourceID;
694 if (!chconfig && (num_channels == input_term->bNrChannels))
695 chconfig = le32_to_cpu(input_term->bmChannelConfig);
696 break;
697 }
698
699 output_term = snd_usb_find_output_terminal_descriptor(chip->ctrl_intf,
700 as->bTerminalLink);
701 if (output_term) {
702 clock = output_term->bCSourceID;
703 break;
704 }
705
706 dev_err(&dev->dev,
707 "%u:%d : bogus bTerminalLink %d\n",
708 iface_no, altno, as->bTerminalLink);
709 continue;
710 }
711
712 case UAC_VERSION_3: {
713 struct uac3_input_terminal_descriptor *input_term;
714 struct uac3_output_terminal_descriptor *output_term;
715 struct uac3_as_header_descriptor *as;
716 struct uac3_cluster_header_descriptor *cluster;
717 struct uac3_hc_descriptor_header hc_header;
718 u16 cluster_id, wLength;
719
720 as = snd_usb_find_csint_desc(alts->extra,
721 alts->extralen,
722 NULL, UAC_AS_GENERAL);
723
724 if (!as) {
725 dev_err(&dev->dev,
726 "%u:%d : UAC_AS_GENERAL descriptor not found\n",
727 iface_no, altno);
728 continue;
729 }
730
731 if (as->bLength < sizeof(*as)) {
732 dev_err(&dev->dev,
733 "%u:%d : invalid UAC_AS_GENERAL desc\n",
734 iface_no, altno);
735 continue;
736 }
737
738 cluster_id = le16_to_cpu(as->wClusterDescrID);
739 if (!cluster_id) {
740 dev_err(&dev->dev,
741 "%u:%d : no cluster descriptor\n",
742 iface_no, altno);
743 continue;
744 }
745
746 /*
747 * Get number of channels and channel map through
748 * High Capability Cluster Descriptor
749 *
750 * First step: get High Capability header and
751 * read size of Cluster Descriptor
752 */
753 err = snd_usb_ctl_msg(chip->dev,
754 usb_rcvctrlpipe(chip->dev, 0),
755 UAC3_CS_REQ_HIGH_CAPABILITY_DESCRIPTOR,
756 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
757 cluster_id,
758 snd_usb_ctrl_intf(chip),
759 &hc_header, sizeof(hc_header));
760 if (err < 0)
761 return err;
762 else if (err != sizeof(hc_header)) {
763 dev_err(&dev->dev,
764 "%u:%d : can't get High Capability descriptor\n",
765 iface_no, altno);
766 return -EIO;
767 }
768
769 /*
770 * Second step: allocate needed amount of memory
771 * and request Cluster Descriptor
772 */
773 wLength = le16_to_cpu(hc_header.wLength);
774 cluster = kzalloc(wLength, GFP_KERNEL);
775 if (!cluster)
776 return -ENOMEM;
777 err = snd_usb_ctl_msg(chip->dev,
778 usb_rcvctrlpipe(chip->dev, 0),
779 UAC3_CS_REQ_HIGH_CAPABILITY_DESCRIPTOR,
780 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
781 cluster_id,
782 snd_usb_ctrl_intf(chip),
783 cluster, wLength);
784 if (err < 0) {
785 kfree(cluster);
786 return err;
787 } else if (err != wLength) {
788 dev_err(&dev->dev,
789 "%u:%d : can't get Cluster Descriptor\n",
790 iface_no, altno);
791 kfree(cluster);
792 return -EIO;
793 }
794
795 num_channels = cluster->bNrChannels;
796 chmap_v3 = convert_chmap_v3(cluster);
797
798 kfree(cluster);
799
800 format = le64_to_cpu(as->bmFormats);
801
802 /* lookup the terminal associated to this interface
803 * to extract the clock */
804 input_term = snd_usb_find_input_terminal_descriptor(
805 chip->ctrl_intf,
806 as->bTerminalLink);
807
808 if (input_term) {
809 clock = input_term->bCSourceID;
810 break;
811 }
812
813 output_term = snd_usb_find_output_terminal_descriptor(chip->ctrl_intf,
814 as->bTerminalLink);
815 if (output_term) {
816 clock = output_term->bCSourceID;
817 break;
818 }
819
820 dev_err(&dev->dev,
821 "%u:%d : bogus bTerminalLink %d\n",
822 iface_no, altno, as->bTerminalLink);
823 continue;
824 }
825 }
826
827 if (protocol == UAC_VERSION_1 || protocol == UAC_VERSION_2) {
828 /* get format type */
829 fmt = snd_usb_find_csint_desc(alts->extra,
830 alts->extralen,
831 NULL, UAC_FORMAT_TYPE);
832 if (!fmt) {
833 dev_err(&dev->dev,
834 "%u:%d : no UAC_FORMAT_TYPE desc\n",
835 iface_no, altno);
836 continue;
837 }
838 if (((protocol == UAC_VERSION_1) && (fmt->bLength < 8))
839 || ((protocol == UAC_VERSION_2) &&
840 (fmt->bLength < 6))) {
841 dev_err(&dev->dev,
842 "%u:%d : invalid UAC_FORMAT_TYPE desc\n",
843 iface_no, altno);
844 continue;
845 }
846
847 /*
848 * Blue Microphones workaround: The last altsetting is
849 * identical with the previous one, except for a larger
850 * packet size, but is actually a mislabeled two-channel
851 * setting; ignore it.
852 */
853 if (fmt->bNrChannels == 1 &&
854 fmt->bSubframeSize == 2 &&
855 altno == 2 && num == 3 &&
856 fp && fp->altsetting == 1 && fp->channels == 1 &&
857 fp->formats == SNDRV_PCM_FMTBIT_S16_LE &&
858 protocol == UAC_VERSION_1 &&
859 le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) ==
860 fp->maxpacksize * 2)
861 continue;
862 }
863
864 fp = kzalloc(sizeof(*fp), GFP_KERNEL);
865 if (!fp)
866 return -ENOMEM;
867
868 fp->iface = iface_no;
869 fp->altsetting = altno;
870 fp->altset_idx = i;
871 fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress;
872 fp->ep_attr = get_endpoint(alts, 0)->bmAttributes;
873 fp->datainterval = snd_usb_parse_datainterval(chip, alts);
874 fp->protocol = protocol;
875 fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
876 fp->channels = num_channels;
877 if (snd_usb_get_speed(dev) == USB_SPEED_HIGH)
878 fp->maxpacksize = (((fp->maxpacksize >> 11) & 3) + 1)
879 * (fp->maxpacksize & 0x7ff);
880 fp->attributes = parse_uac_endpoint_attributes(chip, alts, protocol, iface_no);
881 fp->clock = clock;
882 INIT_LIST_HEAD(&fp->list);
883
884 /* some quirks for attributes here */
885
886 switch (chip->usb_id) {
887 case USB_ID(0x0a92, 0x0053): /* AudioTrak Optoplay */
888 /* Optoplay sets the sample rate attribute although
889 * it seems not supporting it in fact.
890 */
891 fp->attributes &= ~UAC_EP_CS_ATTR_SAMPLE_RATE;
892 break;
893 case USB_ID(0x041e, 0x3020): /* Creative SB Audigy 2 NX */
894 case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
895 /* doesn't set the sample rate attribute, but supports it */
896 fp->attributes |= UAC_EP_CS_ATTR_SAMPLE_RATE;
897 break;
898 case USB_ID(0x0763, 0x2001): /* M-Audio Quattro USB */
899 case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro USB */
900 case USB_ID(0x047f, 0x0ca1): /* plantronics headset */
901 case USB_ID(0x077d, 0x07af): /* Griffin iMic (note that there is
902 an older model 77d:223) */
903 /*
904 * plantronics headset and Griffin iMic have set adaptive-in
905 * although it's really not...
906 */
907 fp->ep_attr &= ~USB_ENDPOINT_SYNCTYPE;
908 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
909 fp->ep_attr |= USB_ENDPOINT_SYNC_ADAPTIVE;
910 else
911 fp->ep_attr |= USB_ENDPOINT_SYNC_SYNC;
912 break;
913 }
914
915 /* ok, let's parse further... */
916 if (protocol == UAC_VERSION_1 || protocol == UAC_VERSION_2) {
> 917 if (snd_usb_parse_audio_format(chip, fp, format,
918 fmt, stream) < 0) {
919 kfree(fp->rate_table);
920 kfree(fp);
921 fp = NULL;
922 continue;
923 }
924 } else {
925 struct uac3_as_header_descriptor *as;
926
927 as = snd_usb_find_csint_desc(alts->extra,
928 alts->extralen,
929 NULL, UAC_AS_GENERAL);
930
931 if (snd_usb_parse_audio_format_v3(chip, fp, as,
932 stream) < 0) {
933 kfree(fp->rate_table);
934 kfree(fp);
935 fp = NULL;
936 continue;
937 }
938 }
939
940 /* Create chmap */
941 if (fp->channels != num_channels)
942 chconfig = 0;
943
944 if (protocol == UAC_VERSION_3)
945 fp->chmap = chmap_v3;
946 else
947 fp->chmap = convert_chmap(fp->channels, chconfig,
948 protocol);
949
950 dev_dbg(&dev->dev, "%u:%d: add audio endpoint %#x\n", iface_no, altno, fp->endpoint);
951 err = snd_usb_add_audio_stream(chip, stream, fp);
952 if (err < 0) {
953 list_del(&fp->list); /* unlink for avoiding double-free */
954 kfree(fp->rate_table);
955 kfree(fp->chmap);
956 kfree(fp);
957 return err;
958 }
959 /* try to set the interface... */
960 usb_set_interface(chip->dev, iface_no, altno);
961 snd_usb_init_pitch(chip, iface_no, alts, fp);
962 snd_usb_init_sample_rate(chip, iface_no, alts, fp, fp->rate_max);
963 }
964 return 0;
965 }
966

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

Attachment: .config.gz
Description: application/gzip