Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp6148067yba; Thu, 11 Apr 2019 13:07:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqzZyTYn8sc4yvN+RiUQJuRGjWRbAHAecXjVTJ3KAiJl9NF0/X8HrG3zD6NnfnK9zglbqt23 X-Received: by 2002:aa7:8589:: with SMTP id w9mr52180830pfn.97.1555013224203; Thu, 11 Apr 2019 13:07:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555013224; cv=none; d=google.com; s=arc-20160816; b=K2uoZH6EbU+1cHEHNSc96uyhIeZQFnA+aAcxXdQaoKagjH6qXDgJY2fo5Tdvxy4eOf mZKCAh6g1cldJiZDhDPCCHYUHHbdEjpzEtMsus57Rmlw8ejGxDnK5yFRQ252K0n+pArG kX8+ryRoMKiK7I0PnrACAHKw2pltxTQpkhtFXCE/VmtODStIUZyMpfSd9zbdbKTyc23I HlOF0YPrcT2M2dMp026XEH5rCBzL3zjnM435r2ThCwh76wIQDefqN6c+kmIsMwMhtuE6 +b4v4ZQ+UpikzuYm1isz7MXd68ugbo3RvVxYOwzYd5uyRzhzawQXnJhXnYwIQtrOXvaL FxxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Fj1uFWvOmJpD3UmwZi5Xp9F4935177QKEo3naEvsMCw=; b=TXFZ41lA0YCksxSBN7wiXg3Xha1J8e6LYPmeAM1oGsqKUb1vknieAz49bPiNLVCgzQ BjVy/bVag/A3BZ4vCKpZfwWeaQWoUzAqS1dPl502iBAg2U+3F6eSJduO4s+X/WcdnsyC r7mkTe4rEYg9J4q5ZZpVe1MahAigZqJw1z5SuneVfOsNxHSzHzPzUDG0ES4t+b9R/2b7 QdplgiCi8cfrKF5KbnDgZv1KDaeI3rTAIZaMosQm7X6OJSsOLctYysM1Dg2EaumBdwbL CXdMucl4HhcEWTVDpF6yODvtm5YGnqbxj+nffL8ST15LMmUovyf/CdXcJC3ynrutfSCf RPEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="J/OHgrTK"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g127si13868749pgc.135.2019.04.11.13.06.47; Thu, 11 Apr 2019 13:07:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="J/OHgrTK"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726678AbfDKUGK (ORCPT + 99 others); Thu, 11 Apr 2019 16:06:10 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:42407 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726538AbfDKUGJ (ORCPT ); Thu, 11 Apr 2019 16:06:09 -0400 Received: by mail-pg1-f193.google.com with SMTP id p6so4012042pgh.9 for ; Thu, 11 Apr 2019 13:06:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Fj1uFWvOmJpD3UmwZi5Xp9F4935177QKEo3naEvsMCw=; b=J/OHgrTKyFI9Y77YJxiuMPWMpYIzOExlqLdh8POog4dA7cKfdhfQ1HuNcOsn7Rrre2 46LGFu7DfyIQsHWDV9cS5KjBpwztEjT/nIE+cKdDNd6upYqeK3azCNEK4qmH7Bp19vmE s/IA06fBnWCIIEtv1izx71K0us2vnc2jjd+YYwJYsA8VnijbAa32kTV5wiqSuJkiAQEI lk7pKo18qefedOqgdXJoPEIkM54a9It3OzlgJnwZ8xSwW9Y8xsdjAQ3nz62+PRXHLHly g60xGwr66U9Uq6W5QRXBX9aLr47AHGpukXDTAsiaKSOnIf6rR9zYzeQIOsbFHcqif7FB 6j0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Fj1uFWvOmJpD3UmwZi5Xp9F4935177QKEo3naEvsMCw=; b=NFwUPZUnxmYncpUv5VxCpV/OYzNp894TwMCxs/v29qenq4u6AFhS6BTrKhwk17HV8w uyoVfBfX2OLY9bqCejoBV1xrCUQuicM9U0n2/5pJSLvuaQLhM7oSi9WtOpwvXQwqoNrC fu2VKrxvXjVehLaTC5XhgvNPDkuPQ3WA+cMZVsal3adx6M0bpRNUeCVOOyjT5RvJsIWy TG+a4Qn1HDs/fUYfc+71RBRgtIifLIVPq0b+TsD/OgmPkSb3WDoaMLAfUg42Q5P9CeAX O+gKmlnxcKSQlqd5ni5hoSQezdAj9E3ulaB6B8mc0jRq3THwfi54sMHtudh4E1FUaWWK 6DEA== X-Gm-Message-State: APjAAAXg+ygwpKc7kRha3aDXUFa/31tp7dsVNKI2UfgZlA8Ld2/LwnW4 9OxOYH/nGETdO7GIWHUY77GTF636H/k= X-Received: by 2002:a63:6a42:: with SMTP id f63mr48235058pgc.207.1555013168534; Thu, 11 Apr 2019 13:06:08 -0700 (PDT) Received: from Asurada-Nvidia.nvidia.com (thunderhill.nvidia.com. [216.228.112.22]) by smtp.gmail.com with ESMTPSA id x24sm53749580pfn.128.2019.04.11.13.06.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 11 Apr 2019 13:06:07 -0700 (PDT) Date: Thu, 11 Apr 2019 13:06:03 -0700 From: Nicolin Chen To: "S.j. Wang" Cc: "timur@kernel.org" , "Xiubo.Lee@gmail.com" , "festevam@gmail.com" , "broonie@kernel.org" , "alsa-devel@alsa-project.org" , "linuxppc-dev@lists.ozlabs.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH V2 1/2] ASoC: fsl_asrc: replace the process_option table with function Message-ID: <20190411200602.GA13170@Asurada-Nvidia.nvidia.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 11, 2019 at 09:39:06AM +0000, S.j. Wang wrote: > +/* > + * Select the pre-processing and post-processing options By aligning with other function comments: /** * Select the pre-processing and post-processing options > + * > + * Fsin: input sample rate > + * Fsout: output sample rate I would suggest to use inrate and outrate to keep naming consistent. > + * pre_proc: return value for pre-processing option > + * post_proc: return value for post-processing option > + */ > +static int fsl_asrc_sel_proc(int Fsin, int Fsout, int *pre_proc, int *post_proc) > +{ > + bool det_out_op2_cond; > + bool det_out_op0_cond; By looking at the comments below. Probably better to rename them bool post_proc_cond2, post_proc_cond0; > + /* Codition for selection of post-processing */ "Codition" -> "Conditions" > + det_out_op2_cond = (((Fsin * 15 > Fsout * 16) & (Fsout < 56000)) | > + ((Fsin > 56000) & (Fsout < 56000))); Combining Daniel's comments + indentation alignment: det_out_op2_cond = (Fsin * 15 > Fsout * 16 && Fsout < 56000) || (Fsin > 56000 && Fsout < 56000); > + det_out_op0_cond = (Fsin * 23 < Fsout * 8); > + > + /* > + * unsupported case: Tsout>16.125*Tsin, and Tsout>8.125*Tsin. Funny thing is that there'd be no point in checking the 16.125, if Tsout is bigger than 8.125 times of Tsin, i.e. only one condition: Tsout > 8.125 * Tsin > + * Tsout>16.125*Tsin -> Fsin * 8 > 129 * Fsout > + * Tsout>8.125*Tsin -> Fsin * 8 > 65 * Fsout > + * Tsout>4.125*Tsin -> Fsin * 8 > 33 * Fsout > + * Tsout>1.875*Tsin -> Fsin * 8 > 15 * Fsout Took me a while to understand what it is saying.... Better to write like this: /* Does not support cases: Tsout > 8.125 * Tsin */ if (Fsin * 8 > 65 * Fsout) { pair_err("Does not support %d > 8.125 * %d\n", Fsout, Fsin); return -EINVAL; } /* Otherwise, select pre_proc between [0, 2] */ if (Fsin * 8 > 33 * Fsout) > + *pre_proc = 2; > + else if (Fsin * 8 > 15 * Fsout) { > + if (Fsin > 152000) > + *pre_proc = 2; > + else > + *pre_proc = 1; > + } else if (Fsin < 76000) > + *pre_proc = 0; > + else if (Fsin > 152000) > + *pre_proc = 2; > + else > + *pre_proc = 1; <== Would look better by moving post_cond calculations here. > + if (det_out_op2_cond) > + *post_proc = 2; > + else if (det_out_op0_cond) > + *post_proc = 0; > + else > + *post_proc = 1; And we could remove this check below: > + /* unsupported options */ > + if (*pre_proc == 4 || *pre_proc == 5) > + return -EINVAL; So basically we are doing: 1) Error out unsupported cases 2) Select pre_proc 3) Calculate conditions for post_proc 4) Select post_proc Thanks