Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2344180imm; Thu, 18 Oct 2018 13:03:17 -0700 (PDT) X-Google-Smtp-Source: ACcGV60IkjVcTcKsCCwEO7SIL93D4qQiGQh/oJau+fFj0dj+UU5oNDSWH1hLsGPlOxOyrOUfkHW7 X-Received: by 2002:a62:37c1:: with SMTP id e184-v6mr32310844pfa.112.1539892996958; Thu, 18 Oct 2018 13:03:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539892996; cv=none; d=google.com; s=arc-20160816; b=ugLonSmGOOhbSENl6tKQKgmScMYC/IXA8qY3zGv0E35sZN8JQR0MEEq2RaX8QfvlgC Rb+fuO7OrecvbYq/9MVi376t2cAQoCFnoYcDqFssdnQ/kGwlqnf2kihUSMfiVV0/Xv+6 RepeEQMKaVYK18arneIL/SqsCJJQKbNJMT/p/lDYpWrmz8HmnW+dsuYYx88i0GYTeqIm n4VEaLHKC1BxX1Jcrm/SVuLNg/SadbWbtcdi7+wtCEc5VhEym3m34ylvVxbVZbQe7uQC BC04OdPKzEqQrGUMiiEYPShOv75XztpC10V59YK8AKKIcDf205ZACrkuE46wAIjQP0nW w7Bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=i6z3vP0fwt68zYFXKZdD0CpdSptngekFINHn9PeTxJ4=; b=kXchXcESwVRKQr5IQk5xqjHYq3E7fQ7zcEbzd/AloKcSOUgzpliMgSXDhHFI+Fdtf1 /oY9bypS6KvHOH7H6W7UFsYN84T/SIxwKY/kotSFQNsJHFZGqTewmsInC3CBS0yj/7R1 htk5xScYLwyJRZg4l6WaPrHE80HCsZaTRLo71SFu82cuv9eFhL3SetIa//WadO4brvvN ECZVGrYU6kj7eU67Y4AVpFY7yMMNQBTnOFKe+dU1mhXwQXOz60rrHz/v7rOzpkXiBqI6 Djgn2A5LqiM8ILIsC0GmzFqzj2lmSt64I7PECJSlY9r4syrva9h0HxIHUYGl6ld1yg/L I3nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mD9FeJe7; 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 g11-v6si21053491plp.128.2018.10.18.13.02.58; Thu, 18 Oct 2018 13:03:16 -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=mD9FeJe7; 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 S1727324AbeJSEE5 (ORCPT + 99 others); Fri, 19 Oct 2018 00:04:57 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:34574 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725735AbeJSEE5 (ORCPT ); Fri, 19 Oct 2018 00:04:57 -0400 Received: by mail-lj1-f196.google.com with SMTP id j17-v6so28884145lja.1; Thu, 18 Oct 2018 13:02:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=i6z3vP0fwt68zYFXKZdD0CpdSptngekFINHn9PeTxJ4=; b=mD9FeJe7eBscyRcgNWxjQvs/84r2Ja+OEXOE2PtQiO4xXOGwv72h7IqoEv5S0dX9Ek NlcwTLUz8kehedfW7WcKwaeSZfDyss6VNC4D+1a/mfnTskKKpuxeen/XDxKecKksPBqn yxbVafz3uc9y7Qhcw64p1Pi8++SJR8Rpp6fS7MxQzIWiaixkoLB8WNNP4WDDdjeEYCpW VZUwLyMIs3G3A73y0FyWS4FNKc/+9rPYcDYbtL/U2ZyreoLYWiIx9eBtO2fqwQ/JwquX yY/0zjZ9fEe+IM0KNHmxaDFQVCQGF1ET3VdwC+8KfMkasmIbgUSoUHHgz4pI9Qh9JEJT jEfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=i6z3vP0fwt68zYFXKZdD0CpdSptngekFINHn9PeTxJ4=; b=Isyi//IAbTYFFSVCxuSudbPnBycMs5APk99+8p3qRBmGciQrpzvgG424Xq29ge6F/2 DRmgUXUtMm9imVhlBSKdytxcJho5ET/3CDuEyCLazif9cEXZNinQ6+CabL4s4DFFQ/rd rMSUiExsNC17MowlyeNaeRht6AAfIxf7rCUmHih0jrMAwvJS/Oq9W8ZeGSGU+H5asDR+ UALvWLSgMWo2dcoLr8hzAlOlMazFf7Fj8cgaxRkfgAwmDZKTAdFiJ0LlVJRg3VVlywrJ Lw5WR0NQrT6L9pz9ZKf+WcUr3y/bpK2lSTvghS6RgOTYigW5mK5illpedDYLo26aMMcQ 6wpg== X-Gm-Message-State: ABuFfojmZC6QWDwqr/epFeV0IwIUjTwTwkQ2bIt6v+NW4w7iYW34J25j GRF2SXSCdvBRpY8VnFsN2o/PqqHDDMd+tQHnZJc= X-Received: by 2002:a2e:974a:: with SMTP id f10-v6mr21079226ljj.30.1539892938758; Thu, 18 Oct 2018 13:02:18 -0700 (PDT) MIME-Version: 1.0 References: <1467735814-23518-1-git-send-email-ricardo.ribalda@gmail.com> <1467735814-23518-11-git-send-email-ricardo.ribalda@gmail.com> In-Reply-To: From: Ricardo Ribalda Delgado Date: Thu, 18 Oct 2018 22:02:01 +0200 Message-ID: Subject: Re: [PATCH v5 8/8] clk: fixed-rate: Convert into a module platform driver To: atull@kernel.org Cc: Michael Turquette , Stephen Boyd , Sascha Hauer , linux-clk@vger.kernel.org, LKML , frowand.list@gmail.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Alan On Thu, Oct 18, 2018 at 9:21 PM Alan Tull wrote: > > On Tue, Jul 5, 2016 at 11:45 AM Ricardo Ribalda Delgado > wrote: > > I've stumbled across a of_node_get/put imbalance that happens when the > fixed rate clock is added and deleted using device tree. The cause is > that this driver calls of_clk_add_provider() when probed, but doesn't > call of_clk_del_provider() when removed. > > It looks like a lot of clock drivers share that issue: > > $ cd drivers/clk/ > $ git grep -l of_clk_add_provider * | xargs grep -L of_clk_del_provider | wc -l > 131 > > It should be a one line fix, but for many files. > > I'm not a clock subsystem expert, so please let me know whether I'm > missing something here. Not an expert either, but I believe that the affected drivers are much less. We have to consider only the drivers that can be removed git grep -l of_clk_add_provider | xargs grep -l platform_driver | xargs grep -l remove | xargs grep -L of_clk_del_provider drivers/clk/clk-fixed-factor.c drivers/clk/clk-fixed-rate.c drivers/clk/davinci/psc.c drivers/clk/ti/adpll.c drivers/gpu/drm/mediatek/mtk_mt8173_hdmi_phy.c Also there is something else that I do not undersand: of_clk_add_hw_provider() is the same as of_clk_add_provider() ? Maybe is a good idea to remove one of them and use the devm_of_add_hw_provider. I can try to do that with coccinelle if you want. Cheers > > Thanks, > Alan > > > > > Adds support for fixed-rate clock providers which have not been > > enabled via of_clk_init(). > > > > This is required by Device trees overlays that introduce clocks > > providers. > > > > Signed-off-by: Ricardo Ribalda Delgado > > --- > > drivers/clk/clk-fixed-rate.c | 69 +++++++++++++++++++++++++++++++++++++++++--- > > 1 file changed, 65 insertions(+), 4 deletions(-) > > > > diff --git a/drivers/clk/clk-fixed-rate.c b/drivers/clk/clk-fixed-rate.c > > index 2edb39342a02..e64ba2315880 100644 > > --- a/drivers/clk/clk-fixed-rate.c > > +++ b/drivers/clk/clk-fixed-rate.c > > @@ -15,6 +15,7 @@ > > #include > > #include > > #include > > +#include > > > > /* > > * DOC: basic fixed-rate clock that cannot gate > > @@ -160,15 +161,16 @@ EXPORT_SYMBOL_GPL(clk_hw_unregister_fixed_rate); > > /** > > * of_fixed_clk_setup() - Setup function for simple fixed rate clock > > */ > > -void of_fixed_clk_setup(struct device_node *node) > > +struct clk *_of_fixed_clk_setup(struct device_node *node) > > { > > struct clk *clk; > > const char *clk_name = node->name; > > u32 rate; > > u32 accuracy = 0; > > + int ret; > > > > if (of_property_read_u32(node, "clock-frequency", &rate)) > > - return; > > + return ERR_PTR(-EIO); > > > > of_property_read_u32(node, "clock-accuracy", &accuracy); > > > > @@ -176,9 +178,68 @@ void of_fixed_clk_setup(struct device_node *node) > > > > clk = clk_register_fixed_rate_with_accuracy(NULL, clk_name, NULL, > > 0, rate, accuracy); > > - if (!IS_ERR(clk)) > > - of_clk_add_provider(node, of_clk_src_simple_get, clk); > > + if (IS_ERR(clk)) > > + return clk; > > + > > + ret = of_clk_add_provider(node, of_clk_src_simple_get, clk); > > + if (ret) { > > + clk_unregister(clk); > > + return ERR_PTR(ret); > > + } > > + > > + return clk; > > +} > > + > > +void of_fixed_clk_setup(struct device_node *node) > > +{ > > + _of_fixed_clk_setup(node); > > } > > EXPORT_SYMBOL_GPL(of_fixed_clk_setup); > > CLK_OF_DECLARE(fixed_clk, "fixed-clock", of_fixed_clk_setup); > > + > > +static int of_fixed_clk_remove(struct platform_device *pdev) > > +{ > > + struct clk *clk = platform_get_drvdata(pdev); > > + > > + if (clk) > > + clk_unregister_fixed_rate(clk); > > + > > + return 0; > > +} > > + > > +static int of_fixed_clk_probe(struct platform_device *pdev) > > +{ > > + struct clk *clk; > > + > > + /* > > + * This function is not executed when of_fixed_clk_setup > > + * succeeded. > > + */ > > + > > + clk = _of_fixed_clk_setup(pdev->dev.of_node); > > + > > + if (IS_ERR(clk)) > > + return PTR_ERR(clk); > > + > > + platform_set_drvdata(pdev, clk); > > + > > + return 0; > > +} > > + > > +static const struct of_device_id of_fixed_clk_ids[] = { > > + { .compatible = "fixed-clock" }, > > + { }, > > +}; > > +MODULE_DEVICE_TABLE(of, of_fixed_clk_ids); > > + > > +static struct platform_driver of_fixed_clk_driver = { > > + .driver = { > > + .name = "of_fixed_clk", > > + .of_match_table = of_fixed_clk_ids, > > + }, > > + .probe = of_fixed_clk_probe, > > + .remove = of_fixed_clk_remove, > > +}; > > + > > +builtin_platform_driver(of_fixed_clk_driver); > > #endif > > -- > > 2.8.1 > > -- Ricardo Ribalda