From patchwork Wed Feb 13 16:40:14 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Anil Kumar X-Patchwork-Id: 2137721 Return-Path: X-Original-To: patchwork-linux-omap@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 45392DFE75 for ; Wed, 13 Feb 2013 16:40:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934247Ab3BMQkb (ORCPT ); Wed, 13 Feb 2013 11:40:31 -0500 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type:content-transfer-encoding; bh=SV6tVG/ddEx82G3NzNrTWIOi6YLjBGQbe0en7R+Hn40=; b=skvWNQ4AXY24dJV5mf305LUgFquyGWKVOInIjfrmSUcdS9QnEx1ScTcZJWI33j6FFW EvFlK1FlXwYOB+zIWKiEZn41IlXM0CANrNyavNb1LXkVe9jrKlBs9bcIuKBG06UhNXl4 6i+UstVdJ92JFOfIapdJyPZUyA/ulucdCD+TJRtVK7Q2FhyTnlo/xQYyjL9CeZ6aUwah pCqSu8aw8r/8f2VUCsbUmas0uAOm7hFDP9oGYAMqqxAXSvvfx3AxrIuOOSuNfZA4IXD6 LGnCQb99el/N2myayyOo0sxLWyhpYoH7fJ4pygkDN8KvZuI68zhFUJG4BojAdgcqFKyL 9J1w== MIME-Version: 1.0 X-Received: by 10.43.134.8 with SMTP id ia8mr31193998icc.42.1360773614408; Wed, 13 Feb 2013 08:40:14 -0800 (PST) Received: by 10.42.43.200 with HTTP; Wed, 13 Feb 2013 08:40:14 -0800 (PST) In-Reply-To: <511BB6C2.3060105@ti.com> References: <511BB6C2.3060105@ti.com> Date: Wed, 13 Feb 2013 22:10:14 +0530 Message-ID: Subject: Re: Use of of_parse_phandle()/of_node_put() From: Anil Kumar 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" Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org 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 = 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 >> “refcount” 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” 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? > 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]:- omap_twl4030_dai_links[0].cpu_of_node = 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" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/sound/soc/omap/omap-twl4030.c b/sound/soc/omap/omap-twl4030.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_device *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 = of_parse_phandle(node, "ti,mcbsp", 0); + if (!dai_node) { + dev_err(&pdev->dev, "McBSP node is not provided\n"); + return -EINVAL; + } + printk(KERN_ERR"refcount 0x%x", atomic_read(&dai_node->kref.refcount)); + + omap_twl4030_dai_links[0].cpu_dai_name = NULL;