Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751397AbdGQNrr (ORCPT ); Mon, 17 Jul 2017 09:47:47 -0400 Received: from hqemgate16.nvidia.com ([216.228.121.65]:18278 "EHLO hqemgate16.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751306AbdGQNro (ORCPT ); Mon, 17 Jul 2017 09:47:44 -0400 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Mon, 17 Jul 2017 06:47:44 -0700 Subject: Re: [PATCH] thermal: tegra: delete unneeded of_node_put To: Julia Lawall , Zhang Rui CC: , Eduardo Valentin , Thierry Reding , , , References: <1500108152-1812-1-git-send-email-Julia.Lawall@lip6.fr> From: Jon Hunter Message-ID: <66e7906c-9472-4fcb-7c04-750bb27d3989@nvidia.com> Date: Mon, 17 Jul 2017 14:47:14 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <1500108152-1812-1-git-send-email-Julia.Lawall@lip6.fr> X-Originating-IP: [10.26.11.200] X-ClientProxiedBy: UKMAIL102.nvidia.com (10.26.138.15) To UKMAIL101.nvidia.com (10.26.138.13) Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2544 Lines: 74 On 15/07/17 09:42, Julia Lawall wrote: > Device node iterators perform an of_node_put on each iteration, so putting > an of_node_put before a continue results in a double put. > > The semantic match that finds this problem is as follows > (http://coccinelle.lip6.fr): > > // > @@ > expression e1; > local idexpression child; > iterator name for_each_child_of_node; > @@ > > for_each_child_of_node(e1,child) { > ... when != of_node_get(child) > * of_node_put(child); > ... > * continue; > } > // > > Furthermore, the call to thermal_of_cooling_device_register immediately > calls __thermal_cooling_device_register with the same arguments. The > latter function stores the device node argument, which is the second > argument of for_each_child_of_node, in the returned thermal_cooling_device > structure. This returned structure is then stored in the cdev field of > stc. Thus it seems that the second argument of for_each_child_of_node > escapes the scope of the for_each_child_of_node, so an explicit of_node_get > on success of thermal_of_cooling_device_register is also needed. > > Signed-off-by: Julia Lawall > > --- > drivers/thermal/tegra/soctherm.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/thermal/tegra/soctherm.c b/drivers/thermal/tegra/soctherm.c > index 7d2db23..10f4fdd 100644 > --- a/drivers/thermal/tegra/soctherm.c > +++ b/drivers/thermal/tegra/soctherm.c > @@ -1014,7 +1014,6 @@ static void soctherm_init_hw_throt_cdev(struct platform_device *pdev) > tcd = thermal_of_cooling_device_register(np_stcc, > (char *)name, ts, > &throt_cooling_ops); > - of_node_put(np_stcc); > if (IS_ERR_OR_NULL(tcd)) { > dev_err(dev, > "throttle-cfg: %s: failed to register cooling device\n", > @@ -1022,6 +1021,7 @@ static void soctherm_init_hw_throt_cdev(struct platform_device *pdev) > continue; > } > > + of_node_get(np_stcc); > stc->cdev = tcd; > stc->init = true; > } Thanks for fixing this. However, I am wondering if it is better for the 'of_node_get' to be placed within the thermal_of_cooling_device_register() function as it seems a bit odd if the caller needs to know that this is being stored for later use. Also, taking a quick look, I see a couple other drivers calling thermal_of_cooling_device_register() and they are also not calling of_node_get on success. So it maybe easier to fix placing it in the thermal_of_cooling_device_register() function. Cheers Jon -- nvpublic