From patchwork Fri Feb 23 12:44:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13569026 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-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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)