From patchwork Wed Feb 2 11:27:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Perches X-Patchwork-Id: 539559 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6CEEC433F5 for ; Wed, 2 Feb 2022 11:27:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241811AbiBBL14 (ORCPT ); Wed, 2 Feb 2022 06:27:56 -0500 Received: from relay039.a.hostedemail.com ([64.99.140.39]:43989 "EHLO relay5.hostedemail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238515AbiBBL1z (ORCPT ); Wed, 2 Feb 2022 06:27:55 -0500 Received: from omf06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 36D1D1204E3; Wed, 2 Feb 2022 11:27:55 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf06.hostedemail.com (Postfix) with ESMTPA id 31AAA2001F; Wed, 2 Feb 2022 11:27:54 +0000 (UTC) Message-ID: <2132d97ca8d4dd5ac9426cc23af95e819079b02c.camel@perches.com> Subject: [PATCH] usb: gadget: f_uac2: Neaten and reduce size of afunc_validate_opts From: Joe Perches To: Felipe Balbi , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, LKML Date: Wed, 02 Feb 2022 03:27:53 -0800 User-Agent: Evolution 3.40.4-1ubuntu2 MIME-Version: 1.0 X-Rspamd-Queue-Id: 31AAA2001F X-Stat-Signature: gc3wm1fcagg5ghyrk6h9935b4g98p5ec X-Rspamd-Server: rspamout06 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX1+tg98Iz6SbLaGINvM6dRk6Lmq3iivjAtE= X-HE-Tag: 1643801274-810819 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Remove the repetition and reduce the object size a bit. $ size drivers/usb/gadget/function/f_uac2.o* (x86-64 defconfig with gadget) text data bss dec hex filename 24515 3136 16 27667 6c13 drivers/usb/gadget/function/f_uac2.o.new 24817 3136 16 27969 6d41 drivers/usb/gadget/function/f_uac2.o.old Signed-off-by: Joe Perches --- drivers/usb/gadget/function/f_uac2.c | 91 +++++++++++++++--------------------- 1 file changed, 38 insertions(+), 53 deletions(-) diff --git a/drivers/usb/gadget/function/f_uac2.c b/drivers/usb/gadget/function/f_uac2.c index f2237bcdba7c0..1ee06d40059c1 100644 --- a/drivers/usb/gadget/function/f_uac2.c +++ b/drivers/usb/gadget/function/f_uac2.c @@ -973,59 +973,44 @@ static void setup_descriptor(struct f_uac2_opts *opts) static int afunc_validate_opts(struct g_audio *agdev, struct device *dev) { struct f_uac2_opts *opts = g_audio_to_uac2_opts(agdev); - - if (!opts->p_chmask && !opts->c_chmask) { - dev_err(dev, "Error: no playback and capture channels\n"); - return -EINVAL; - } else if (opts->p_chmask & ~UAC2_CHANNEL_MASK) { - dev_err(dev, "Error: unsupported playback channels mask\n"); - return -EINVAL; - } else if (opts->c_chmask & ~UAC2_CHANNEL_MASK) { - dev_err(dev, "Error: unsupported capture channels mask\n"); - return -EINVAL; - } else if ((opts->p_ssize < 1) || (opts->p_ssize > 4)) { - dev_err(dev, "Error: incorrect playback sample size\n"); - return -EINVAL; - } else if ((opts->c_ssize < 1) || (opts->c_ssize > 4)) { - dev_err(dev, "Error: incorrect capture sample size\n"); - return -EINVAL; - } else if (!opts->p_srates[0]) { - dev_err(dev, "Error: incorrect playback sampling rate\n"); - return -EINVAL; - } else if (!opts->c_srates[0]) { - dev_err(dev, "Error: incorrect capture sampling rate\n"); - return -EINVAL; - } - - if (opts->p_volume_max <= opts->p_volume_min) { - dev_err(dev, "Error: incorrect playback volume max/min\n"); - return -EINVAL; - } else if (opts->c_volume_max <= opts->c_volume_min) { - dev_err(dev, "Error: incorrect capture volume max/min\n"); - return -EINVAL; - } else if (opts->p_volume_res <= 0) { - dev_err(dev, "Error: negative/zero playback volume resolution\n"); - return -EINVAL; - } else if (opts->c_volume_res <= 0) { - dev_err(dev, "Error: negative/zero capture volume resolution\n"); - return -EINVAL; - } - - if ((opts->p_volume_max - opts->p_volume_min) % opts->p_volume_res) { - dev_err(dev, "Error: incorrect playback volume resolution\n"); - return -EINVAL; - } else if ((opts->c_volume_max - opts->c_volume_min) % opts->c_volume_res) { - dev_err(dev, "Error: incorrect capture volume resolution\n"); - return -EINVAL; - } - - if ((opts->p_hs_bint < 0) || (opts->p_hs_bint > 4)) { - dev_err(dev, "Error: incorrect playback HS/SS bInterval (1-4: fixed, 0: auto)\n"); - return -EINVAL; - } - - if ((opts->c_hs_bint < 0) || (opts->c_hs_bint > 4)) { - dev_err(dev, "Error: incorrect capture HS/SS bInterval (1-4: fixed, 0: auto)\n"); + const char *msg = NULL; + + if (!opts->p_chmask && !opts->c_chmask) + msg = "no playback and capture channels"; + else if (opts->p_chmask & ~UAC2_CHANNEL_MASK) + msg = "unsupported playback channels mask"; + else if (opts->c_chmask & ~UAC2_CHANNEL_MASK) + msg = "unsupported capture channels mask"; + else if ((opts->p_ssize < 1) || (opts->p_ssize > 4)) + msg = "incorrect playback sample size"; + else if ((opts->c_ssize < 1) || (opts->c_ssize > 4)) + msg = "incorrect capture sample size"; + else if (!opts->p_srates[0]) + msg = "incorrect playback sampling rate"; + else if (!opts->c_srates[0]) + msg = "incorrect capture sampling rate"; + + else if (opts->p_volume_max <= opts->p_volume_min) + msg = "incorrect playback volume max/min"; + else if (opts->c_volume_max <= opts->c_volume_min) + msg = "incorrect capture volume max/min"; + else if (opts->p_volume_res <= 0) + msg = "negative/zero playback volume resolution"; + else if (opts->c_volume_res <= 0) + msg = "negative/zero capture volume resolution"; + + else if ((opts->p_volume_max - opts->p_volume_min) % opts->p_volume_res) + msg = "incorrect playback volume resolution"; + else if ((opts->c_volume_max - opts->c_volume_min) % opts->c_volume_res) + msg = "incorrect capture volume resolution"; + + else if ((opts->p_hs_bint < 0) || (opts->p_hs_bint > 4)) + msg = "incorrect playback HS/SS bInterval (1-4: fixed, 0: auto)"; + else if ((opts->c_hs_bint < 0) || (opts->c_hs_bint > 4)) + msg = "incorrect capture HS/SS bInterval (1-4: fixed, 0: auto)"; + + if (msg) { + dev_err(dev, "Error: %s\n", msg); return -EINVAL; }