Message ID | 20240211174237.182947-2-jic23@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-60886-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2032529dyd; Sun, 11 Feb 2024 09:43:45 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWkSxO3z29ZOuBodYM5KS7r2wgcqhsQbkPqoHDAsLP7gYMILgPoFy4LEZxnDasXJMq5tq/qrKK0yllIkPEcBUuRETECaA== X-Google-Smtp-Source: AGHT+IEMHe9jKxVvFz1gqvAe8mpNpbSE9ONl8XVDIdMD93FeoQ7CuAw6BZTK0QgaahM+uXBQh31N X-Received: by 2002:a17:906:f9d1:b0:a38:5658:54aa with SMTP id lj17-20020a170906f9d100b00a38565854aamr4331088ejb.12.1707673425525; Sun, 11 Feb 2024 09:43:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707673425; cv=pass; d=google.com; s=arc-20160816; b=j199EtdRQ5GktHCGFPJt7T8T5DScpvcSXW7xbhoAbD7CBPeLHrr+hhbs+y/NySjQRz U0LG4YFL3qPt+fNZs0OK17b60hH4NoPgf+fbkxfxwa43eVurlm3dnA0AMjxEpXpmmgvx SIuap8h0GbbYVZqB2mWIHu9zJZ7TG8nNY+KLBp2e4lOYaYzKvRUuta9HgwhRQvQcRcKf yVcykPFiO5chVVv130+uRHVbSDeS8iNr5Snra8wlbxW6ceHIKxVdg3wbvt7hx+Q56Xge YuxNM2cy4OVfFsIZShzHjd4EDt+mEM/d1C9huf+I8FpYRBmMqq71PqP/kXdmdz3lrLQD 0iSA== 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=nQsj22NPxmBMr5ip7C9eNpQVJYUc91r8FEatPtU1zrk=; fh=xfiTMzPv/Vii32NWQwZKUy4liNzEYqGxEhjuGAQAoJo=; b=iTVaekaN3oF5DGnpQ4yNCoikxhdU7Jh3drnf4/AQMKCj0aggExtuYZlT94pGGlnS/4 pR1odFyJlhTwTWtNRew4TlQZ+YPCBdP7gC7RENlWP5UYHBHPyYjGTxh//n6vQ8fG+BUO RVnZ2UoZ0K5/m4w06ojY9D4UQwq+/CGZsKhxMZHSino25SPcs4da1AbvrNVBQeQbbvTi Mg5FOo3Jkza681CwW9H10Jbn9UTgOb9CLaXb/AnQeKl4l9+MS8DPpeV4poa6ib5attHF wEHQq2WNvNedZ0n5XlGdYiu/V+mEnSvA+s2EedbwpTOTJXIDd2OOGBvxQxD4FIcW/n3D duxw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qUqMQoWk; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-60886-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60886-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCWAQ6ULOqdwJHS45uOhdiG0ChgJ/d6ZU82fwY4pLoK9dpp0yiAwaFr+RTgkMX7LeJJbQELr4o8gaOzOeqQ4RR/DcnMIXw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id gt17-20020a170906f21100b00a384f537a74si3028208ejb.860.2024.02.11.09.43.45 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 09:43:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60886-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=qUqMQoWk; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-60886-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60886-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 255391F227A9 for <ouuuleilei@gmail.com>; Sun, 11 Feb 2024 17:43:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 272025D745; Sun, 11 Feb 2024 17:43:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qUqMQoWk" 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 2DD102837D; Sun, 11 Feb 2024 17:43:12 +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=1707673393; cv=none; b=SjVrsHH/2FMap/JwV/aWOrxMuWsq5Xrpaib4kRpudmCFnZ2JD+ooM3Obnf21JfWI3zCHyI2FP7rPxonTjSh6lZSB9jZtHdKsAXS5TmTiLbm4sSyakl5QTlwbD68sMpJUNfrg9xFnVjfGd838I1plck1BKFkoVgaQ3isjVPUQSak= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707673393; c=relaxed/simple; bh=FL7OGytfdxTg1+Il2BlWOFoikr/LWTCTYjPks2DpfGI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H1LDiu8ygANN3U2cDpShQbIlPZAAsL5UydtHChrN8icqC6NdIR1kxB6CRAvCjJMsmah734MhzPY+g56APKZt9fwMV7Y1hr3qgXGwW/ekuyk7G5eZC+teGlhh9ktJek0k4oXDVyb2w1BgtuDgIIubacltHKinz2O87Ad4Br1ECGs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qUqMQoWk; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7586BC43390; Sun, 11 Feb 2024 17:43:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707673392; bh=FL7OGytfdxTg1+Il2BlWOFoikr/LWTCTYjPks2DpfGI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qUqMQoWk1tXkagwZnH8JtWCfo+skthBMefbkiM+Vfu4g8PAYIoVqT7XFHAHWFPWuf OXFcvLIbfoxckJ3Bowqs/sx/kC5iM9Sds9nYopT+bQ4o6ueB3YpwsH4oV5aHi5S76h rA/cChOxg6BuRiDe/W0FE+PEcV9k2DpFtMXiRUwliV3jVuYu7g9QVoO07h/HrMDb8C mwPGc1bPXyG3sXjdpqEo3CjzH+15pwe2VDwHtPKOW7Xkqn0G7o2b7RhQCQiKFYRmgp H5F/XrokeFMMrDTzdBorgj280D9v+zZuyBFX0IY1gPMc/PE9r3cgf8DUXSoeMGsoaL 66JjV23yVCS+A== From: Jonathan Cameron <jic23@kernel.org> To: linux-iio@vger.kernel.org, Rob Herring <robh@kernel.org>, Frank Rowand <frowand.list@gmail.com>, linux-kernel@vger.kernel.org, Julia Lawall <Julia.Lawall@inria.fr> Cc: Peter Zijlstra <peterz@infradead.org>, Nicolas Palix <nicolas.palix@imag.fr>, Sumera Priyadarsini <sylphrenadin@gmail.com>, "Rafael J . Wysocki" <rafael@kernel.org>, Len Brown <lenb@kernel.org>, linux-acpi@vger.kernel.org, Andy Shevchenko <andriy.shevchenko@linux.intel.com>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, =?utf-8?q?Nuno_S=C3=A1?= <nuno.sa@analog.com>, Jonathan Cameron <Jonathan.Cameron@huawei.com> Subject: [PATCH 1/8] of: Add cleanup.h based auto release via __free(device_node) markings. Date: Sun, 11 Feb 2024 17:42:29 +0000 Message-ID: <20240211174237.182947-2-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: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790625370235264406 X-GMAIL-MSGID: 1790625370235264406 |
Series |
of: automate of_node_put() - new approach to loops.
|
|
Commit Message
Jonathan Cameron
Feb. 11, 2024, 5:42 p.m. UTC
From: Jonathan Cameron <Jonathan.Cameron@huawei.com> The recent addition of scope based cleanup support to the kernel provides a convenient tool to reduce the chances of leaking reference counts where of_node_put() should have been called in an error path. This enables struct device_node *child __free(device_node) = NULL; for_each_child_of_node(np, child) { if (test) return test; } with no need for a manual call of of_node_put(). A following patch will reduce the scope of the child variable to the for loop, to avoid an issues with ordering of autocleanup, and make it obvious when this assigned a non NULL value. In this simple example the gains are small but there are some very complex error handling cases buried in these loops that will be greatly simplified by enabling early returns with out the need for this manual of_node_put() call. Note that there are coccinelle checks in scripts/coccinelle/iterators/for_each_child.cocci to detect a failure to call of_node_put(). This new approach does not cause false positives. Longer term we may want to add scripting to check this new approach is done correctly with no double of_node_put() calls being introduced due to the auto cleanup. It may also be useful to script finding places this new approach is useful. Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> --- include/linux/of.h | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/include/linux/of.h b/include/linux/of.h index 6a9ddf20e79a..50e882ee91da 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -13,6 +13,7 @@ */ #include <linux/types.h> #include <linux/bitops.h> +#include <linux/cleanup.h> #include <linux/errno.h> #include <linux/kobject.h> #include <linux/mod_devicetable.h> @@ -134,6 +135,7 @@ static inline struct device_node *of_node_get(struct device_node *node) } static inline void of_node_put(struct device_node *node) { } #endif /* !CONFIG_OF_DYNAMIC */ +DEFINE_FREE(device_node, struct device_node *, if (_T) of_node_put(_T)) /* Pointer for first entry in chain of all nodes. */ extern struct device_node *of_root;