From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: AIpwx49HOuKjNfcLFc2K1fpev2OWJs8rz1/aEtRKaTIk4DY1+wqIF9rKeuFErmkVIxrFHnCqsHu5 ARC-Seal: i=1; a=rsa-sha256; t=1524133157; cv=none; d=google.com; s=arc-20160816; b=W4WzAanhaoPLW/lttSr102Sif/YMhet+y6G3ZRpIXeTCT3NUKuD27WNceXvML6j/Py 7RJUeI3s9mqfKMBhw0S9ADD8yFRDWbJ5C5M55mpPqT4aXamqaFHGEMa0gZA1RP2GA4OC YB9TOepBP0z1Mrj9BcIbvzrA/3h1XniK1IbBnbnb8lr9NDDdfq0cq9+8LDCWYXle0VpC NiTn971ad08Ya9DR9k4a9B0qSIqtajuxNFHGJWjjnpRpiMXwTRxRixu8ebQBFrbjAWTH TGZciLgFgs3OQaHgKX063otsdpE5oFMtsVyuuhTWi9iuBPXJY5ZTrnRoadh2QXn/jWpf gEzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:references:in-reply-to:subject:cc:to:from :message-id:date:arc-authentication-results; bh=MoMHwtBopEkJ2xR1X2d6gN7DCagCo0O6IofSb+0nuRk=; b=0kKjq0uEObHfNLMNTAriWaYR9YPs3wPdrKo5lx4D2MuNLHmgWdTNh0sqiTKJC3hnOJ Dq2B8ZELnyMfQ1565atmIyv+s5EtvX6JRWTgh/n9bZhHFnBQ673tqdCDXvWYQAZVQ3gT zolDHWdaUc1QGuQVLzMUMzxfisg6h2rW0c2TFMgzMzRa9m8UuNd93J6D2I4R3prOeZEz JkmypMt/BiOyCXg2PiaXcAw6feoJnxKumQLYbWxAOeRzwpYTgL7yxKL9nvzZgJYjzKYD H/9kUC3jCPqX81gkPIztkRC9/31aLDXLx+BHmMXbO+h3Rwk5jwQm1Rk0yzwfP3oYi2kP sCxQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of tiwai@suse.de designates 195.135.220.15 as permitted sender) smtp.mailfrom=tiwai@suse.de Authentication-Results: mx.google.com; spf=pass (google.com: domain of tiwai@suse.de designates 195.135.220.15 as permitted sender) smtp.mailfrom=tiwai@suse.de Date: Thu, 19 Apr 2018 12:19:15 +0200 Message-ID: From: Takashi Iwai To: Ruslan Bilovol Cc: Jorge , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: Re: [alsa-devel] [PATCH 4/4] ALSA: usb: add UAC3 BADD profiles support In-Reply-To: <1523658266-2259-5-git-send-email-ruslan.bilovol@gmail.com> References: <1523658266-2259-1-git-send-email-ruslan.bilovol@gmail.com> <1523658266-2259-5-git-send-email-ruslan.bilovol@gmail.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: =?utf-8?q?1597671512160670217?= X-GMAIL-MSGID: =?utf-8?q?1598169449943431446?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: On Sat, 14 Apr 2018 00:24:26 +0200, Ruslan Bilovol wrote: > > +static void build_feature_ctl_badd(struct usb_mixer_interface *mixer, > + unsigned int ctl_mask, int control, int unitid, > + const struct usbmix_name_map *badd_map) > +{ .... > + kctl = snd_ctl_new1(&usb_feature_unit_ctl, cval); > + > + if (!kctl) { > + usb_audio_err(mixer->chip, "cannot malloc kcontrol\n"); No need for error message after malloc failure. The kernel is already chatty about it. > +static int snd_usb_mixer_controls_badd(struct usb_mixer_interface *mixer, > + int ctrlif) > +{ > + struct usb_device *dev = mixer->chip->dev; > + struct usb_interface_assoc_descriptor *assoc; > + int badd_profile = mixer->chip->badd_profile; > + const struct usbmix_ctl_map *map; > + int p_chmask = 0, c_chmask = 0, st_chmask = 0; > + int i; > + > + assoc = usb_ifnum_to_if(dev, ctrlif)->intf_assoc; > + > + /* Detect BADD capture/playback channels from AS EP descriptors */ > + for (i = 0; i < assoc->bInterfaceCount; i++) { > + int intf = assoc->bFirstInterface + i; > + > + if (intf != ctrlif) { In this case, it's better to skip like if (intf == ctrlif) continue; so that we can save an indentation for the whole long block. > + switch (badd_profile) { > + default: > + return -EINVAL; > + case UAC3_FUNCTION_SUBCLASS_GENERIC_IO: > + /* > + * BAIF, BAOF or combination of both > + * IN: Mono or Stereo cfg, Mono alt possible > + * OUT: Mono or Stereo cfg, Mono alt possible > + */ > + /* c_chmask := DYNAMIC */ > + /* p_chmask := DYNAMIC */ > + if (!c_chmask && !p_chmask) { > + usb_audio_err(mixer->chip, > + "BADD GENERIC_IO profile: no channels?\n"); > + return -EINVAL; > + } > + break; Maybe we can simplify the whole switch/case with a table lookup. For example, for (f = uac3_func_tables; f->name; f++) { if (badd_profile == f->subclass) break; } if (!f->name) return -EINVAL; if (!uac3_func_has_valid_channels(mixer, f, c_chmask, p_chmask)) return -EINVAL; st_chmask = f->st_chmask; and in uac3_func_has_valid_channels(), static bool uac3_func_has_valid_channels() { if ((f->c_chmask < 0 && !c_chmask) || (f->c_chmask >= 0 && f->c_chmask != c_chmask)) { usb_audio_warn(mixer->chip, "BAAD %s c_chmask mismatch", f->name); return false; } if ((f->p_chmask < 0 && !p_chmask) || (f->p_chmask >= 0 && f->p_chmask != p_chmask)) { usb_audio_warn(mixer->chip, "BAAD %s p_chmask mismatch", f->name); return false; } return true; } thanks, Takashi