From patchwork Sun Feb 11 17:42:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 199490 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2032601dyd; Sun, 11 Feb 2024 09:44:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IFlS0aABUET5Ti+oK+UTtRS30X0fSIT1aTqd5eMiC5M90RfRhECEkbgWmJHmOU6n1QwZiCA X-Received: by 2002:ac2:44ab:0:b0:510:ee2d:c185 with SMTP id c11-20020ac244ab000000b00510ee2dc185mr2946084lfm.13.1707673440997; Sun, 11 Feb 2024 09:44:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707673440; cv=pass; d=google.com; s=arc-20160816; b=bfE/pu5URSwr2uzX5m83zpt40VBx34yzWmWCUaCcadCKbPSn70PkeytMumHfoS9Bb9 zKZa1PzXWDPPioDyNOBgmHRaA+pa2Y9XHu6erPWQQ9auWtzD+nppi/ukaDEUcNfzULQj GXuZDdM+pwGkQkgoKopUzTv1YExHSuiHQeopgstoxaoy81LcQJsrxzMQAvFM7mqR9rJK OtNhVj1Vv8j+6Evwhd9usCL/gMoTchHN3MYRVrk4F+8cGOBzoN3+ORovJzgAZONpXxMl 0x7/oIb4njlXLynFFsi0Qbduh47AW1qNd2xlfUsF+V1P2OXa56y+nGkCH8Uu51D4UiYs pmfg== 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=ELvTT+TwAMDXy1/buqnUbKuYi0cGHMudMPi+twztNOs=; fh=zA3Vk3bZOog6QEQVHRHuDlpFHnCKEYOP/w08OutB/OA=; b=XlzwvpZva7RXsaJeXJmhwcnGVa41PUTQ5avuGB0lYp+7LRYWecdx4omFkzwOGpi1Sf lMe5mSGaAOgngx+QQl5Phq34aBjX4jmE4X6EuwvRZWL7i0LX8Doz6KepEOMn+ZUwyFAQ 23wfkKnre3ZPjXSYqTbY7CFU/GHeR2ZrUlAXLJ3FAMPZmiGP6fw58FNZ6dQfsodWSjh8 zHxZ0S/NoXgDPUiaNePgm7uwahJ4DpMdQe8ayt+bWYGDS1mGKSGX7/PuyY8nHS4gOdJq 0FBpBXOAyOF8alHfa3W1TN2YJg+TecfK0pPBPhS8CuSJFpu9XPbJsalWjvDX691VtpHG NGTw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OCrmHKDP; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-60887-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60887-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCWKaAezKbbqrXLIsKgM2ZFB71cS+LmRk17ca1jKcVwxQN/3PN8FTVNyoA8GO9DdeGuuwcI7Q3dn1z6Yfb5VmXnCgLwnQQ== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id h25-20020aa7de19000000b0055ef7edb086si1917680edv.365.2024.02.11.09.44.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 09:44:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60887-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OCrmHKDP; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-60887-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60887-ouuuleilei=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 9386C1F226EE for ; Sun, 11 Feb 2024 17:44:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A11F35D8E8; Sun, 11 Feb 2024 17:43:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OCrmHKDP" 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 C79E85CDF6; Sun, 11 Feb 2024 17:43:16 +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=1707673396; cv=none; b=cBZYPVcdwsKN1cWj/c1hwXzZ5ttWWZDUB5jKYaAi+OP8Nca++JkgXRfWRP19rWhLAmmBMcLTqQd0uOrXqMt33YRQEGdE8ggPmFbGDTEXVtXWHidjBu+hdsMktXoJw8D5yVwpPce+fJ2Y7rWmAPMQPbB3AKQArvHYkBMzE8C2bfg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707673396; c=relaxed/simple; bh=VgEK2vscmpylabGiM7nvGoX57oIPPeaNwTit8d+h46A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PBTU9x9L97uaExtanH5teun+7Lk2o1M6fzsoL1kR2TT0DMCBkTZY7FFClZUFsqH8kRmvsPhL5CRjY3Du6t/tXu/zM0u+JrnEOPO6Mi7/shBC/nBaqa2G5Y67XKd3MuQ6mUSAmzkWPVt1zCJljKTD/088B8JGoVz2CVT/V+JHH9w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OCrmHKDP; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4724CC433C7; Sun, 11 Feb 2024 17:43:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707673396; bh=VgEK2vscmpylabGiM7nvGoX57oIPPeaNwTit8d+h46A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OCrmHKDPCdySn0pPYItTL2t7zwZYjXsrjzzICJ5bIPlVfBxcXz3I4mQx9Rm8+05IG 4zhQ5X9GNutZxC1biiXulib7hYq7Nf9Pkc+p8yBs7GT2qSG+CWT06pgc4K15BVQ/Pt xJIvH/rpk2l+k8WlsV5XbVworWbScq2wnTXn6sh9G4n1qq322KDmhvEqFftqyOQTsF jO52rL3gkVRzJMXltO1tCzCRdeY33DAJeUZXabutSKhgmJRten5clFb7JlKG02UOgL 1DrJWdfMVK3jobfLMxbYhWwFvjIGhSWiXkuryeMBJYkELTHBHier4/Bq62iK/5yJp7 mbpWd75FVNViQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org, Rob Herring , Frank Rowand , linux-kernel@vger.kernel.org, Julia Lawall Cc: Peter Zijlstra , Nicolas Palix , Sumera Priyadarsini , "Rafael J . Wysocki" , Len Brown , linux-acpi@vger.kernel.org, Andy Shevchenko , Greg Kroah-Hartman , =?utf-8?q?Nuno_S=C3=A1?= , Jonathan Cameron Subject: [PATCH 2/8] of: Introduce for_each_*_child_of_node_scoped() to automate of_node_put() handling Date: Sun, 11 Feb 2024 17:42:30 +0000 Message-ID: <20240211174237.182947-3-jic23@kernel.org> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240211174237.182947-1-jic23@kernel.org> References: <20240211174237.182947-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790625386072843064 X-GMAIL-MSGID: 1790625386072843064 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))