Received: by 2002:a05:7208:3188:b0:7e:5202:c8b4 with SMTP id r8csp819128rbd; Fri, 23 Feb 2024 04:46:19 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXaOSZu3gcI8E42iofuWutgolg+Hby1/1pb/y32D/nqzeRrwI/90oi3gSADgKNmIue662NuRZLZX9tj5Fyf9cVsNWKacM8OLJW77EwUdQ== X-Google-Smtp-Source: AGHT+IGNhmH80LoohuZmFlnFz2e/A82Wtfv4WGADhzmD+S8v46poDHSxjPQ8m65Uk6hKX9uhieE2 X-Received: by 2002:a05:6102:304a:b0:470:3f14:b86 with SMTP id w10-20020a056102304a00b004703f140b86mr1904937vsa.11.1708692378870; Fri, 23 Feb 2024 04:46:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708692378; cv=pass; d=google.com; s=arc-20160816; b=fp18ZfbipqhQGA3JONLw+yfnx2cXi2D9a2e1KnlDEjAKoUVRUAgnC/0B5F8qScKpL5 wURxhHL34RSx/QeKMTWly2GHfA73lyzVP4TZR9srVLY2ZVzAwM20FTeBGhlYQZ4AbDVb wJho93X3oXjgLab6886Fsc+Rg6CAOT/mSV9LRFz4gLA/r6otSrCRRnWhbs2evCsUeo5h W3HJY5DQzt0LYPdaWyy+9Lkf0K2GfeVOnXj7M/F0627pVLCeMZCf5jy005sipbyTQzVN +nhx3i6m3R9uZ8rRe1FeguPgkvVj6SvrwwpBMnlX39CryWPFPARRCmiH9xLXs8riXEDi G7QA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=mEGC+CflIW9+yNsfN/afo+6I9w5U9Ug+garPB5kxtgg=; fh=Yi6ySJLnlzcQ1cHAdg2GPzYoHD8fqg7PDZYO61sUDKc=; b=hRSy0BRllwqs+ePuVpcwVRORjgxC5y+DEt2smOQCk7KdpOkSWaWmgEi+yoorEoI/gy p752klAg6zGYpf9V5yHIBOAK16/d9Li1aesypTTXKXQuKc9fgE4leBaZ3n0MTf8maEBH YAZQy07b3ZsIxVdPU4k8dU/M9+T/eyyFTt/smKw5od28vKZaKESCbbDq3yiCMS2dw55c RR5HPJ4N8Zi2n0QAmvRP3ZEOm5HyFTWIzIMbZSXiqAP6SUBunpYv3ljF1kbK8QD+KLWp qUu8H4wQL6vDMGTjilkLKUPIWgingPHIutsppnA7BXsyYyvhZ5IT+Jep6XlKBbawS8lC 7Uvg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-78316-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78316-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=QUARANTINE) header.from=huawei.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id ou16-20020a05620a621000b00785982ccee8si15125417qkn.130.2024.02.23.04.46.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 04:46:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-78316-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-78316-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78316-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=QUARANTINE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 700FB1C209CA for ; Fri, 23 Feb 2024 12:46:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6B73A7CF1A; Fri, 23 Feb 2024 12:46:10 +0000 (UTC) Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 433C278699; Fri, 23 Feb 2024 12:46:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708692369; cv=none; b=A2OkJ6o3vvSD1NiYJNF9HodyH0h1sFQY6+9YqoPkGjQ7/t0CTF1Gg2hI2EcpQLoKk5cfpItkkpygonrKAkMeAQj+6klAmaYaK93BqzF3vP50s+an/gIfkTGvZPu24huuS1gD6+aK6/HMJnSGGvVzZBj7nA67y8U9jLBtwEoRFMk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708692369; c=relaxed/simple; bh=0nvO5QhVTwHXLw89GWAB8O3fllRqeNhpn3I82k2THuM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=heWsbMb9z9YtesSlRHJe3Ro1P0P+TcYOqf85FvG3zaSwNoXagcoAb/yAprEtuf9HBYtQ+97SyLhiBQkJTDdQpXMEhkX7XvcxIXYmNc9zQQ0wnRnSoUEbSI8TaR0tKoT4/CkuFXSr49Z4LStwLoEC55ubzZ8znI2nqDcAt1TnERw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.216]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4Th8lh5rj4z67Jjw; Fri, 23 Feb 2024 20:41:52 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id D4F19140119; Fri, 23 Feb 2024 20:46:01 +0800 (CST) Received: from SecurePC-101-06.china.huawei.com (10.122.247.231) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Fri, 23 Feb 2024 12:46:01 +0000 From: Jonathan Cameron To: , Rob Herring , Frank Rowand , , Julia Lawall CC: Peter Zijlstra , Andy Shevchenko , Greg Kroah-Hartman , Subject: [PATCH v2 3/4] of: unittest: Use for_each_child_of_node_scoped() Date: Fri, 23 Feb 2024 12:44:31 +0000 Message-ID: <20240223124432.26443-4-Jonathan.Cameron@huawei.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240223124432.26443-1-Jonathan.Cameron@huawei.com> References: <20240223124432.26443-1-Jonathan.Cameron@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: lhrpeml100004.china.huawei.com (7.191.162.219) To lhrpeml500005.china.huawei.com (7.191.163.240) A simple example of the utility of this autocleanup approach to handling of_node_put(). In this particular case some of the nodes needed for the test are not available and the _available_ version would cause them to be skipped resulting in a test failure. Signed-off-by: Jonathan Cameron --- drivers/of/unittest.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index d7593bde2d02..567904464a21 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -239,27 +239,22 @@ static void __init of_unittest_dynamic(void) static int __init of_unittest_check_node_linkage(struct device_node *np) { - struct device_node *child; int count = 0, rc; - for_each_child_of_node(np, child) { + for_each_child_of_node_scoped(np, child) { if (child->parent != np) { pr_err("Child node %pOFn links to wrong parent %pOFn\n", child, np); - rc = -EINVAL; - goto put_child; + return -EINVAL; } rc = of_unittest_check_node_linkage(child); if (rc < 0) - goto put_child; + return rc; count += rc; } return count + 1; -put_child: - of_node_put(child); - return rc; } static void __init of_unittest_check_tree_linkage(void) -- 2.39.2