usb: gadget: f_uac2: Neaten and reduce size of afunc_validate_opts
authorJoe Perches <joe@perches.com>
Wed, 2 Feb 2022 11:27:53 +0000 (03:27 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 4 Feb 2022 14:52:50 +0000 (15:52 +0100)
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 <joe@perches.com>
Link: https://lore.kernel.org/r/2132d97ca8d4dd5ac9426cc23af95e819079b02c.camel@perches.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/gadget/function/f_uac2.c

index 3358559..a902b0c 100644 (file)
@@ -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;
        }