Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3258298imu; Thu, 29 Nov 2018 19:11:02 -0800 (PST) X-Google-Smtp-Source: AFSGD/XvXvYdTfL1ywVO5gZznANjOSgySh41SvMRUFD1zG26g4wQaRq2v/eM+eAknpvvHbWF/w+H X-Received: by 2002:a17:902:a601:: with SMTP id u1mr3968132plq.77.1543547462503; Thu, 29 Nov 2018 19:11:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543547462; cv=none; d=google.com; s=arc-20160816; b=cLz8AEnIDfEO2FssyzOYBouNeEcEgPFrJKUKv2inkBog6QXApgAwtHLwhcyT024mmf cT24PyTBKgXUs+yWmBEYKsvoiyMsPstV7qK3ao4gtLR/v5RLly86+JR4k1lSmOvJNu76 HV0IyBvBrn+NtkUIBaQC6l2Mgn6i5CHzlrqAaWxleRYNXUN9+h8LOHSBGnC62J/aEfgd CsALvGGWe5Uctln5yx/ksTUIQz6gn8Mb6ydFVumwnDdqCWckCHiZWgt6PFnAcKkTuBb4 rX311V2lwt23X6mrB3dIetGE/EFTKBnyT/fq4NtM3zpRl6pSP7aLPEsXbIzEqUL9YakX Henw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:dkim-signature:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=KmXv8UHXJWEGQpuB29G2q13uYSH5NBMF4sdTfQz5whI=; b=G+FU4AzP9YgSIA3VhhJPY7JfXwx7k9uZ8aq+DGxKtPiDCLe6T1EX4xiJfQW9KUmYpm tsnLvSZ6EL5DuP8D6HeyqLO89FIAKdxOeSUJL8aoJq2TtNcXt/eKZI/Dmmva+VsId1uR b85QBmg3EfCMy4iDF1bRbnQuqemrinuyoLav6EX0PkXNR5yLUc/NKFwreNso6+vKkJtH CdI61YGMQeXOv3IFNYRZUzBAgs5kIKr/lGqAP5djW62aEVFaTy6qdbi96FNwjP8kctrA l6/0amu1Wg1o78PRq9daHZQDCfdJ5K2BAKvtQ4chCVtkm7q+7xQ8xCOV3aVALZOpwXxG b46Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=Cz3h1057; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bg7si3900282plb.149.2018.11.29.19.10.47; Thu, 29 Nov 2018 19:11:02 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=Cz3h1057; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726615AbeK3OR7 (ORCPT + 99 others); Fri, 30 Nov 2018 09:17:59 -0500 Received: from hqemgate14.nvidia.com ([216.228.121.143]:14080 "EHLO hqemgate14.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726386AbeK3OR7 (ORCPT ); Fri, 30 Nov 2018 09:17:59 -0500 Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqemgate14.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Thu, 29 Nov 2018 19:10:14 -0800 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Thu, 29 Nov 2018 19:10:12 -0800 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Thu, 29 Nov 2018 19:10:12 -0800 Received: from [10.19.225.182] (10.124.1.5) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 30 Nov 2018 03:10:10 +0000 Subject: Re: [PATCH v3 3/3] thermal: tegra: parse sensor id before sensor register To: Thierry Reding CC: , , , , , References: <1543383877-20555-1-git-send-email-wni@nvidia.com> <1543383877-20555-4-git-send-email-wni@nvidia.com> <20181128102520.GC20723@ulmo> <9c373693-1d3c-cd02-4972-dde338651c0e@nvidia.com> <20181129171304.GB18128@ulmo> From: Wei Ni Message-ID: <9beaf6ea-14bb-1944-2372-eb615f04f9e3@nvidia.com> Date: Fri, 30 Nov 2018 11:10:08 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20181129171304.GB18128@ulmo> X-Originating-IP: [10.124.1.5] X-ClientProxiedBy: HQMAIL105.nvidia.com (172.20.187.12) To HQMAIL101.nvidia.com (172.20.187.10) Content-Type: text/plain; charset="windows-1252" Content-Language: en-US Content-Transfer-Encoding: 7bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1543547415; bh=KmXv8UHXJWEGQpuB29G2q13uYSH5NBMF4sdTfQz5whI=; h=X-PGP-Universal:Subject:To:CC:References:From:Message-ID:Date: User-Agent:MIME-Version:In-Reply-To:X-Originating-IP: X-ClientProxiedBy:Content-Type:Content-Language: Content-Transfer-Encoding; b=Cz3h1057CKIwNxXO3Sy3EI/6EUhxHS+2JE2MTyhQSzpdPGzAw/LAEaL2gdQjdZw7t 4mfY06tFOq/xWWf4sItVUeeI52JtjnS8hrze85rRa3mlzdmV8S6DLs/13AqHAwj4gr dhpwyEzo7EDABZCe0jnEYVp6i1xTrbinQnnKDwrlcOX2DWj3WymY1fcqSlM8tGPBSg NoWqtdonYVYHy1QcMoJA1n0TzdoS0vmp/LtLM9VpG3SV4GC7d+xnKIQ9QoktvTozJ7 WePyuxnZ9sUM8TWEuP2P3LD7AtFMWkqmFRi/tc9waacISiSiVu4VtpwB8WZuj+D5Xa Udz96TyRIWfrA== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 30/11/2018 1:13 AM, Thierry Reding wrote: > On Thu, Nov 29, 2018 at 01:55:02PM +0800, Wei Ni wrote: >> On 28/11/2018 6:25 PM, Thierry Reding wrote: >>> On Wed, Nov 28, 2018 at 01:44:37PM +0800, Wei Ni wrote: > [...] >>>> + bool ret = false; >>>> + struct of_phandle_args sensor_specs; >>>> + struct device_node *np, *sensor_np; >>>> + >>>> + np = of_find_node_by_name(NULL, "thermal-zones"); >>>> + if (!np) >>>> + return ret; >>>> + >>>> + sensor_np = of_get_next_child(np, NULL); >>>> + for_each_available_child_of_node(np, sensor_np) { >>> >>> Aren't we leaking np here? I think we need of_node_put() after >>> of_get_next_child() to make sure the reference to the "thermal-zones" >>> node is properly released. >> >> No, we will not leak np here. Because the >> for_each_available_child_of_node will call >> of_get_next_available_child(), which will call of_node_put(prev) to >> decrease refcount of the prev node. So we just need to of_node_put the >> last node after break from this for block. > > Okay, looks like I misinterpreted what you were doing there. I thought > that for_each_available_child_of_node() took the child as first argument > and the parent as second and therefore np would be overwritten by the > first assignment in the macro. > > But looking at this more closely I think there's something else wrong > here. for_each_available_child_of_node() is defined as: > > for_each_available_child_of_node(parent, child) > > so in the above, np will be the parent and sensor_np the child. Why do > you have to do > > sensor_np = of_get_next_child(np, NULL); > > ? That's already done as part of the loop in the macro, right? So does > that not mean we get two references and we leak the first one? Can the > above not simply been dropped? It's so sorry, it's my mistake, we should remove this line, it was my develop code, forgot to remove it. Will fix it in next version. Thanks. > > Thierry >