From: Greg Kroah-Hartman Date: Fri, 30 Aug 2024 05:35:58 +0000 (+0200) Subject: 6.1-stable patches X-Git-Tag: v4.19.321~77 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=caf0a142a06d96391fb90353b0a21e0f526a1afc;p=thirdparty%2Fkernel%2Fstable-queue.git 6.1-stable patches added patches: of-add-cleanup.h-based-auto-release-via-__free-device_node-markings.patch --- diff --git a/queue-6.1/of-add-cleanup.h-based-auto-release-via-__free-device_node-markings.patch b/queue-6.1/of-add-cleanup.h-based-auto-release-via-__free-device_node-markings.patch new file mode 100644 index 00000000000..3cff72d3ad9 --- /dev/null +++ b/queue-6.1/of-add-cleanup.h-based-auto-release-via-__free-device_node-markings.patch @@ -0,0 +1,66 @@ +From 9448e55d032d99af8e23487f51a542d51b2f1a48 Mon Sep 17 00:00:00 2001 +From: Jonathan Cameron +Date: Sun, 25 Feb 2024 14:27:11 +0000 +Subject: of: Add cleanup.h based auto release via __free(device_node) markings + +From: Jonathan Cameron + +commit 9448e55d032d99af8e23487f51a542d51b2f1a48 upstream. + +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 +Reviewed-by: Rob Herring +Link: https://lore.kernel.org/r/20240225142714.286440-2-jic23@kernel.org +Signed-off-by: Rob Herring +Signed-off-by: Greg Kroah-Hartman +--- + include/linux/of.h | 2 ++ + 1 file changed, 2 insertions(+) + +--- a/include/linux/of.h ++++ b/include/linux/of.h +@@ -13,6 +13,7 @@ + */ + #include + #include ++#include + #include + #include + #include +@@ -128,6 +129,7 @@ static inline struct device_node *of_nod + } + 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; diff --git a/queue-6.1/series b/queue-6.1/series index 48799a651a4..c514f20aa7d 100644 --- a/queue-6.1/series +++ b/queue-6.1/series @@ -4,3 +4,4 @@ btrfs-run-delayed-iputs-when-flushing-delalloc.patch smb-client-avoid-dereferencing-rdata-null-in-smb2_new_read_req.patch pinctrl-rockchip-correct-rk3328-iomux-width-flag-for-gpio2-b-pins.patch pinctrl-single-fix-potential-null-dereference-in-pcs_get_function.patch +of-add-cleanup.h-based-auto-release-via-__free-device_node-markings.patch