From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 16D731A9F88 for ; Mon, 16 Feb 2026 08:43:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771231435; cv=none; b=moIsIGC6G2ZAQJgcXhcgZQsL+mB6utI9ALQSSYu684bDObRXOQVFsk7B+U6sa+JdLu4PbPb2qZMhquzYwy5oGKXqUpxLVlIgTB9msq/Obw4d2rzcpd6cHXjf3xJYr8prh/nRVCcV3149Ow2LER13tI85eSHS1IRmdnz95CbSP30= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771231435; c=relaxed/simple; bh=t5jU0zdxXC9oc8VmqMDOIcx2L5P5AgBlSl7RA94sQ4U=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WKmBHQlat6ALMbPgQ08S5wN29Wy+xlxd7FmKoswij5sVHe6ckciQXVCdrrjQst2rq8zxpMKErsTnWaVFyStPVRjpzyaNveJ2BcFQfbVOKcBG2rRGLb6W/8L2B1xtTVSOfEBQh6TZnJkrnLriXoMWmUV4KuaZR/SwAKSWZCW4B58= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=cHhpr3Pa; arc=none smtp.client-ip=209.85.128.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cHhpr3Pa" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-4806b88d8c9so3809025e9.2 for ; Mon, 16 Feb 2026 00:43:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771231432; x=1771836232; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=E0xs9fvGeOqwxr5V8t4Km2tE6fnDF+EDCRUjcySx4So=; b=cHhpr3Pa0wO1j6qmUaBHNRM1LRKIQN305dOtlvdjre8Y4C99aUk0+mdjOezlVQDvG+ P7hV7jP+FAVetV2r9S8x5Uv5ZqMjlyrZKK9ek5HKnWwaN0KUWTRknRJWU4Du/Ure/ijU 9/pU+q1WcJWl3axiweB4pn9i64mSYGgRwSfdtNd3lVS65tRJ4ulpYVJNXu2KwJf8Wy4O rap/iLhhv5ygDaClgN0ECc/wZy3hZ8OEQL3ugYMrkl/k6zDRAFbqti1JPtYuIshBYgHT puyT3hrIhMC8xe/sd/YTNzT+ZyPStG/bpPFhFk868RUOiS0golOgS5ZXugnPg/qXEGJD XMDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771231432; x=1771836232; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=E0xs9fvGeOqwxr5V8t4Km2tE6fnDF+EDCRUjcySx4So=; b=Z5sBf/8wh6iMKeQoKiQOg3Qp8C6haTLwyYw+cdNIA744RexgoUl0oj6YH5gCTx0huc nOMeurBBQQLwsPQ66ahw+bABniykXCfIiYAtmlRRI2vai7JQAt/MuBdqC1dIPP/+lLL2 saD4qE76jIHwL7SkTKLLoTUxiePQ3Y3iV5OpZrAE0BlbgLhICLIzUkLyNMBBx16Qvbpo 2ZnlJwzzs7HAkAR+2tzwXl+U2onEyQ6sW4WdK+tEaRFTK+4aBMqZeZJrgrfeBDi7FAc6 2o+fBM03j0QuqeeN49ETyvct6bFY0iBGFx5MKYb26FlOhj5dC71RdD+bWs3M0oPLWmi0 Y2NQ== X-Forwarded-Encrypted: i=1; AJvYcCX0UfdktcTKarvOL3WIA9aOET5H2FDW+HzoqtrQUvg2XAZNS43Is/4dkgx2yfSALqbh1LZP3SiMjewdxcU=@vger.kernel.org X-Gm-Message-State: AOJu0Yyce95g2yBHXD0h40rDf1bEeXBlQfXuodIit9tmFXUvL7hXJmDW 74n6Gd3vUDZdhrMuCajUQEJQ6v4MOrdCGNf3Hx9URl5xzoWb14pO068g X-Gm-Gg: AZuq6aJnzNXsr1uWL7Ihg2bwpC/FT30+c78FpGdSiVNUt1xb3rGx9VJ4nNfB3HOvbUK k+VVqfUycH4PcSxNx31B0XSejaeBgm4K9cicj+biwtIV4MBU10rz+oxt2h2NOUZCsCaNH2ftVYu ChSlrzqxZ/LpfKu9sXx1ZDVdm4/hEwUuHS+8+BcqMwHgrAtT+oXPSvEG4sNt1gQ0d0XsgmlsoyT 5FT6+rMu3+URYF8qAYzaUFcn4vsPTkswNph4nkRsL5D5RcZ6/8U0pBF0rGdA4/2dkRgLIxTD7DZ Irij0BS6+7u4NaLkDx4W1qN0qsSzgZ2kyUzkbR8OqGq3g6pxrfBz3nqZ5yqzoJT5P8rZKnnmBbp 6w7L4SRy7AVRC2Am5yK9Jmkj9GjFHM13WoHE471BC98Cnsi0T2qMTF0l+1SUgRqXux0KK6XOR+t KjSMaWJAFNyexUGQ== X-Received: by 2002:a05:600c:4448:b0:47b:d992:601e with SMTP id 5b1f17b1804b1-48370e2b6bemr118383285e9.2.1771231432075; Mon, 16 Feb 2026 00:43:52 -0800 (PST) Received: from skbuf ([2a02:2f04:d501:d900:68e2:cc27:74c:c083]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48371a15dd9sm111107765e9.5.2026.02.16.00.43.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Feb 2026 00:43:50 -0800 (PST) Date: Mon, 16 Feb 2026 10:43:48 +0200 From: Vladimir Oltean To: Haotian Zhang Cc: vkoul@kernel.org, kishon@kernel.org, andriy.shevchenko@linux.intel.com, linux-phy@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] phy: hisilicon: Fix OF node reference leak Message-ID: <20260216084348.e2ozdqy5unvfs7qe@skbuf> References: <20251112062246.852-1-vulab@iscas.ac.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20251112062246.852-1-vulab@iscas.ac.cn> Hello Haotian, On Wed, Nov 12, 2025 at 02:22:46PM +0800, Haotian Zhang wrote: > hi3670_pcie_get_resources_from_pcie() leaks an OF node reference > obtained by of_get_child_by_name(). The reference is not released > on any of the error paths or on successful return, causing a > reference count leak. > > Fix this by declaring the device node with the __free(device_node) > cleanup construct to ensure the reference is automatically released. > > Fixes: 73075011ffff ("phy: HiSilicon: Add driver for Kirin 970 PCIe PHY") > Signed-off-by: Haotian Zhang > --- > drivers/phy/hisilicon/phy-hi3670-pcie.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/drivers/phy/hisilicon/phy-hi3670-pcie.c b/drivers/phy/hisilicon/phy-hi3670-pcie.c > index dbc7dcce682b..fc4f50aa31cd 100644 > --- a/drivers/phy/hisilicon/phy-hi3670-pcie.c > +++ b/drivers/phy/hisilicon/phy-hi3670-pcie.c > @@ -558,11 +558,10 @@ static int hi3670_pcie_noc_power(struct hi3670_pcie_phy *phy, bool enable) > > static int hi3670_pcie_get_resources_from_pcie(struct hi3670_pcie_phy *phy) > { > - struct device_node *pcie_port; > struct device *dev = phy->dev; > struct device *pcie_dev; > - > - pcie_port = of_get_child_by_name(dev->parent->of_node, "pcie"); > + struct device_node *pcie_port __free(device_node) = > + of_get_child_by_name(dev->parent->of_node, "pcie"); > if (!pcie_port) { > dev_err(dev, "no pcie node found in %s\n", > dev->parent->of_node->full_name); > -- > 2.50.1.windows.1 > > Sorry for the delay, and thank you for the patch. Please do not complicate the solution more than necessary, and more importantly, do not use cleanup.h infrastructure added in 2023 to fix a bug from 2021 (will be difficult to backport). In this case, it is sufficient to free the OF node after bus_find_device_by_of_node(): pcie_port = of_get_child_by_name(dev->parent->of_node, "pcie"); if (!pcie_port) { dev_err(dev, "no pcie node found in %s\n", dev->parent->of_node->full_name); return -ENODEV; } pcie_dev = bus_find_device_by_of_node(&platform_bus_type, pcie_port); + of_node_put(pcie_port); if (!pcie_dev) { dev_err(dev, "Didn't find pcie device\n"); return -ENODEV; } Note that there exists a second reference leak bug in the same function. bus_find_device_by_of_node() requires put_device(pcie_dev) after it is no longer needed. Can you resubmit a patch set addressing both issues?