Re: [PATCH net] net: dsa: bcm_sf2: Fix node reference count

2020-06-18 Thread David Miller
From: Florian Fainelli 
Date: Wed, 17 Jun 2020 20:42:44 -0700

> of_find_node_by_name() will do an of_node_put() on the "from" argument.
> With CONFIG_OF_DYNAMIC enabled which checks for device_node reference
> counts, we would be getting a warning like this:
 ...
> Fix this by adding a of_node_get() to increment the reference count
> prior to the call.
> 
> Fixes: afa3b592953b ("net: dsa: bcm_sf2: Ensure correct sub-node is parsed")
> Signed-off-by: Florian Fainelli 

Applied and queued up for v5.7 -stable, thanks.


Re: [PATCH net] net: dsa: bcm_sf2: Fix node reference count

2020-06-18 Thread David Miller
From: Andrew Lunn 
Date: Thu, 18 Jun 2020 14:56:40 +0200

> That if_find_node_by_name() does a put is not very intuitive.
> Maybe document that as well in the kerneldocs?
> 
> Reviewed-by: Andrew Lunn 

I've been complaining about the non-intuitiveness of the various
OF interfaces for a long time.  They transfer reference counts
across objects, and that makes the logic hard to audit.

The iterators are the worst.


Re: [PATCH net] net: dsa: bcm_sf2: Fix node reference count

2020-06-18 Thread Florian Fainelli



On 6/18/2020 5:56 AM, Andrew Lunn wrote:
> On Wed, Jun 17, 2020 at 08:42:44PM -0700, Florian Fainelli wrote:
>> of_find_node_by_name() will do an of_node_put() on the "from" argument.
> 
>> Fixes: afa3b592953b ("net: dsa: bcm_sf2: Ensure correct sub-node is parsed")
>> Signed-off-by: Florian Fainelli 
>> ---
>>  drivers/net/dsa/bcm_sf2.c | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
>> index c1bd21e4b15c..9f62ba3e4345 100644
>> --- a/drivers/net/dsa/bcm_sf2.c
>> +++ b/drivers/net/dsa/bcm_sf2.c
>> @@ -1154,6 +1154,8 @@ static int bcm_sf2_sw_probe(struct platform_device 
>> *pdev)
>>  set_bit(0, priv->cfp.used);
>>  set_bit(0, priv->cfp.unique);
>>  
>> +/* Balance of_node_put() done by of_find_node_by_name() */
>> +of_node_get(dn);
>>  ports = of_find_node_by_name(dn, "ports");
> 
> That if_find_node_by_name() does a put is not very intuitive.
> Maybe document that as well in the kerneldocs?

Yes that is the plan, most callers call it with a NULL from argument but
that is a bit silly if you know what the Device Tree looks like, you can
search quicker to the target node. Thanks.

> 
> Reviewed-by: Andrew Lunn 
> 
> Andrew
> 

-- 
Florian


Re: [PATCH net] net: dsa: bcm_sf2: Fix node reference count

2020-06-18 Thread Andrew Lunn
On Wed, Jun 17, 2020 at 08:42:44PM -0700, Florian Fainelli wrote:
> of_find_node_by_name() will do an of_node_put() on the "from" argument.

> Fixes: afa3b592953b ("net: dsa: bcm_sf2: Ensure correct sub-node is parsed")
> Signed-off-by: Florian Fainelli 
> ---
>  drivers/net/dsa/bcm_sf2.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
> index c1bd21e4b15c..9f62ba3e4345 100644
> --- a/drivers/net/dsa/bcm_sf2.c
> +++ b/drivers/net/dsa/bcm_sf2.c
> @@ -1154,6 +1154,8 @@ static int bcm_sf2_sw_probe(struct platform_device 
> *pdev)
>   set_bit(0, priv->cfp.used);
>   set_bit(0, priv->cfp.unique);
>  
> + /* Balance of_node_put() done by of_find_node_by_name() */
> + of_node_get(dn);
>   ports = of_find_node_by_name(dn, "ports");

That if_find_node_by_name() does a put is not very intuitive.
Maybe document that as well in the kerneldocs?

Reviewed-by: Andrew Lunn 

Andrew