Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36432C433E0 for ; Thu, 4 Feb 2021 21:34:08 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7D24964FAB for ; Thu, 4 Feb 2021 21:34:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7D24964FAB Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id D8E3715E5; Thu, 4 Feb 2021 22:33:13 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz D8E3715E5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1612474443; bh=r1uBsa9pP3fPwJFmdKu7R0sSnaF96lu+XeWy6NuBPa4=; h=Date:From:To:Subject:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=ORXDy4se4hUjvuayArOD+b6LOjenZ6be40YfgwtUsIICKGHTgnLHBLPeBBhqknj6b RnzDbV+bQtv4NqrJj6RUNnbSTVKVLgBIQwowkXcPoCvGBZQzg0gDmcBM8a2a35Db4P G+2Gv6/O0xxmmbBsqy+WAZLTNhPw+hCu7s9AHEw8= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 5EC4AF80155; Thu, 4 Feb 2021 22:33:13 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 725FDF80171; Thu, 4 Feb 2021 22:33:11 +0100 (CET) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 57D3EF80139 for ; Thu, 4 Feb 2021 22:33:03 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 57D3EF80139 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 4C1B3AC45; Thu, 4 Feb 2021 21:33:02 +0000 (UTC) Date: Thu, 04 Feb 2021 22:33:02 +0100 Message-ID: From: Takashi Iwai To: Olivia Mackintosh Subject: Re: [PATCH v3 1/1] ALSA: usb-audio: Add DJM750 to Pioneer mixer quirk In-Reply-To: <20210204193906.20716-2-livvy@base.nu> References: <20210204193906.20716-1-livvy@base.nu> <20210204193906.20716-2-livvy@base.nu> 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 Cc: alsa-devel@alsa-project.org, fabian@lesniak-it.de X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" On Thu, 04 Feb 2021 20:39:06 +0100, Olivia Mackintosh wrote: > > This allows for N different devices to use the pioneer mixer quirk for > setting capture/record type and recording level. The impementation has > not changed much with the exception of an additional mask on > private_value to allow storing of a device index: > DEVICE MASK 0xff000000 > GROUP_MASK 0x00ff0000 > VALUE_MASK 0x0000ffff > > There is perhaps room for removing the duplication in the lookup tables > (name, wValue, wIndex) and deriving these. See the code header comment > to understand how this can be achieved. > > Feedback is very much appreciated as I'm not the most proficient C > programmer but am learning as I go. > > Signed-off-by: Olivia Mackintosh The patch looks almost good, below are just some nitpicking. > --- a/sound/usb/mixer_quirks.c > +++ b/sound/usb/mixer_quirks.c > @@ -2602,142 +2602,218 @@ static int snd_bbfpro_controls_create(struct usb_mixer_interface *mixer) > return 0; > } > > + No need to add more empty line here. > +struct snd_djm_device { > + char *name; > + const struct snd_djm_ctl *controls; > + const size_t ncontrols; The const to ncontrols is almost useless. > +struct snd_djm_ctl { > + const char *name; > + const u16 *options; > + const size_t noptions; > + const u16 default_value; > + const u16 wIndex; Ditto, const for integers are superfluous. > +static char *snd_djm_get_label_caplevel(u16 wvalue) This should have const instead. > +{ > + switch (wvalue) { > + case 0x0000: return "-19dB"; > + case 0x0100: return "-15dB"; > + case 0x0200: return "-10dB"; > + case 0x0300: return "-5dB"; > + default: return "\0"; // 'EINVAL' Let return NULL for the error instead. > +static char *snd_djm_get_label_cap(u16 wvalue) Use const. > +{ > + switch (wvalue & 0x00ff) { > + case SND_DJM_CAP_LINE: return "Control Tone LINE\0"; The trainling '\0' is superfluous. Ditto in other lines. > + default: return "\0"; // 'EINVAL' Let's use NULL. > +static char *snd_djm_get_label_pb(u16 wvalue) Use const. > +{ > + switch (wvalue & 0x00ff) { > + case SND_DJM_PB_CH1: return "Ch1\0"; > + case SND_DJM_PB_CH2: return "Ch2\0"; > + case SND_DJM_PB_AUX: return "Aux\0"; > + default: return "\0"; // 'EINVAL' Like the above. > +static char *snd_djm_get_label(u16 wvalue, u16 windex) Use const. > +{ > + switch (windex) { > + case SND_DJM_WINDEX_CAPLVL: return snd_djm_get_label_caplevel(wvalue); > + case SND_DJM_WINDEX_CAP: return snd_djm_get_label_cap(wvalue); > + case SND_DJM_WINDEX_PB: return snd_djm_get_label_pb(wvalue); > + default: return "\0"; // 'EINVAL'; Use NULL. > -static int snd_pioneer_djm_controls_info(struct snd_kcontrol *kctl, struct snd_ctl_elem_info *info) > +static int snd_djm_controls_info(struct snd_kcontrol *kctl, > + struct snd_ctl_elem_info *info) > { > - u16 group_index = kctl->private_value >> SND_PIONEER_DJM_GROUP_SHIFT; > - size_t count; > + unsigned long private_value = kctl->private_value; > + u8 device_idx = (private_value & SND_DJM_DEVICE_MASK) >> SND_DJM_DEVICE_SHIFT; > + u8 ctl_idx = (private_value & SND_DJM_GROUP_MASK) >> SND_DJM_GROUP_SHIFT; > + const struct snd_djm_device device = snd_djm_devices[device_idx]; This will end up copying the whole struct on a stack. Instead, const struct snd_djm_device *device = &snd_djm_devices[device_idx]; and access via device->ncontrols > + name = snd_djm_get_label( > + ctl->options[info->value.enumerated.item], > + ctl->wIndex > + ); It's better not to put a line-break after the open parenthesis. name = snd_djm_get_label(ctl->options[info->value.enumerated.item], ctl->wIndex); > + if (strlen(name) == 0) > return -EINVAL; If the functions above return NULL for errors, this can be simplified as: if (!name) return -EINVAL; > -static int snd_pioneer_djm_controls_update(struct usb_mixer_interface *mixer, u16 group, u16 value) > +static int snd_djm_controls_update(struct usb_mixer_interface *mixer, > + u8 device_idx, u8 group, u16 value) > { > int err; > + const struct snd_djm_device *device = &snd_djm_devices[device_idx]; Funnily, here you're doing right :) > +static int snd_djm_controls_create(struct usb_mixer_interface *mixer, > + const u8 device_idx) > { > int err, i; > - const struct snd_pioneer_djm_option_group *group; > + u16 value; > + > + const struct snd_djm_device device = snd_djm_devices[device_idx]; ... but here not. thanks, Takashi