From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Kumar, Anil" Subject: Use of of_parse_phandle()/of_node_put() Date: Wed, 13 Feb 2013 06:04:35 +0000 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============4667858887916314625==" Return-path: Content-Language: en-US List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: devicetree-discuss-bounces+gldd-devicetree-discuss=m.gmane.org-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org Sender: "devicetree-discuss" To: "Ujfalusi, Peter" Cc: Alsa Devel List , "devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org" , "broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org" , "linux-omap-u79uwXL29TY76Z2rM5mHXA@public.gmane.org" , "Girdwood, Liam" , "jarkko.nikula-FVTvWyuFUl3QT0dZR+AlfA@public.gmane.org" List-Id: linux-omap@vger.kernel.org --===============4667858887916314625== Content-Language: en-US Content-Type: multipart/alternative; boundary="_000_F3DBB1B3EF102E4994C89758CFCA32412C6E52DBDE01entticom_" --_000_F3DBB1B3EF102E4994C89758CFCA32412C6E52DBDE01entticom_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Peter, Just trying to understand. In omap-twl4030.c file probe function :- dai_node =3D of_parse_phandle(node, "ti,mcbsp", 0); if (!dai_node) { dev_err(&pdev->dev, "McBSP node is not provided\n")= ; return -EINVAL; } Here "of_parse_phandle()" is used to get "of_device" node pointer. of_parse_phandle() suggest to use of_node_put() on it when done. It looks when code request for an "of_device" node, kernel maintains "refc= ount" for this. It check "refcount" before giving pointer of of_device node and WARN_ON() in case of refcount > 0 and increase it on success. Should this code need to use of_node_put() on the requested "of_device" whe= n done so that this can be get again ? I am taking reference of Linux-next kernel. I'm sorry if this question is very vague or missing something. Thanks, Anil --_000_F3DBB1B3EF102E4994C89758CFCA32412C6E52DBDE01entticom_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable
Hi  Peter,
 
Just trying to understand.
 
In omap-twl4030.c file probe function :-
 
dai_node =3D of_parse_phandle(node, "ti,mcbsp", 0);
           &nbs= p;    if (!dai_node) {
           &nbs= p;            dev_er= r(&pdev->dev, "McBSP node is not provided\n");
           &nbs= p;            return= -EINVAL;
           &nbs= p;    }
 
Here  “of_parse_phandle()”  is used to get = “of_device” node pointer.
of_parse_phandle() suggest to use of_node_put()  on it when done.=
 
It looks when code request for an “of_device” node, kernel=   maintains “refcount” for this.
It check “refcount”  before giving pointer of of_devi= ce node and  WARN_ON()
in case of refcount  > 0 and increase it on success.
 
Should this code need to use of_node_put() on the requested “of_= device” when done
so that this can be get  again ?
 
I am taking reference of Linux-next kernel.
 
I'm sorry if this question is very vague or  missing something.
 
Thanks,
Anil
 
 
 
 
 
 
--_000_F3DBB1B3EF102E4994C89758CFCA32412C6E52DBDE01entticom_-- --===============4667858887916314625== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org https://lists.ozlabs.org/listinfo/devicetree-discuss --===============4667858887916314625==-- From mboxrd@z Thu Jan 1 00:00:00 1970 From: Peter Ujfalusi Subject: Re: Use of of_parse_phandle()/of_node_put() Date: Wed, 13 Feb 2013 16:52:34 +0100 Message-ID: <511BB6C2.3060105@ti.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org To: "Kumar, Anil" Cc: Alsa Devel List , "devicetree-discuss@lists.ozlabs.org" , Mark Brown , Liam Girdwood , "linux-omap@vger.kernel.org" , "jarkko.nikula@bitmer.com" List-Id: linux-omap@vger.kernel.org On 02/13/2013 07:04 AM, Kumar, Anil wrote: > Hi Peter, > = > Just trying to understand. > = > In omap-twl4030.c file probe function :- > = > dai_node =3D of_parse_phandle(node, "ti,mcbsp", 0); > if (!dai_node) { > dev_err(&pdev->dev, "McBSP node is not provided\n= "); > return -EINVAL; > } > = > Here =93of_parse_phandle()=94 is used to get =93of_device=94 node poin= ter. > of_parse_phandle() suggest to use of_node_put() on it when done. > = > It looks when code request for an =93of_device=94 node, kernel maintains > =93refcount=94 for this. > It check =93refcount=94 before giving pointer of of_device node and WAR= N_ON() > in case of refcount > 0 and increase it on success. > = > Should this code need to use of_node_put() on the requested =93of_device= =94 when done > so that this can be get again ? Hrm, one thing or sure we should not call it of_node_put() while we have the card loaded since the node is used runtime by the core. However when we unload the machine driver it might be needed, but not sure about this. None of the existing machine drivers doing it (tegra, samsung, omap, etc). But if it is needed it might be better to be done by the core? > = > I am taking reference of Linux-next kernel. > = > I'm sorry if this question is very vague or missing something. > = > Thanks, > Anil > = > = > = > = > = > = -- = P=E9ter From mboxrd@z Thu Jan 1 00:00:00 1970 From: Anil Kumar Subject: Re: Use of of_parse_phandle()/of_node_put() Date: Wed, 13 Feb 2013 22:10:14 +0530 Message-ID: References: <511BB6C2.3060105@ti.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: QUOTED-PRINTABLE Return-path: Received: from mail-ia0-f169.google.com ([209.85.210.169]:59206 "EHLO mail-ia0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934262Ab3BMQk1 convert rfc822-to-8bit (ORCPT ); Wed, 13 Feb 2013 11:40:27 -0500 Received: by mail-ia0-f169.google.com with SMTP id j5so1403740iaf.0 for ; Wed, 13 Feb 2013 08:40:26 -0800 (PST) In-Reply-To: <511BB6C2.3060105@ti.com> Sender: linux-omap-owner@vger.kernel.org List-Id: linux-omap@vger.kernel.org To: Alsa Devel List , "devicetree-discuss@lists.ozlabs.org" , "linux-omap@vger.kernel.org" Cc: "Kumar, Anil" , Peter Ujfalusi , Mark Brown , Liam Girdwood , "jarkko.nikula@bitmer.com" Hi, On Wed, Feb 13, 2013 at 9:22 PM, Peter Ujfalusi = wrote: > On 02/13/2013 07:04 AM, Kumar, Anil wrote: >> Hi Peter, >> >> Just trying to understand. >> >> In omap-twl4030.c file probe function :- >> >> dai_node =3D of_parse_phandle(node, "ti,mcbsp", 0); >> if (!dai_node) { >> dev_err(&pdev->dev, "McBSP node is not provi= ded\n"); >> return -EINVAL; >> } >> >> Here =93of_parse_phandle()=94 is used to get =93of_device=94 node= pointer. >> of_parse_phandle() suggest to use of_node_put() on it when done. >> >> It looks when code request for an =93of_device=94 node, kernel main= tains >> =93refcount=94 for this. >> It check =93refcount=94 before giving pointer of of_device node and= WARN_ON() >> in case of refcount > 0 and increase it on success. >> >> Should this code need to use of_node_put() on the requested =93of_de= vice=94 when done >> so that this can be get again ? > > Hrm, one thing or sure we should not call it of_node_put() while we h= ave the > card loaded since the node is used runtime by the core. > > However when we unload the machine driver it might be needed, but not= sure > about this. None of the existing machine drivers doing it (tegra, sam= sung, > omap, etc). > But if it is needed it might be better to be done by the core? > It looks issue is different here. I have done some testing here with patch[1]. In this patch i tried to get same "of_device" node pointer again and found refcount for this dt node is 1 [Result]. As of_parse_phandle() says it "returns the device_node pointer with refcount incremented". But why refcount value is 1 [Result] again ? -----------------------------8--------------------- Patch[1]:- diff --git a/sound/soc/omap/omap-twl4030.c b/sound/soc/omap/omap-twl403= 0.c index fd98509..0828a5c 100644 --- a/sound/soc/omap/omap-twl4030.c +++ b/sound/soc/omap/omap-twl4030.c @@ -297,6 +297,16 @@ static int omap_twl4030_probe(struct platform_devi= ce *pdev) dev_err(&pdev->dev, "McBSP node is not provided= \n"); return -EINVAL; } + printk(KERN_ERR"refcount 0x%x", atomic_read(&dai_node->kref.refcount)); + + dai_node =3D of_parse_phandle(node, "ti,mcbsp", 0); + if (!dai_node) { + dev_err(&pdev->dev, "McBSP node is not provide= d\n"); + return -EINVAL; + } + printk(KERN_ERR"refcount 0x%x", atomic_read(&dai_node->kref.refcount)); + + omap_twl4030_dai_links[0].cpu_dai_name =3D NULL; omap_twl4030_dai_links[0].cpu_of_node =3D dai_node; [Result]:- root@DevKit8000:/# insmod snd-soc-omap-twl4030.ko [ 95.718109] refcount 0x1 [ 95.720611] refcount 0x1 [ 95.818054] omap-twl4030 sound.20: twl4030-hifi <-> 49022000.mcbsp mapping ok Thanks, Anil [...] -- To unsubscribe from this list: send the line "unsubscribe linux-omap" i= n the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html From mboxrd@z Thu Jan 1 00:00:00 1970 From: Anil Kumar Subject: Re: Use of of_parse_phandle()/of_node_put() Date: Wed, 13 Feb 2013 22:32:11 +0530 Message-ID: References: <511BB6C2.3060105@ti.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: QUOTED-PRINTABLE Return-path: Received: from mail-ie0-f175.google.com ([209.85.223.175]:60445 "EHLO mail-ie0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760036Ab3BMRCO convert rfc822-to-8bit (ORCPT ); Wed, 13 Feb 2013 12:02:14 -0500 Received: by mail-ie0-f175.google.com with SMTP id c12so1955141ieb.20 for ; Wed, 13 Feb 2013 09:02:12 -0800 (PST) In-Reply-To: Sender: linux-omap-owner@vger.kernel.org List-Id: linux-omap@vger.kernel.org To: Peter Ujfalusi Cc: "Kumar, Anil" , Mark Brown , Liam Girdwood , "jarkko.nikula@bitmer.com" , "devicetree-discuss@lists.ozlabs.org" , "linux-omap@vger.kernel.org" , Alsa Devel List Hi Peter, On Wed, Feb 13, 2013 at 10:10 PM, Anil Kumar wrote= : > Hi, > > On Wed, Feb 13, 2013 at 9:22 PM, Peter Ujfalusi wrote: >> On 02/13/2013 07:04 AM, Kumar, Anil wrote: >>> Hi Peter, >>> >>> Just trying to understand. >>> >>> In omap-twl4030.c file probe function :- >>> >>> dai_node =3D of_parse_phandle(node, "ti,mcbsp", 0); >>> if (!dai_node) { >>> dev_err(&pdev->dev, "McBSP node is not prov= ided\n"); >>> return -EINVAL; >>> } >>> >>> Here =93of_parse_phandle()=94 is used to get =93of_device=94 nod= e pointer. >>> of_parse_phandle() suggest to use of_node_put() on it when done. >>> >>> It looks when code request for an =93of_device=94 node, kernel mai= ntains >>> =93refcount=94 for this. >>> It check =93refcount=94 before giving pointer of of_device node an= d WARN_ON() >>> in case of refcount > 0 and increase it on success. >>> >>> Should this code need to use of_node_put() on the requested =93of_d= evice=94 when done >>> so that this can be get again ? >> >> Hrm, one thing or sure we should not call it of_node_put() while we = have the >> card loaded since the node is used runtime by the core. >> >> However when we unload the machine driver it might be needed, but no= t sure >> about this. None of the existing machine drivers doing it (tegra, sa= msung, >> omap, etc). >> But if it is needed it might be better to be done by the core? >> Sorry i forgot to mention. Yes, I think soc core may have something like[1] to release cpu_of_node= =2E [1] ------------8--------------- diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index b7e84a7..9000f4a 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1044,6 +1044,13 @@ static void soc_remove_dai_links(struct snd_soc_card *card) soc_remove_link_dais(card, dai, order); } + /* release cpu_of_node */ + if(card->dai_link) { + int i; + for(i =3D 0; i < card->num_links; i++) + of_node_put(card->dai_link[i].cpu_of_node); + } + Thanks, Anil > > It looks issue is different here. > I have done some testing here with patch[1]. In this patch i tried to > get same "of_device" node pointer > again and found refcount for this dt node is 1 [Result]. > > As of_parse_phandle() says it "returns the device_node pointer with > refcount incremented". > But why refcount value is 1 [Result] again ? > > -----------------------------8--------------------- > Patch[1]:- > diff --git a/sound/soc/omap/omap-twl4030.c b/sound/soc/omap/omap-twl4= 030.c > index fd98509..0828a5c 100644 > --- a/sound/soc/omap/omap-twl4030.c > +++ b/sound/soc/omap/omap-twl4030.c > @@ -297,6 +297,16 @@ static int omap_twl4030_probe(struct platform_de= vice *pdev) > dev_err(&pdev->dev, "McBSP node is not provid= ed\n"); > return -EINVAL; > } > + printk(KERN_ERR"refcount 0x%x", > atomic_read(&dai_node->kref.refcount)); > + > + dai_node =3D of_parse_phandle(node, "ti,mcbsp", 0); > + if (!dai_node) { > + dev_err(&pdev->dev, "McBSP node is not provi= ded\n"); > + return -EINVAL; > + } > + printk(KERN_ERR"refcount 0x%x", > atomic_read(&dai_node->kref.refcount)); > + > + > omap_twl4030_dai_links[0].cpu_dai_name =3D NULL; > omap_twl4030_dai_links[0].cpu_of_node =3D dai_node; > > [Result]:- > root@DevKit8000:/# insmod snd-soc-omap-twl4030.ko > [ 95.718109] refcount 0x1 > [ 95.720611] refcount 0x1 [ 95.818054] omap-twl4030 sound.20: > twl4030-hifi <-> 49022000.mcbsp mapping ok > > > Thanks, > Anil > [...] -- To unsubscribe from this list: send the line "unsubscribe linux-omap" i= n the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html From mboxrd@z Thu Jan 1 00:00:00 1970 From: Peter Ujfalusi Subject: Re: Use of of_parse_phandle()/of_node_put() Date: Thu, 14 Feb 2013 10:21:35 +0100 Message-ID: <511CAC9F.4010308@ti.com> References: <511BB6C2.3060105@ti.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE Return-path: Received: from devils.ext.ti.com ([198.47.26.153]:47762 "EHLO devils.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756740Ab3BNJV5 (ORCPT ); Thu, 14 Feb 2013 04:21:57 -0500 In-Reply-To: Sender: linux-omap-owner@vger.kernel.org List-Id: linux-omap@vger.kernel.org To: Anil Kumar Cc: Alsa Devel List , "devicetree-discuss@lists.ozlabs.org" , "linux-omap@vger.kernel.org" , "Kumar, Anil" , Mark Brown , Liam Girdwood , "jarkko.nikula@bitmer.com" On 02/13/2013 05:40 PM, Anil Kumar wrote: > It looks issue is different here. > I have done some testing here with patch[1]. In this patch i tried to > get same "of_device" node pointer > again and found refcount for this dt node is 1 [Result]. >=20 > As of_parse_phandle() says it "returns the device_node pointer with > refcount incremented". > But why refcount value is 1 [Result] again ? Documentation/kref.txt >=20 > -----------------------------8--------------------- > Patch[1]:- > diff --git a/sound/soc/omap/omap-twl4030.c b/sound/soc/omap/omap-twl4= 030.c > index fd98509..0828a5c 100644 > --- a/sound/soc/omap/omap-twl4030.c > +++ b/sound/soc/omap/omap-twl4030.c > @@ -297,6 +297,16 @@ static int omap_twl4030_probe(struct platform_de= vice *pdev) > dev_err(&pdev->dev, "McBSP node is not provid= ed\n"); > return -EINVAL; > } > + printk(KERN_ERR"refcount 0x%x", > atomic_read(&dai_node->kref.refcount)); > + > + dai_node =3D of_parse_phandle(node, "ti,mcbsp", 0); > + if (!dai_node) { > + dev_err(&pdev->dev, "McBSP node is not provi= ded\n"); > + return -EINVAL; > + } > + printk(KERN_ERR"refcount 0x%x", > atomic_read(&dai_node->kref.refcount)); > + > + > omap_twl4030_dai_links[0].cpu_dai_name =3D NULL; > omap_twl4030_dai_links[0].cpu_of_node =3D dai_node; >=20 > [Result]:- > root@DevKit8000:/# insmod snd-soc-omap-twl4030.ko > [ 95.718109] refcount 0x1 > [ 95.720611] refcount 0x1 [ 95.818054] omap-twl4030 sound.20: > twl4030-hifi <-> 49022000.mcbsp mapping ok >=20 >=20 > Thanks, > Anil > [...] >=20 --=20 P=E9ter -- To unsubscribe from this list: send the line "unsubscribe linux-omap" i= n the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html From mboxrd@z Thu Jan 1 00:00:00 1970 From: Peter Ujfalusi Subject: Re: Use of of_parse_phandle()/of_node_put() Date: Thu, 14 Feb 2013 10:26:41 +0100 Message-ID: <511CADD1.9060104@ti.com> References: <511BB6C2.3060105@ti.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: QUOTED-PRINTABLE Return-path: Received: from arroyo.ext.ti.com ([192.94.94.40]:58003 "EHLO arroyo.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756741Ab3BNJ1A (ORCPT ); Thu, 14 Feb 2013 04:27:00 -0500 In-Reply-To: Sender: linux-omap-owner@vger.kernel.org List-Id: linux-omap@vger.kernel.org To: Anil Kumar Cc: "Kumar, Anil" , Mark Brown , Liam Girdwood , "jarkko.nikula@bitmer.com" , "devicetree-discuss@lists.ozlabs.org" , "linux-omap@vger.kernel.org" , Alsa Devel List On 02/13/2013 06:02 PM, Anil Kumar wrote: > ------------8--------------- > diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c > index b7e84a7..9000f4a 100644 > --- a/sound/soc/soc-core.c > +++ b/sound/soc/soc-core.c > @@ -1044,6 +1044,13 @@ static void soc_remove_dai_links(struct > snd_soc_card *card) > soc_remove_link_dais(card, dai, order); > } >=20 > + /* release cpu_of_node */ > + if(card->dai_link) { > + int i; > + for(i =3D 0; i < card->num_links; i++) > + of_node_put(card->dai_link[i].cpu_of_node); and the same for codec_of_node and platform_of_node for that matter. Mark: what do you think? Does it make sense to do this in the core or s= hould we let the machine drivers to take care of this? > + } > + >=20 --=20 P=E9ter -- To unsubscribe from this list: send the line "unsubscribe linux-omap" i= n the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html