public inbox for devicetree@vger.kernel.org
 help / color / mirror / Atom feed
From: <Tudor.Ambarus@microchip.com>
To: <nsaenz@kernel.org>, <saravanak@google.com>
Cc: <mturquette@baylibre.com>, <sboyd@kernel.org>,
	<maxime@cerno.tech>, <gregkh@linuxfoundation.org>,
	<rafael@kernel.org>, <khilman@kernel.org>,
	<ulf.hansson@linaro.org>, <len.brown@intel.com>, <pavel@ucw.cz>,
	<robh+dt@kernel.org>, <frowand.list@gmail.com>, <maz@kernel.org>,
	<tglx@linutronix.de>, <geert@linux-m68k.org>,
	<nsaenzjulienne@suse.de>, <linux@roeck-us.net>,
	<guillaume.tucker@collabora.com>, <linux-clk@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <corbet@lwn.net>,
	<Nicolas.Ferre@microchip.com>, <Claudiu.Beznea@microchip.com>,
	<linux-doc@vger.kernel.org>, <linux-pm@vger.kernel.org>,
	<devicetree@vger.kernel.org>, <linux-acpi@vger.kernel.org>,
	<kernel-team@android.com>, <linux-rpi-kernel@lists.infradead.org>,
	<m.szyprowski@samsung.com>
Subject: Re: [PATCH 1/2] clk: Do not register provider with a NULL dev->of_node
Date: Fri, 23 Apr 2021 18:35:42 +0000	[thread overview]
Message-ID: <2165b512-6f01-707b-2276-20a20899b19f@microchip.com> (raw)
In-Reply-To: <528ab89224ba27f6164135a8ac00a828e7113805.camel@kernel.org>

On 4/23/21 9:21 PM, nicolas saenz julienne wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> Hi Saravana, Tudor,
> 
> On Fri, 2021-04-23 at 10:24 -0700, Saravana Kannan wrote:
>> On Fri, Apr 23, 2021 at 10:14 AM Tudor Ambarus
>> <tudor.ambarus@microchip.com> wrote:
>>>
>>> commit 6579c8d97ad7 ("clk: Mark fwnodes when their clock provider is added")
>>> revealed that clk/bcm/clk-raspberrypi.c driver calls
>>> devm_of_clk_add_hw_provider(), with a NULL dev->of_node.
>>>
>>> devm_of_clk_add_hw_provider() should not register the provider with
>>> a NULL dev->of_node, as there is no of_node. Apart of the NULL pointer
>>> dereference that will result when calling fwnode_dev_initialized() in
>>> of_clk_add_hw_provider(), another problem is that when two drivers calling
>>> of_clk_add_hw_provider() with np = NULL, their unregistration order is not
>>> guaranteed to be correct. Avoid all the problems and just return -ENODEV
>>> when the callers of devm_of_clk_add_hw_provider() use a NULL dev->of_node,
>>> which seems the natural way to do.
>>>
>>> Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
>>> Fixes: 6579c8d97ad7 ("clk: Mark fwnodes when their clock provider is added")
>>> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
>>> ---
>>>  drivers/clk/clk.c | 12 +++++++-----
>>>  1 file changed, 7 insertions(+), 5 deletions(-)
>>>
>>> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
>>> index e2ec1b745243..8b5077cc5e67 100644
>>> --- a/drivers/clk/clk.c
>>> +++ b/drivers/clk/clk.c
>>> @@ -4634,11 +4634,10 @@ static struct device_node *get_clk_provider_node(struct device *dev)
>>>   * @get: callback for decoding clk_hw
>>>   * @data: context pointer for @get callback
>>>   *
>>> - * Registers clock provider for given device's node. If the device has no DT
>>> - * node or if the device node lacks of clock provider information (#clock-cells)
>>> - * then the parent device's node is scanned for this information. If parent node
>>> - * has the #clock-cells then it is used in registration. Provider is
>>> - * automatically released at device exit.
>>> + * Registers clock provider for given device's node. If the device node lacks
>>> + * of clock provider information (#clock-cells) then the parent device's node is
>>> + * scanned for this information. If parent node has the #clock-cells then it is
>>> + * used in registration. Provider is automatically released at device exit.
>>>   *
>>>   * Return: 0 on success or an errno on failure.
>>>   */
>>> @@ -4650,6 +4649,9 @@ int devm_of_clk_add_hw_provider(struct device *dev,
>>>         struct device_node **ptr, *np;
>>>         int ret;
>>>
>>> +       if (!dev->of_node)
>>> +               return -ENODEV;
>>> +
>>
>> Based on the other discussions, for now, just return 0. The error
>> might cause other issues in other drivers. We can clean this up later.
> 
> +1, Let's return 0 and do nothing skip the logic in the driver.
> 
> Now, from what I read in devm_of_clk_add_hw_provider(), there is a use case for
> entering with '!dev->of_node'. See get_clk_provider_node()'s usage. So I think
> we should only bail if that function fails to provide a device_node.
> 

Oh, yes, the error should have been after the get_clk_provider_node().
Any way, will send the return 0 variant too.

Cheers,
ta
 


  reply	other threads:[~2021-04-23 18:35 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-23 17:13 [PATCH 0/2] clk: Do not register provider with a NULL dev->of_node Tudor Ambarus
2021-04-23 17:13 ` [PATCH 1/2] " Tudor Ambarus
2021-04-23 17:24   ` Saravana Kannan
2021-04-23 18:21     ` nicolas saenz julienne
2021-04-23 18:35       ` Tudor.Ambarus [this message]
2021-04-23 17:13 ` [PATCH 2/2] clk: bcm: rpi: Do not call devm_of_clk_add_hw_provider " Tudor Ambarus
2021-04-23 19:12 ` [PATCH] clk: Skip clk provider registration when np is NULL Tudor Ambarus
2021-04-23 19:16   ` Tudor.Ambarus
2021-04-24  1:17   ` Stephen Boyd

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=2165b512-6f01-707b-2276-20a20899b19f@microchip.com \
    --to=tudor.ambarus@microchip.com \
    --cc=Claudiu.Beznea@microchip.com \
    --cc=Nicolas.Ferre@microchip.com \
    --cc=corbet@lwn.net \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=geert@linux-m68k.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=guillaume.tucker@collabora.com \
    --cc=kernel-team@android.com \
    --cc=khilman@kernel.org \
    --cc=len.brown@intel.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=linux@roeck-us.net \
    --cc=m.szyprowski@samsung.com \
    --cc=maxime@cerno.tech \
    --cc=maz@kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=nsaenz@kernel.org \
    --cc=nsaenzjulienne@suse.de \
    --cc=pavel@ucw.cz \
    --cc=rafael@kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=saravanak@google.com \
    --cc=sboyd@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=ulf.hansson@linaro.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