Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp841158rbb; Sun, 25 Feb 2024 06:28:17 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUW3MhdyFwN/1z/W6JpewesPtPyv6+svPeFwQmPq28WTSwkd4tdJrh+B6LPOAwhemwjj+IJkC9ZhNXCTxC7VBSdcYCXmt3VCGUsKJxdEw== X-Google-Smtp-Source: AGHT+IF0jclGXWHSd2LutTXFzJqNa5qmkhX1HfiPwPTomEpS4/oI7t9CvJx6omOw+HM6F3Fp+Mjt X-Received: by 2002:a17:906:a384:b0:a43:3acd:67c with SMTP id k4-20020a170906a38400b00a433acd067cmr596679ejz.11.1708871297347; Sun, 25 Feb 2024 06:28:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708871297; cv=pass; d=google.com; s=arc-20160816; b=dADa9yTG2ATufdVJaPfIJjs6q2WzZHVWz4ZhZBVJVAWJThov8unuHRgA+2b9+x+gQi KQeABPxDWcHiIq94wlK51TvjjMIdoY8eIDAi/XllxZnxqh8FDFoAerdeCIIjo0CyEo00 Vq4Vm9jyD9Gm09AJjRV1pm8PIqAD9pGiNdtyBwU65Gye4PgbWv61hUN5Pgzs3cAh4uUN QNFS9TKviRFOmhCbgTeL+7FjZ7JKP1/T/bISF13Trw1T/671XrWCpQwlSsff9XJT/OY/ MhcbeZVMVoCEOjg6kidyceyvua58b4RI0gNRps5lLb0DI/yriyudmBOnwmiDv3KhO5aS Jvuw== 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:dkim-signature; bh=ZxnQYunt9dHV1HqD7hX+sXznv05Wmnd0Z4hkMgi8/7A=; fh=PiZ5V/4sGLDov5cF6A5wY5iqIfZAXRefEy8l5uZe2FU=; b=wr+wVzy7qfEV+dpFE25YUZS3l1SmGni91p6QSfhNMbc/tHvEBqcgo8hIHrOa9RvST0 Ddt2mCEkG0j3AbM4B2uj7l5X2+3WE5zZYlnmbNxHYWZ51WrqYJfRSprs/GrXEd4vsLrC KHUGuwMSX7PoCbyuZlqmzFUH9tc89At0TnrGZawFUrXE3QEImX/Xu8mzdS/CL6NwjJUt qZ+MyO2MzKhD3nPG6IgEMJntsMMktT8q9+UzuVoMx1qTIqXX3Go8rWdnMtDwpewX0JOH Lq0hISaiM5QgTnPtjeODoP5eZlFBCKidVHxHR678NeRj64yhXbvrz2WYAdCCkm5FDcwb HTBw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ICAhHYMD; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80099-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80099-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id ov30-20020a170906fc1e00b00a3f033ce7e8si1294575ejb.243.2024.02.25.06.28.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 06:28:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80099-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ICAhHYMD; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80099-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80099-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 208EE1F2150B for ; Sun, 25 Feb 2024 14:28:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B63A315E8B; Sun, 25 Feb 2024 14:27:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ICAhHYMD" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D925014F62; Sun, 25 Feb 2024 14:27:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708871263; cv=none; b=NLbmsoUOrIEZo/QR1aKKc76EmC0AQm6OYzgYukF9iohH/EoYejEp+KO+Ha9E6g5piCUb1n8GMA4rXDkl5724x2dHhe+0/v0+oJQ9yYDlEQxWVETYSTMwyVkslq24GZaBNVX+37qBvkzOOGxFBOinlLJDrZkHLgaiNfcyNfcDHj4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708871263; c=relaxed/simple; bh=JrxvOnnekqmZH3ajB2UIPWqOc4Gn4lKhT3b0ty+A5S8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qvYh1AIEtKpQ2M96CL9WsWhrkAc2Odn5l+luXWzwbTjWr4Q5dCxT0QI06qc4QLBR5UHluotnyw03v8578vrv0amNY8z8yTKfFL632Poztj7KR96dMeXQFQ/3fdQNyfLme9mA/SNH2tlKqKe/XDA+XI3HHL7Oy2YWs8BfU0JZycI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ICAhHYMD; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5430CC43394; Sun, 25 Feb 2024 14:27:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708871262; bh=JrxvOnnekqmZH3ajB2UIPWqOc4Gn4lKhT3b0ty+A5S8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ICAhHYMDXJlaFwdl0M9SxF2WSfiL+8mnR/YOiI670MrkWnJY7o5CdDZ8EyAfWy8Yw zJ7Qyvnvsiiw6YrMRN9e5rVbq9TFAmAWcOCH84LPhQtqHrC3IOgg5F5AAFcnTcNvQB WvXiIC1wkr/40zKn8zihJf3wEhhwxje2gjXvAogBPkSCuhcTDSyEA/M5xkrcw4SrDO sNAhlIrAaD5ItV5GP34OJQD1Hg3dP4d/NVw0HDi0DMM/RD/iY8DIMHmGjSyPhuobX4 iuyEu9+QMvwIxDKdjLtK42XAsISWGfn60HEI8Jn9N5Y+nZ/f1fwwurTEfALt1JwOSM G7lvr6gZ51kyQ== From: Jonathan Cameron To: devicetree@vger.kernel.org, linux-iio@vger.kernel.org, Rob Herring , Frank Rowand , linux-kernel@vger.kernel.org, Julia Lawall Cc: Peter Zijlstra , Andy Shevchenko , Greg Kroah-Hartman , marek.vasut@gmail.com, Jonathan Cameron Subject: [RESEND PATCH v2 2/4] of: Introduce for_each_*_child_of_node_scoped() to automate of_node_put() handling Date: Sun, 25 Feb 2024 14:27:12 +0000 Message-ID: <20240225142714.286440-3-jic23@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240225142714.286440-1-jic23@kernel.org> References: <20240225142714.286440-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Jonathan Cameron To avoid issues with out of order cleanup, or ambiguity about when the auto freed data is first instantiated, do it within the for loop definition. The disadvantage is that the struct device_node *child variable creation is not immediately obvious where this is used. However, in many cases, if there is another definition of struct device_node *child; the compiler / static analysers will notify us that it is unused, or uninitialized. Note that, in the vast majority of cases, the _available_ form should be used and as code is converted to these scoped handers, we should confirm that any cases that do not check for available have a good reason not to. Signed-off-by: Jonathan Cameron --- include/linux/of.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/linux/of.h b/include/linux/of.h index 50e882ee91da..024dda54b9c7 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -1430,10 +1430,23 @@ static inline int of_property_read_s32(const struct device_node *np, #define for_each_child_of_node(parent, child) \ for (child = of_get_next_child(parent, NULL); child != NULL; \ child = of_get_next_child(parent, child)) + +#define for_each_child_of_node_scoped(parent, child) \ + for (struct device_node *child __free(device_node) = \ + of_get_next_child(parent, NULL); \ + child != NULL; \ + child = of_get_next_child(parent, child)) + #define for_each_available_child_of_node(parent, child) \ for (child = of_get_next_available_child(parent, NULL); child != NULL; \ child = of_get_next_available_child(parent, child)) +#define for_each_available_child_of_node_scoped(parent, child) \ + for (struct device_node *child __free(device_node) = \ + of_get_next_available_child(parent, NULL); \ + child != NULL; \ + child = of_get_next_available_child(parent, child)) + #define for_each_of_cpu_node(cpu) \ for (cpu = of_get_next_cpu_node(NULL); cpu != NULL; \ cpu = of_get_next_cpu_node(cpu)) -- 2.44.0