linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Boyd <sboyd@kernel.org>
To: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>,
	mazziesaccount@gmail.com
Cc: Jonathan Corbet <corbet@lwn.net>,
	Michael Turquette <mturquette@baylibre.com>,
	Chanwoo Choi <cw00.choi@samsung.com>,
	Krzysztof Kozlowski <krzk@kernel.org>,
	Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>,
	Russell King <linux@armlinux.org.uk>,
	Andy Gross <andy.gross@linaro.org>,
	David Brown <david.brown@linaro.org>,
	Andrey Smirnov <andrew.smirnov@gmail.com>,
	Guenter Roeck <linux@roeck-us.net>, Rob Herring <robh@kernel.org>,
	Sebastian Reichel <sre@kernel.org>,
	Lee Jones <lee.jones@linaro.org>,
	Huang Shijie <sjhuang@iluvatar.ai>,
	Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>,
	Daniel Kurtz <djkurtz@chromium.org>,
	Akshu Agrawal <akshu.agrawal@amd.com>,
	"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org
Subject: Re: [PATCH v4 1/8] clk: clkdev/of_clk - add managed lookup and provider registrations
Date: Fri, 30 Nov 2018 00:54:10 -0800	[thread overview]
Message-ID: <154356805035.88331.16867826308376667832@swboyd.mtv.corp.google.com> (raw)
In-Reply-To: <ec0d6ee7ea79f0e05041ed3e564b0aadb297ef5f.1542107769.git.matti.vaittinen@fi.rohmeurope.com>

Quoting Matti Vaittinen (2018-11-13 03:55:58)
> With MFD devices the clk properties may be contained in MFD (parent) DT
> node. Current devm_of_clk_add_hw_provider assumes the clk is bound to MFD
> subdevice not to MFD device (parent). Add
> devm_of_clk_add_hw_provider_parent to tackle this issue.
> 
> Also clkdev registration lacks of managed registration functions and it
> seems few drivers do not drop clkdev lookups at exit. Add
> devm_clk_hw_register_clkdev and devm_clk_release_clkdev to ease lookup
> releasing at exit.

Please split this into clkdev and non-clkdev devm functionality.

> 
> Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
> ---
>  Documentation/driver-model/devres.txt |   3 +
>  drivers/clk/clk.c                     |  28 ++++++--
>  drivers/clk/clkdev.c                  | 122 ++++++++++++++++++++++++++--------
>  include/linux/clk-provider.h          |  11 +++
>  include/linux/clkdev.h                |   4 ++
>  5 files changed, 136 insertions(+), 32 deletions(-)
> 
> diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt
> index 43681ca0837f..fac63760b01c 100644
> --- a/Documentation/driver-model/devres.txt
> +++ b/Documentation/driver-model/devres.txt
> @@ -238,6 +238,9 @@ CLOCK
>    devm_clk_put()
>    devm_clk_hw_register()
>    devm_of_clk_add_hw_provider()
> +  devm_of_clk_add_parent_hw_provider()
> +  devm_clk_hw_register_clkdev()
> +  devm_clk_release_clkdev()

The 'release' or non-common functions shouldn't be documented here.

>  
>  DMA
>    dmaenginem_async_device_register()
> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> index af011974d4ec..9bb921eb90f6 100644
> --- a/drivers/clk/clk.c
> +++ b/drivers/clk/clk.c
> @@ -3893,12 +3893,12 @@ static void devm_of_clk_release_provider(struct device *dev, void *res)
>         of_clk_del_provider(*(struct device_node **)res);
>  }
>  
> -int devm_of_clk_add_hw_provider(struct device *dev,
> +static int __devm_of_clk_add_hw_provider(struct device *dev,
>                         struct clk_hw *(*get)(struct of_phandle_args *clkspec,
>                                               void *data),
> -                       void *data)
> +                       struct device_node *of_node, void *data)
>  {
> -       struct device_node **ptr, *np;
> +       struct device_node **ptr;
>         int ret;
>  
>         ptr = devres_alloc(devm_of_clk_release_provider, sizeof(*ptr),
> @@ -3906,10 +3906,9 @@ int devm_of_clk_add_hw_provider(struct device *dev,
>         if (!ptr)
>                 return -ENOMEM;
>  
> -       np = dev->of_node;
> -       ret = of_clk_add_hw_provider(np, get, data);
> +       *ptr = of_node;
> +       ret = of_clk_add_hw_provider(of_node, get, data);
>         if (!ret) {
> -               *ptr = np;

Why is this moved outside of the if condition? In fact, why isn't just
the first line in this hunk deleted and passed to this function as
struct device_node *np?

>                 devres_add(dev, ptr);
>         } else {
>                 devres_free(ptr);
> @@ -3917,8 +3916,25 @@ int devm_of_clk_add_hw_provider(struct device *dev,
>  
>         return ret;
>  }

Nitpick: Add a newline here.

> +int devm_of_clk_add_hw_provider(struct device *dev,
> +                       struct clk_hw *(*get)(struct of_phandle_args *clkspec,
> +                                             void *data),
> +                       void *data)
> +{
> +       return __devm_of_clk_add_hw_provider(dev, get, dev->of_node, data);
> +}
>  EXPORT_SYMBOL_GPL(devm_of_clk_add_hw_provider);
>  
> +int devm_of_clk_add_parent_hw_provider(struct device *dev,
> +                       struct clk_hw *(*get)(struct of_phandle_args *clkspec,
> +                                             void *data),
> +                       void *data)
> +{
> +       return __devm_of_clk_add_hw_provider(dev, get, dev->parent->of_node,

I'm wondering if we can somehow auto-detect this in
devm_of_clk_add_hw_provider() by looking for #clock-cells in the node.
If it isn't there, then we go to the parent node and look for a
#clock-cells property there in the DT node for that device. Does that
make sense? Then there isn't any new API and we can attach the lifetime
of the devm registration to the presence of the property indicating this
is a clk controller or not.

> +                                            data);
> +}
> +EXPORT_SYMBOL_GPL(devm_of_clk_add_parent_hw_provider);

Can we get some kernel doc on these functions?

> +
>  /**
>   * of_clk_del_provider() - Remove a previously registered clock provider
>   * @np: Device node pointer associated with clock provider
> diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c
> index 9ab3db8b3988..f6100b6e06fd 100644
> --- a/drivers/clk/clkdev.c
> +++ b/drivers/clk/clkdev.c
[...]
> +
> +/**
> + * devm_clk_release_clkdev - Resource managed clkdev lookup release
> + * @dev: device this lookup is bound
> + * @con_id: connection ID string on device
> + * @dev_id: format string describing device name
> + *
> + * Drop the clkdev lookup created with devm_clk_hw_register_clkdev.
> + * Normally this function will not need to be called and the resource
> + * management code will ensure that the resource is freed.
> + */
> +void devm_clk_release_clkdev(struct device *dev, const char *con_id,
> +                            const char *dev_id)
> +{
> +       struct clk_lookup *cl;
> +       int rval;
> +
> +       cl = clk_find(dev_id, con_id);
> +       WARN_ON(!cl);
> +       rval = devres_release(dev, devm_clkdev_release,
> +                             &devm_clk_match_clkdev, cl);

Nitpick: Drop & on functions taken as pointers.

> +       WARN_ON(rval);
> +}
> +EXPORT_SYMBOL(devm_clk_release_clkdev);

  reply	other threads:[~2018-11-30  8:54 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-13 11:54 [PATCH v4 0/8] clk: clkdev: managed clk lookup and provider registrations Matti Vaittinen
2018-11-13 11:55 ` [PATCH v4 1/8] clk: clkdev/of_clk - add managed " Matti Vaittinen
2018-11-30  8:54   ` Stephen Boyd [this message]
2018-11-30 10:50     ` Matti Vaittinen
2018-11-30 11:06       ` Russell King - ARM Linux
2018-11-30 12:59         ` Matti Vaittinen
2018-12-03 12:16       ` Matti Vaittinen
2018-12-03 23:35       ` Stephen Boyd
2018-12-04  7:13         ` Matti Vaittinen
2018-12-04 18:21           ` Stephen Boyd
2018-12-04 18:59             ` Vaittinen, Matti
2018-11-13 11:57 ` [PATCH v4 2/8] clk: clk-max77686: Clean clkdev lookup leak and use devm Matti Vaittinen
2018-11-13 11:59 ` [PATCH v4 3/8] clk: clk-st: avoid clkdev lookup leak at remove Matti Vaittinen
2018-11-13 12:00 ` [PATCH v4 4/8] clk: clk-hi655x: Free of_provider " Matti Vaittinen
2018-11-13 12:00 ` [PATCH v4 5/8] clk: rk808: use managed version of of_provider registration Matti Vaittinen
2018-11-13 12:01 ` [PATCH v4 6/8] clk: clk-twl6040: Free of_provider at remove Matti Vaittinen
2018-11-13 12:02 ` [PATCH v4 7/8] clk: apcs-msm8916: simplify probe cleanup by using devm Matti Vaittinen
2018-11-13 12:03 ` [PATCH v4 8/8] clk: bd718x7: Initial support for ROHM bd71837/bd71847 PMIC clock Matti Vaittinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=154356805035.88331.16867826308376667832@swboyd.mtv.corp.google.com \
    --to=sboyd@kernel.org \
    --cc=akshu.agrawal@amd.com \
    --cc=andrew.smirnov@gmail.com \
    --cc=andy.gross@linaro.org \
    --cc=b.zolnierkie@samsung.com \
    --cc=corbet@lwn.net \
    --cc=cw00.choi@samsung.com \
    --cc=david.brown@linaro.org \
    --cc=djkurtz@chromium.org \
    --cc=krzk@kernel.org \
    --cc=lee.jones@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-soc@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=linux@roeck-us.net \
    --cc=matti.vaittinen@fi.rohmeurope.com \
    --cc=mazziesaccount@gmail.com \
    --cc=mturquette@baylibre.com \
    --cc=rafael.j.wysocki@intel.com \
    --cc=robh@kernel.org \
    --cc=sjhuang@iluvatar.ai \
    --cc=sre@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).