Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1109577pxb; Wed, 6 Apr 2022 08:57:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw1aDzcBosAa07zEODcqxsMg6sXm8VDy7agKegozBcf1KdkFMhR4fbblliQdKbtC0BLQnNj X-Received: by 2002:a63:78ca:0:b0:398:ae5:6515 with SMTP id t193-20020a6378ca000000b003980ae56515mr7697290pgc.345.1649260665148; Wed, 06 Apr 2022 08:57:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649260665; cv=none; d=google.com; s=arc-20160816; b=eNDit2PI7ZkLX0wdx549yVApdgRkl3ZVtxx5b2pDXV8/QxDpqWxH/pqgFh6OASz/pM 5xNx2Siq52+03FsWV8uWA1LO6OF0Tfwg9QyCgRQa8nXiVDhKRNc22p4do/dupem7H2w7 Gx1MKJ4tdj+hJcyrGe8zHabFzO5hZUDtFmUXswuesUeLfdrXDf1p4CPQV1C/CyMd639z 5TF3E0IMke+SWi3aVtFX0eDJUw15dSwtifwtoKn6rO2mpAR2/0ClW1VUsOBL8/sa4tZp TRz4JZMwfNo7TQRCIaPYrk3rCorOvEibIR/vP7wJ3qgCqclcg49pLEnrLGS4mfinO71t w+Iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=XgjMEhLjRT4MPAMhsdcS0Ym9ucVGsbeQUnv8qRyOX2I=; b=nTEauvHgm25DMVLIHJUyokjd6arG4PUP+t6gCY8FCVsYNLR37+KwW2YyQlS+Bclzbu 8B2AARCHlYAOFkebD1EEepyVtbzIsUMnpF/cQUSA0RYqtOVfMpGbsOdNJ47gWAu3fzWV s2yvBC63LB130YKD2UYwBDnvBnZiN6kcGMmaeCRFI20G2QLBHWOJS3HWOt8KzPWvIvBS 76P9n0XSFl9UqNsx0HAL+B6O9NnG6Knfrb+2i7p8Pr0x41vpQfBEbRMrOSRJ3NGT1Xpk N7NntciAm+Fy4y633JqJDlqeUzVBKBAU69AVokWEDA8eyrMaHACPEfX/KlAU26lMOhrS 8RkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=GG33N9hg; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id l10-20020a056a00140a00b004fa3a8dff7asi15685213pfu.49.2022.04.06.08.57.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 08:57:45 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=GG33N9hg; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C13EC1CCAE0; Wed, 6 Apr 2022 07:54:06 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235327AbiDFOzp (ORCPT + 99 others); Wed, 6 Apr 2022 10:55:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235352AbiDFOzf (ORCPT ); Wed, 6 Apr 2022 10:55:35 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 030BF27CE2E for ; Tue, 5 Apr 2022 19:19:11 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id p8so1186576pfh.8 for ; Tue, 05 Apr 2022 19:19:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=XgjMEhLjRT4MPAMhsdcS0Ym9ucVGsbeQUnv8qRyOX2I=; b=GG33N9hgu+eD/ebEhy3Uqtw42T1KOy4AZNx8zMiQ8RNnMqDR3MrKJ0yJbDK9/zahZX XtmX82g9WyruU473qtdYCzzuJtiRU5bvSltOqdS8XpnjIMfFtqtndkOjetDeT6d5nICG ArTrqu2AeWHeYKaQse/8jm14/6N+2jzKs9HxS/F2IvH4VALeAE+SZsPvFjFWefv/ScOF ayWSL1CW+OxpZgkOU3exCbNpR1e+35NzKgm/gbzNwD10kDdU8yuS+TO6hIXiw7MLqE54 kPh636J/zKiCfcJsVnKkcLXxcasLEiRxsOcCxgZ7jiYVfAOpTmBtoCYkwg2cNjdc/9fT mN1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=XgjMEhLjRT4MPAMhsdcS0Ym9ucVGsbeQUnv8qRyOX2I=; b=00iEp3MZ5nW1nb1Z2PmmYjp9p35mXJ2IwRKGrRBh/JUT0FM+O5/0er90MWIKko1GlE L4+GYgkxfNVvQwBytPnQG280RQZ3EMP8RgZpn+9gXqZkOIk0DYqTkmxmLRu/FaPQ1BO8 5AoXbJsR8XJriZ0hdsXwiYfyfb/xBu6L1UEyraBmbjCrBesDWC7Pt+Z6hknvmHeAWveS mKxla4KSky8jXYkjR0R5HUWNla0qJPM3dXBSqcgGAqt36L91ZpVSx1gWzEqGuu9Zh2oF wZE/ojg5koD3WEjA1M4Zfz91E9UWaNnuTcXFSp3NIN/YEUkOpy4X891PmHnyxJeBwaJM uOzA== X-Gm-Message-State: AOAM531Wck32YaDdz8ycXXvUIFEn+qb5yZ+VThk5q3u3JunGd4AgwS3D Zs7stFFOFJcNqtjAh/4cbQ0= X-Received: by 2002:a63:d454:0:b0:386:86:6aaa with SMTP id i20-20020a63d454000000b0038600866aaamr5248075pgj.60.1649211550460; Tue, 05 Apr 2022 19:19:10 -0700 (PDT) Received: from 8345e2a12d0c ([159.226.95.43]) by smtp.gmail.com with ESMTPSA id f16-20020a056a00229000b004fabe756ba6sm18627715pfe.54.2022.04.05.19.19.07 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Apr 2022 19:19:10 -0700 (PDT) Date: Wed, 6 Apr 2022 02:19:05 +0000 From: Miaoqian Lin To: Stefano Stabellini Cc: Russell King , Catalin Marinas , Shannon Zhao , Julien Grall , xen-devel@lists.xenproject.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] arm/xen: Fix refcount leak in xen_dt_guest_init Message-ID: <20220406021905.GA30436@8345e2a12d0c> References: <20220309102442.14726-1-linmq006@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Fri, Mar 11, 2022 at 06:01:11PM -0800, Stefano Stabellini wrote: > On Wed, 9 Mar 2022, Miaoqian Lin wrote: > > The of_find_compatible_node() function returns a node pointer with > > refcount incremented, We should use of_node_put() on it when done > > Add the missing of_node_put() to release the refcount. > > > > Fixes: 9b08aaa3199a ("ARM: XEN: Move xen_early_init() before efi_init()") > > Signed-off-by: Miaoqian Lin > > Thanks for the patch! > > > > --- > > arch/arm/xen/enlighten.c | 1 + > > 1 file changed, 1 insertion(+) > > > > diff --git a/arch/arm/xen/enlighten.c b/arch/arm/xen/enlighten.c > > index ec5b082f3de6..262f45f686b6 100644 > > --- a/arch/arm/xen/enlighten.c > > +++ b/arch/arm/xen/enlighten.c > > @@ -424,6 +424,7 @@ static void __init xen_dt_guest_init(void) > > > > if (of_address_to_resource(xen_node, GRANT_TABLE_INDEX, &res)) { > > pr_err("Xen grant table region is not found\n"); > > + of_node_put(xen_node); > > return; > > } > > This is adding a call to of_node_put on the error path. Shouldn't it > be called also in the non-error path? You're right. It should be called also in the non-error path. I made a mistake. > Also, there is another instance of of_address_to_resource being called > in this file (in arch_xen_unpopulated_init), does it make sense to call > of_node_put there too? I think so, becase device node pointer np is a local variable. So the reference it taken should be released in the scope. I look into the whole codebase for this kind of usage pattern ($ret=of_find_compatible_node();of_address_to_resource($ret,_,_), $ret is a local variable), Most of them call of_node_put() when done. And document of of_find_compatible_node() also mentions > Return: A node pointer with refcount incremented, use > of_node_put() on it when done. But I am not sure, Since I am unfamiliar with other code logic. It better if the developers could double check. I found some similar cases in arch/arm.