Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2828237pxb; Tue, 12 Oct 2021 14:26:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6uuuy+cesVOkcx5O6d4/f4uZDnskDqoobgvzv5CGrRa7XmEva2xUOpNlfgUkjIda8oQ3X X-Received: by 2002:a05:6402:2684:: with SMTP id w4mr3333188edd.108.1634073974705; Tue, 12 Oct 2021 14:26:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634073974; cv=none; d=google.com; s=arc-20160816; b=k3f5ghkL5BHvyAl0eSrYwEMlGoON8v5Du8I0HJxPKPoqQ9RcSyK7EatzKVazSHlaTQ WW4NdrfKBnolbBGzqxLs50qnIS3PQ1mYGRRB3T5lVdVpjDEnjrnvZ8GMnDM8FR1W5d5z qF93BpDpOe+vtKgzj3Ik64+gvQL78ECWYJolfM7gezSV6qpWv6D2hCXwsdqs1JJL+sN6 7PWWZ67Kgo/qGEe0BXlGywU7AIiFKDejd09OTSVPsdu57qbtb5MlN14RLsFYrp4dkEJg DEsMjWv0GHym5x/4kH2Sv7M1qjUPiGGm1VAfuFFrERzxn3vKfVs4zvnEkvJTuTv6vu35 2CLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=gOFNBJr+5UGYcXXM52CBBPVCPAsy4cPdDGbGieRT3Pw=; b=rbPw1F5eij3nowQWXzBXbhf/kvvyOrHJ0DZVmHu3Gp3RjYVUEReTkwlz8jz62AUxyL WtrIpiYefAeoD1LvxA0/6vNsxzgaTx35BbR1sSyfwRx0FLAlU55TMIQd1c97feq5s4/l +eBLuq509IMq30pd40vXSnc4a7TIqobfnmezElsqUtGjRtSQT8+cOQUYEstzW25gCddm 3J1G8omvIyFcZlwoSjESaq5Xvz4Pd5V2KysCFtV1DugyiRauDUao4FPSm33gSSXnL2ME 7q3+EovvRmRSdk9BWnleSB8TWUMTfSOn7nxgEoHhs4cxjKxGUdZ8B36L3IljrQqqNf+u ejvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=TjyrNYrA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id b15si17671204edm.614.2021.10.12.14.25.50; Tue, 12 Oct 2021 14:26:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=TjyrNYrA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S235086AbhJLVXe (ORCPT + 99 others); Tue, 12 Oct 2021 17:23:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233635AbhJLVXd (ORCPT ); Tue, 12 Oct 2021 17:23:33 -0400 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67970C061570; Tue, 12 Oct 2021 14:21:31 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id r18so1347236edv.12; Tue, 12 Oct 2021 14:21:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=gOFNBJr+5UGYcXXM52CBBPVCPAsy4cPdDGbGieRT3Pw=; b=TjyrNYrAJjITZgQqDIhNBw1waTJz03vnWMl+Y/NcIBBjvX+/eQQKKsaNJr5LF9vE/m U7HF99K3buQSlliPH7Y57gW8fcassAWYG8KLcminqJ3HpgDIA4QOzM1ttT4Toam8i+zj loUEwm7f4uGNYNP+lEiX76DKTTWoRBqMX6MQtDuOpXW5WdtCCRfhhZbqwC9bVl/Jx137 6zn0fRNrLwrgXBQPfibscSDKJ0TyA2u1+2N4tdOIJTICaaYl9RtiuyGYH01Vxh3gKJJe sbjeY31IlJkRviou4RLSupw9CNHNivQ+REiV0LHNpTHNQiiTBtoh9FtRbcU6L9o6M1md S3NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=gOFNBJr+5UGYcXXM52CBBPVCPAsy4cPdDGbGieRT3Pw=; b=aDRHj+pxJ3CklbQzyOnYKQLXev7NIxyZOegulFp+sT3Lry5/PdYo9GWtGiPN/POiza YcZmnnC3QgSYSbvfY5CmZfszCJLjMBAfc8b7qyXfijhn2h6zTFXqmH9MtHWfIegkFD0A QokH56p6mMZWLMmDh+rv8ZxOCxHZn9NTOiUv9IZPMLKuZd+XzMqkv2MRq+f2GmkxGoSR amEus9Yx3wZENFNQ6OfLjrYv9Mfr0G+XdxRYnWTaifIcz/BscvVKF9OFU2RxOXELp2K7 7PvQTWimZqN6KzDVN9UoJD3vsBGFQtcmOSb65uevFk2/+ZAA1TB5jXzrfb313Uct3b1G ebSg== X-Gm-Message-State: AOAM5302Zj3GgQ5/XRgRLQrKYUvilzw4vAUGHIASwmYoAIeMZapHGjBw DAU7nPTKANKEnzQqK5weQT2eK0OzfyTZGOfcio0= X-Received: by 2002:a17:906:5a47:: with SMTP id my7mr35357939ejc.128.1634073689974; Tue, 12 Oct 2021 14:21:29 -0700 (PDT) MIME-Version: 1.0 References: <20211012134027.684712-1-kernel@esmil.dk> <20211012134027.684712-7-kernel@esmil.dk> In-Reply-To: From: Andy Shevchenko Date: Wed, 13 Oct 2021 00:20:53 +0300 Message-ID: Subject: Re: [PATCH v1 06/16] clk: starfive: Add JH7100 clock generator driver To: Emil Renner Berthing Cc: linux-riscv , devicetree , linux-clk , "open list:GPIO SUBSYSTEM" , "open list:SERIAL DRIVERS" , Geert Uytterhoeven , Palmer Dabbelt , Paul Walmsley , Rob Herring , Michael Turquette , Stephen Boyd , Thomas Gleixner , Marc Zyngier , Philipp Zabel , Linus Walleij , Greg Kroah-Hartman , Daniel Lezcano , Andy Shevchenko , Jiri Slaby , Maximilian Luz , Sagar Kadam , Drew Fustini , Anup Patel , Atish Patra , Matteo Croce , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 12, 2021 at 11:08 PM Emil Renner Berthing wrote: > On Tue, 12 Oct 2021 at 17:40, Andy Shevchenko wrote: > > On Tue, Oct 12, 2021 at 4:42 PM Emil Renner Berthing wrote: ... > > > + value |= readl_relaxed(reg) & ~mask; > > > > value is not masked, is it okay? > > > > Usual pattern for this kind of operations is > > > > value = (current & ~mask) | (value & mask); > > This function is only ever called with constants, already masked > values or the parent number from the clk framework, so it should be > ok. Up to you, but I think it's better to have a usual pattern. > > > + writel_relaxed(value, reg); ... > > > + rate = parent / div; > > > + if (rate < req->min_rate && div > 1) { > > > + div -= 1; > > > + rate = parent / div; > > > + } > > > > Seems like homegrown DIV_ROUND_UP() or so. Who will guarantee that > > decreasing div by 1 will satisfy the conditional again? > > Maths unless I'm mistaken: div = DIV_ROUND_UP(parent, target), so in > rational numbers > div - 1 < parent / target > But the target is clamped by min_rate and max_rate, so > min_rate <= target < parent / (div - 1) = rate > > Sorry, re-using the rate varable for both the target and result is > confusing. I'll fix that. Also needs a comment, I believe. ... > > > +#ifdef CONFIG_DEBUG_FS > > > > Perhaps __maybe_unused? > > I can definitely use __maybe_unused for the function declaration, but > then I'll need a conditional every time clk_ops.debug_init needs to be > initialized to either the function or NULL depending on > CONFIG_DEBUG_FS below. Is that better? Actually, why can't you always initialize the field? Shouldn't CLK core take care about this conditional? > > > +#else > > > +#define jh7100_clk_debug_init NULL > > > +#endif ... > > > + while (idx > 0) > > > + clk_hw_unregister(&priv->reg[--idx].hw); > > > > The > > > > while (idx--) > > clk_hw_unregister(&priv->reg[idx].hw); > > > > is slightly better to read. > > It's not something I'll insist hard on, but I must admit I disagree. > To me the above looks like cartoon characters running off a cliff and > back. As a middle ground could we maybe do this? > > while (idx) > clk_hw_unregister(&priv->reg[--idx].hw); My point is exactly in having the common pattern for error paths, i.e. while (counter--) ...bla-bla-bla... Your second approach is better, but I think that proposed by me is even better. ... > > > +subsys_initcall(clk_starfive_jh7100_init); > > > > Any explanation why subsys_initcall() is in use? > > TBH I just inherited that from Geert's first mock driver and never > thought to question it. What would be a better alternative to try? At least add a comment to explain the choice. -- With Best Regards, Andy Shevchenko