of: change overlay apply input data from unflattened
Subsystems (2)
v5 cover of: change overlay apply input data from unflattened
From: Frank Rowand <[email protected]>
Move duplicating and unflattening of an overlay flattened devicetree (FDT) into the overlay application code. To accomplish this, of_overlay_apply() is replaced by of_overlay_fdt_apply().
The copy of the FDT (aka "duplicate FDT") now belongs to devicetree code, which is thus responsible for freeing the duplicate FDT. The caller of of_overlay_fdt_apply() remains responsible for freeing the original FDT.
The unflattened devicetree now belongs to devicetree code, which is thus responsible for freeing the unflattened devicetree.
These ownership changes prevent early freeing of the duplicated FDT or the unflattened devicetree, which could result in use after free errors.
These changes led to migrating some unittest overlay data into their own devicetree source files, and then converting most of them to use sugar syntax instead of hand coding fragments.
Changes from v4:
(all in patch 1/4)
- move of_overlay_fdt_apply() prototype from of_private.h to of.h
- of_overlay_apply(): add kfree(fdt) if resolve phandles or initialize changeset fail
- of_overlay_fdt_apply(): add parameter size of overlay_fdt and use it for some additional validation of the overlay fdt
- update unittest.c with additional parameter to of_overlay_fdt_apply()
Changes from v3:
- patch 1/4: OF_OVERLAY: add select OF_FLATTREE
Changes from v2:
- improve error messages in patch 4/4, as suggested by Geert
Changes from v1:
- rebase on v4.16-rc1
- update documentation
- split out error message to a separate patch
Frank Rowand (4):
of: change overlay apply input data from unflattened to FDT
of: Documentation: of_overlay_apply() replaced by
of_overlay_fdt_apply()
of: convert unittest overlay devicetree source to sugar syntax
of: improve reporting invalid overlay target path
Documentation/devicetree/overlay-notes.txt | 4 +- drivers/of/Kconfig | 1 + drivers/of/overlay.c | 134 +++++++++-- drivers/of/resolver.c | 6 - drivers/of/unittest-data/Makefile | 28 ++- drivers/of/unittest-data/overlay.dts | 101 ++++---- drivers/of/unittest-data/overlay_0.dts | 14 ++ drivers/of/unittest-data/overlay_1.dts | 14 ++ drivers/of/unittest-data/overlay_10.dts | 27 +++ drivers/of/unittest-data/overlay_11.dts | 28 +++ drivers/of/unittest-data/overlay_12.dts | 14 ++ drivers/of/unittest-data/overlay_13.dts | 14 ++ drivers/of/unittest-data/overlay_15.dts | 30 +++ drivers/of/unittest-data/overlay_2.dts | 9 + drivers/of/unittest-data/overlay_3.dts | 9 + drivers/of/unittest-data/overlay_4.dts | 18 ++ drivers/of/unittest-data/overlay_5.dts | 9 + drivers/of/unittest-data/overlay_6.dts | 10 + drivers/of/unittest-data/overlay_7.dts | 10 + drivers/of/unittest-data/overlay_8.dts | 10 + drivers/of/unittest-data/overlay_9.dts | 10 + drivers/of/unittest-data/overlay_bad_phandle.dts | 23 +- drivers/of/unittest-data/overlay_bad_symbol.dts | 25 +- drivers/of/unittest-data/tests-overlay.dtsi | 217 +---------------- drivers/of/unittest.c | 294 +++++++++++------------ include/linux/of.h | 6 +- 26 files changed, 582 insertions(+), 483 deletions(-) create mode 100644 drivers/of/unittest-data/overlay_0.dts create mode 100644 drivers/of/unittest-data/overlay_1.dts create mode 100644 drivers/of/unittest-data/overlay_10.dts create mode 100644 drivers/of/unittest-data/overlay_11.dts create mode 100644 drivers/of/unittest-data/overlay_12.dts create mode 100644 drivers/of/unittest-data/overlay_13.dts create mode 100644 drivers/of/unittest-data/overlay_15.dts create mode 100644 drivers/of/unittest-data/overlay_2.dts create mode 100644 drivers/of/unittest-data/overlay_3.dts create mode 100644 drivers/of/unittest-data/overlay_4.dts create mode 100644 drivers/of/unittest-data/overlay_5.dts create mode 100644 drivers/of/unittest-data/overlay_6.dts create mode 100644 drivers/of/unittest-data/overlay_7.dts create mode 100644 drivers/of/unittest-data/overlay_8.dts create mode 100644 drivers/of/unittest-data/overlay_9.dts
Signature · 1 line
Frank Rowand <[email protected]>
PATCH v5 1/4 of: change overlay apply input data from unflattened to FDT
From: Frank Rowand <[email protected]>
Move duplicating and unflattening of an overlay flattened devicetree (FDT) into the overlay application code. To accomplish this, of_overlay_apply() is replaced by of_overlay_fdt_apply().
The copy of the FDT (aka "duplicate FDT") now belongs to devicetree code, which is thus responsible for freeing the duplicate FDT. The caller of of_overlay_fdt_apply() remains responsible for freeing the original FDT.
The unflattened devicetree now belongs to devicetree code, which is thus responsible for freeing the unflattened devicetree.
These ownership changes prevent early freeing of the duplicated FDT or the unflattened devicetree, which could result in use after free errors.
of_overlay_fdt_apply() is a private function for the anticipated overlay loader.
Update unittest.c to use of_overlay_fdt_apply() instead of of_overlay_apply().
Move overlay fragments from artificial locations in drivers/of/unittest-data/tests-overlay.dtsi into one devicetree source file per overlay. This led to changes in drivers/of/unitest-data/Makefile and drivers/of/unitest.c.
- Add overlay directives to the overlay devicetree source files so that dtc will compile them as true overlays into one FDT data chunk per overlay.
- Set CFLAGS for drivers/of/unittest-data/testcases.dts so that symbols will be generated for overlay resolution of overlays that are no longer artificially contained in testcases.dts
- Unflatten and apply each unittest overlay FDT using
of_overlay_fdt_apply().
- Enable the of_resolve_phandles() check for whether the unflattened overlay is detached. This check was previously disabled because the overlays from tests-overlay.dtsi were not unflattened into detached trees.
- Other changes to unittest.c infrastructure to manage multiple test FDTs built into the kernel image (access by name instead of arbitrary number).
- of_unittest_overlay_high_level(): previously unused code to add properties from the overlay_base devicetree to the live tree was triggered by the restructuring of tests-overlay.dtsi and thus testcases.dts. This exposed two bugs: (1) the need to dup a property before adding it, and (2) property 'name' is auto-generated in the unflatten code and thus will be a duplicate in the __symbols__ node - do not treat this duplicate as an error.
---
There are checkpatch warnings. I have reviewed them and feel they can be ignored. They are "line over 80 characters" for either pre-existing long lines, or lines in devicetree source files.
There are still some functions in unittest.c that should be tagged __init due to changes in this patch, but modpost is not warning of them and they are not a risk because they are only called from __init functions. A sweep of unittest.c for functions that should be tagged __init is on the todo list.
Rob, the good news is that I have add making unittest a loadable module to my todo list.
Changes from v4:
- move of_overlay_fdt_apply() prototype from of_private.h to of.h
- of_overlay_apply(): add kfree(fdt) if resolve phandles or initialize changeset fail
- of_overlay_fdt_apply(): add parameter size of overlay_fdt and use it for some additional validation of the overlay fdt
- update unittest.c with additional parameter to of_overlay_fdt_apply()
Changes from v3:
- OF_OVERLAY: add select OF_FLATTREE
Changes from v1:
- rebase on v4.16-rc1
drivers/of/Kconfig | 1 + drivers/of/overlay.c | 112 ++++++++++- drivers/of/resolver.c | 6 - drivers/of/unittest-data/Makefile | 28 ++- drivers/of/unittest-data/overlay_0.dts | 14 ++ drivers/of/unittest-data/overlay_1.dts | 14 ++ drivers/of/unittest-data/overlay_10.dts | 34 ++++ drivers/of/unittest-data/overlay_11.dts | 34 ++++ drivers/of/unittest-data/overlay_12.dts | 14 ++ drivers/of/unittest-data/overlay_13.dts | 14 ++ drivers/of/unittest-data/overlay_15.dts | 35 ++++ drivers/of/unittest-data/overlay_2.dts | 14 ++ drivers/of/unittest-data/overlay_3.dts | 14 ++ drivers/of/unittest-data/overlay_4.dts | 23 +++ drivers/of/unittest-data/overlay_5.dts | 14 ++ drivers/of/unittest-data/overlay_6.dts | 15 ++ drivers/of/unittest-data/overlay_7.dts | 15 ++ drivers/of/unittest-data/overlay_8.dts | 15 ++ drivers/of/unittest-data/overlay_9.dts | 15 ++ drivers/of/unittest-data/tests-overlay.dtsi | 213 -------------------- drivers/of/unittest.c | 294 ++++++++++++++-------------- include/linux/of.h | 6 +- 22 files changed, 559 insertions(+), 385 deletions(-) create mode 100644 drivers/of/unittest-data/overlay_0.dts create mode 100644 drivers/of/unittest-data/overlay_1.dts create mode 100644 drivers/of/unittest-data/overlay_10.dts create mode 100644 drivers/of/unittest-data/overlay_11.dts create mode 100644 drivers/of/unittest-data/overlay_12.dts create mode 100644 drivers/of/unittest-data/overlay_13.dts create mode 100644 drivers/of/unittest-data/overlay_15.dts create mode 100644 drivers/of/unittest-data/overlay_2.dts create mode 100644 drivers/of/unittest-data/overlay_3.dts create mode 100644 drivers/of/unittest-data/overlay_4.dts create mode 100644 drivers/of/unittest-data/overlay_5.dts create mode 100644 drivers/of/unittest-data/overlay_6.dts create mode 100644 drivers/of/unittest-data/overlay_7.dts create mode 100644 drivers/of/unittest-data/overlay_8.dts create mode 100644 drivers/of/unittest-data/overlay_9.dts
drivers/of/Kconfig +1 -0
@@ -92,6 +92,7 @@ config OF_RESOLVE config OF_OVERLAY bool "Device Tree overlays" select OF_DYNAMIC + select OF_FLATTREE select OF_RESOLVE help Overlays are a method to dynamically modify part of the kernel's
drivers/of/overlay.c +103 -9
209 lines not on this page · raw message
drivers/of/resolver.c +0 -6
@@ -269,17 +269,11 @@ int of_resolve_phandles(struct device_node *overlay) goto out; } -#if 0 - Temporarily disable check so that old style overlay unittests - do not fail when of_resolve_phandles() is moved into - of_overlay_apply(). -if (!of_node_check_flag (overlay,OF_DETACHED )) {pr_err ("overlay not detached\n" ); err = -EINVAL ; goto out; } -#endif phandle_delta =live_tree_max_phandle () +1 ;adjust_overlay_phandles (overlay, phandle_delta);
drivers/of/unittest-data/Makefile +23 -5
@@ -1,8 +1,22 @@ # SPDX-License-Identifier: GPL-2.0 -DTC_FLAGS_testcases := -Wno-interrupts_property obj-y += testcases.dtb.o obj-$(CONFIG_OF_OVERLAY) += overlay.dtb.o \ + overlay_0.dtb.o \ + overlay_1.dtb.o \ + overlay_2.dtb.o \ + overlay_3.dtb.o \ + overlay_4.dtb.o \ + overlay_5.dtb.o \ + overlay_6.dtb.o \ + overlay_7.dtb.o \ + overlay_8.dtb.o \ + overlay_9.dtb.o \ + overlay_10.dtb.o \ + overlay_11.dtb.o \ + overlay_12.dtb.o \ + overlay_13.dtb.o \ + overlay_15.dtb.o \ overlay_bad_phandle.dtb.o \ overlay_bad_symbol.dtb.o \ overlay_base.dtb.o
@@ -10,10 +24,14 @@ obj-$(CONFIG_OF_OVERLAY) += overlay.dtb.o \ targets += $(foreach suffix, dtb dtb.S, $(patsubst %.dtb.o,%.$(suffix),$(obj-y))) # enable creation of __symbols__ node -DTC_FLAGS_overlay := -@ -DTC_FLAGS_overlay_bad_phandle := -@ -DTC_FLAGS_overlay_bad_symbol := -@ -DTC_FLAGS_overlay_base := -@ +DTC_FLAGS_overlay += -@ +DTC_FLAGS_overlay_bad_phandle += -@ +DTC_FLAGS_overlay_bad_symbol += -@ +DTC_FLAGS_overlay_base += -@ +DTC_FLAGS_testcases += -@ + +# suppress warnings about intentional errors +DTC_FLAGS_testcases += -Wno-interrupts_property .PRECIOUS: \ $(obj)/%.dtb.S \
drivers/of/unittest-data/overlay_0.dts new file +14 -0
@@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/plugin/; + +/ { + /* overlay_0 - enable using absolute target path */ + + fragment@0 { + target-path = "/testcase-data/overlay-node/test-bus/test-unittest0"; + __overlay__ { + status = "okay"; + }; + }; +};
drivers/of/unittest-data/overlay_1.dts new file +14 -0
@@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/plugin/; + +/ { + /* overlay_1 - disable using absolute target path */ + + fragment@0 { + target-path = "/testcase-data/overlay-node/test-bus/test-unittest1"; + __overlay__ { + status = "disabled"; + }; + }; +};
drivers/of/unittest-data/overlay_10.dts new file +34 -0
@@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/plugin/; + +/ { + /* overlay_10 */ + /* overlays 8, 9, 10, 11 application and removal in bad sequence */ + + fragment@0 { + target-path = "/testcase-data/overlay-node/test-bus"; + __overlay__ { + + /* suppress DTC warning */ + #address-cells = <1>; + #size-cells = <0>; + + test-unittest10 { + compatible = "unittest"; + status = "okay"; + reg = <10>; + + #address-cells = <1>; + #size-cells = <0>; + + test-unittest101 { + compatible = "unittest"; + status = "okay"; + reg = <1>; + }; + + }; + }; + }; +};
drivers/of/unittest-data/overlay_11.dts new file +34 -0
@@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/plugin/; + +/ { + /* overlay_11 */ + /* overlays 8, 9, 10, 11 application and removal in bad sequence */ + + fragment@0 { + target-path = "/testcase-data/overlay-node/test-bus"; + __overlay__ { + + /* suppress DTC warning */ + #address-cells = <1>; + #size-cells = <0>; + + test-unittest11 { + compatible = "unittest"; + status = "okay"; + reg = <11>; + + #address-cells = <1>; + #size-cells = <0>; + + test-unittest111 { + compatible = "unittest"; + status = "okay"; + reg = <1>; + }; + + }; + }; + }; +};
drivers/of/unittest-data/overlay_12.dts new file +14 -0
@@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/plugin/; + +/ { + /* overlay_12 - enable using absolute target path (i2c) */ + + fragment@0 { + target-path = "/testcase-data/overlay-node/test-bus/i2c-test-bus/test-unittest12"; + __overlay__ { + status = "okay"; + }; + }; +};
drivers/of/unittest-data/overlay_13.dts new file +14 -0
@@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/plugin/; + +/ { + /* overlay_13 - disable using absolute target path (i2c) */ + + fragment@0 { + target-path = "/testcase-data/overlay-node/test-bus/i2c-test-bus/test-unittest13"; + __overlay__ { + status = "disabled"; + }; + }; +};
drivers/of/unittest-data/overlay_15.dts new file +35 -0
@@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/plugin/; + +/ { + /* overlay_15 - mux overlay */ + + fragment@0 { + target-path = "/testcase-data/overlay-node/test-bus/i2c-test-bus"; + __overlay__ { + #address-cells = <1>; + #size-cells = <0>; + test-unittest15 { + reg = <11>; + compatible = "unittest-i2c-mux"; + status = "okay"; + + #address-cells = <1>; + #size-cells = <0>; + + i2c@0 { + #address-cells = <1>; + #size-cells = <0>; + reg = <0>; + + test-mux-dev { + reg = <32>; + compatible = "unittest-i2c-dev"; + status = "okay"; + }; + }; + }; + }; + }; +};
drivers/of/unittest-data/overlay_2.dts new file +14 -0
@@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/plugin/; + +/ { + /* overlay_2 - enable using label */ + + fragment@0 { + target = <&unittest2>; + __overlay__ { + status = "okay"; + }; + }; +};
drivers/of/unittest-data/overlay_3.dts new file +14 -0
@@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/plugin/; + +/ { + /* overlay_3 - disable using label */ + + fragment@0 { + target = <&unittest3>; + __overlay__ { + status = "disabled"; + }; + }; +};
drivers/of/unittest-data/overlay_4.dts new file +23 -0
@@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/plugin/; + +/ { + /* overlay_4 - test insertion of a full node */ + + fragment@0 { + target = <&unittestbus>; + __overlay__ { + + /* suppress DTC warning */ + #address-cells = <1>; + #size-cells = <0>; + + test-unittest4 { + compatible = "unittest"; + status = "okay"; + reg = <4>; + }; + }; + }; +};
drivers/of/unittest-data/overlay_5.dts new file +14 -0
@@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/plugin/; + +/ { + /* overlay_5 - test overlay apply revert */ + + fragment@0 { + target-path = "/testcase-data/overlay-node/test-bus/test-unittest5"; + __overlay__ { + status = "okay"; + }; + }; +};
drivers/of/unittest-data/overlay_6.dts new file +15 -0
@@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/plugin/; + +/ { + /* overlay_6 */ + /* overlays 6, 7 application and removal in sequence */ + + fragment@0 { + target-path = "/testcase-data/overlay-node/test-bus/test-unittest6"; + __overlay__ { + status = "okay"; + }; + }; +};
drivers/of/unittest-data/overlay_7.dts new file +15 -0
@@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/plugin/; + +/ { + /* overlay_7 */ + /* overlays 6, 7 application and removal in sequence */ + + fragment@0 { + target-path = "/testcase-data/overlay-node/test-bus/test-unittest7"; + __overlay__ { + status = "okay"; + }; + }; +};
drivers/of/unittest-data/overlay_8.dts new file +15 -0
@@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/plugin/; + +/ { + /* overlay_8 */ + /* overlays 8, 9, 10, 11 application and removal in bad sequence */ + + fragment@0 { + target-path = "/testcase-data/overlay-node/test-bus/test-unittest8"; + __overlay__ { + status = "okay"; + }; + }; +};
drivers/of/unittest-data/overlay_9.dts new file +15 -0
@@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/plugin/; + +/ { + /* overlay_9 */ + /* overlays 8, 9, 10, 11 application and removal in bad sequence */ + + fragment@0 { + target-path = "/testcase-data/overlay-node/test-bus/test-unittest8"; + __overlay__ { + property-foo = "bar"; + }; + }; +};
drivers/of/unittest-data/tests-overlay.dtsi +0 -213
218 lines not on this page · raw message
drivers/of/unittest.c +145 -149
575 lines not on this page · raw message
include/linux/of.h +3 -3
@@ -1359,8 +1359,8 @@ struct of_overlay_notify_data {#ifdef CONFIG_OF_OVERLAY -/* ID based overlays; the API for external users */ -int of_overlay_apply (struct device_node *tree,int *ovcs_id); +int of_overlay_fdt_apply (const void *overlay_fdt,u32 overlay_fdt_size, +int *ovcs_id);int of_overlay_remove (int *ovcs_id);int of_overlay_remove_all (void );
@@ -1369,7 +1369,7 @@ struct of_overlay_notify_data {#else -static inline int of_overlay_apply (struct device_node *tree,int *ovcs_id) +static inline int of_overlay_fdt_apply (void *overlay_fdt,int *ovcs_id) {return -ENOTSUPP ; }
Signature · 1 line
Frank Rowand <[email protected]>
Re: [PATCH v5 1/4] of: change overlay apply input data from unflattened to FDT
Hi Frank,
Quoted 5 lines · On Fri, Mar 2, 2018 at 2:51 AM, <[email protected]> wrote:
There are still some functions in
unittest.cthat should be tagged__initdue to changes in this patch, but modpost is not warning of them and they are not a risk because they are only called from__initfunctions. A sweep ofunittest.cfor functions that should be tagged__initis on the todo list.
If modpost doesn't warn, that merely means your compiler decided to inline all functions with wrong annotations, hiding the problem. Other (versions of) compilers may behave differently, so we do want to get this right.
With my trusty gcc-4.1.2:
WARNING: vmlinux.o(.text+0x342dd4): Section mismatch in reference
from the function of_unittest_apply_revert_overlay_check() to the function .init.text:of_unittest_apply_overlay()
The function of_unittest_apply_revert_overlay_check() references the function __init of_unittest_apply_overlay().
This is often because of_unittest_apply_revert_overlay_check lacks a __init annotation or the annotation of of_unittest_apply_overlay is wrong.
To fix the above:
-static int of_unittest_apply_revert_overlay_check(int overlay_nr, +static int __init of_unittest_apply_revert_overlay_check(int overlay_nr, -static void of_unittest_overlay_5(void)
+static void __init of_unittest_overlay_5(void)
-static void of_unittest_overlay_11(void)
+static void __init of_unittest_overlay_11(void)
drivers/of/unittest.c static __init void of_unittest_overlay_high_level(void) · line 2279
Quoted 9 lines
drivers/of/unittest.c +1
-0@@ -2290,18 +2275,29 @@ static __init void of_unittest_overlay_high_level(void)__of_attach_node_sysfs (np);if (of_symbols) { +struct property *new_prop;for_each_property_of_node (overlay_base_symbols, prop) {
drivers/of/unittest.c: In function ‘of_unittest_overlay_high_level’:drivers/of/unittest.c:2193: warning: ‘overlay_base_symbols’ may be used uninitialized in this function
This isn't a new warning, so I guess I never reported it before because I thought it was a false positive (misguided by the "if (of_symbols)" test?).
However, now I believe it is not, and an uninitialized pointer will be dereferenced if of_root has a __symbols__ node, but overlay_base_root hasn't.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Re: [PATCH v5 1/4] of: change overlay apply input data from unflattened to FDT
Quoted 26 lines · Geert Uytterhoeven
Hi Frank,
Quoted 5 lines · On Fri, Mar 2, 2018 at 2:51 AM, <[email protected]> wrote:
There are still some functions in
unittest.cthat should be tagged__initdue to changes in this patch, but modpost is not warning of them and they are not a risk because they are only called from__initfunctions. A sweep ofunittest.cfor functions that should be tagged__initis on the todo list.If modpost doesn't warn, that merely means your compiler decided to inline all functions with wrong annotations, hiding the problem. Other (versions of) compilers may behave differently, so we do want to get this right.
With my trusty gcc-4.1.2:
WARNING: vmlinux.o(.text+0x342dd4): Section mismatch in referencefrom the function
of_unittest_apply_revert_overlay_check()to the function .init.text:of_unittest_apply_overlay()
The functionof_unittest_apply_revert_overlay_check()references the function__initof_unittest_apply_overlay().
This is often becauseof_unittest_apply_revert_overlay_checklacks a__initannotation or the annotation ofof_unittest_apply_overlayis wrong.To fix the above:
Review
Quoted 6 lines
(quoted diff) +3
-3-static int of_unittest_apply_revert_overlay_check(int overlay_nr, +static int __init of_unittest_apply_revert_overlay_check(int overlay_nr, -static void of_unittest_overlay_5(void) +static void __init of_unittest_overlay_5(void) -static void of_unittest_overlay_11(void) +static void __init of_unittest_overlay_11(void)
Yes, that is exactly the extra set of functions I was talking about. Even though I would prefer to annotate them, in practice they will not be a problem because they only get called from __init functions (either directly or indirectly). But if Rob will take a patch with them annotated, I will spin the series.
Quoted 14 lines
drivers/of/unittest.c static __init void of_unittest_overlay_high_level(void) · line 2279
Quoted 9 lines
drivers/of/unittest.c +1
-0@@ -2290,18 +2275,29 @@ static __init void of_unittest_overlay_high_level(void)__of_attach_node_sysfs (np);if (of_symbols) { +struct property *new_prop;for_each_property_of_node (overlay_base_symbols, prop) {
drivers/of/unittest.c: In function ‘of_unittest_overlay_high_level’:drivers/of/unittest.c:2193: warning: ‘overlay_base_symbols’ may be used uninitialized in this function
Quoted 5 lines
This isn't a new warning, so I guess I never reported it before because I thought it was a false positive (misguided by the "if (
of_symbols)" test?).However, now I believe it is not, and an uninitialized pointer will be dereferenced if
of_roothas a__symbols__node, butoverlay_base_roothasn't.
Yes, thanks for reporting it. My gcc isn't this smart.
Fortunately overlay_base_root does have a __symbols__ node. But I will fix it in a patch outside this series.
Quoted 12 lines
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
PATCH v5 2/4 of: Documentation: of_overlay_apply() replaced by of_overlay_fdt_apply()
In reply to [email protected]From: Frank Rowand <[email protected]>
--- Documentation/devicetree/overlay-notes.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Documentation/devicetree/overlay-notes.txt +2 -2
@@ -87,8 +87,8 @@ Overlay in-kernel API The API is quite easy to use. -1. Call of_overlay_apply() to create and apply an overlay changeset. The return -value is an error or a cookie identifying this overlay. +1. Call of_overlay_fdt_apply() to create and apply an overlay changeset. The +return value is an error or a cookie identifying this overlay. 2. Call of_overlay_remove() to remove and cleanup the overlay changeset previously created via the call to of_overlay_apply(). Removal of an overlay
Signature · 1 line
Frank Rowand <[email protected]>
PATCH v5 3/4 of: convert unittest overlay devicetree source to sugar syntax
In reply to [email protected]From: Frank Rowand <[email protected]>
The unittest-data overlays have been pulled into proper overlay devicetree source files without changing their format. The next step is to convert them to use sugar syntax instead of hand coding overlay fragments structure.
A few of the overlays can not be converted because they test absolute target paths in the overlay fragment. dtc does not generate this type of target:
overlay_0.dts
overlay_1.dts
overlay_12.dts
overlay_13.dts
Two pre-existing unittest overlay devicetree source files are also converted:
overlay_bad_phandle.dts
overlay_bad_symbol.dts
---
There are checkpatch warnings. I have reviewed them and feel they can be ignored. They are pre-existing warnings of un-documented bindings of made up (fake) compatibles in devicetree source for test overlays.
drivers/of/unittest-data/overlay.dts | 101 ++++++++++------------- drivers/of/unittest-data/overlay_10.dts | 39 ++++----- drivers/of/unittest-data/overlay_11.dts | 40 ++++----- drivers/of/unittest-data/overlay_15.dts | 41 ++++----- drivers/of/unittest-data/overlay_2.dts | 11 +-- drivers/of/unittest-data/overlay_3.dts | 11 +-- drivers/of/unittest-data/overlay_4.dts | 23 ++---- drivers/of/unittest-data/overlay_5.dts | 11 +-- drivers/of/unittest-data/overlay_6.dts | 13 +-- drivers/of/unittest-data/overlay_7.dts | 13 +-- drivers/of/unittest-data/overlay_8.dts | 13 +-- drivers/of/unittest-data/overlay_9.dts | 13 +-- drivers/of/unittest-data/overlay_bad_phandle.dts | 23 ++---- drivers/of/unittest-data/overlay_bad_symbol.dts | 25 ++---- drivers/of/unittest-data/tests-overlay.dtsi | 4 +- 15 files changed, 148 insertions(+), 233 deletions(-)
drivers/of/unittest-data/overlay.dts +44 -57
@@ -2,76 +2,63 @@ /dts-v1/; /plugin/; -/ { +&electric_1 { - fragment@0 { - target = <&electric_1>; + status = "okay"; - __overlay__ { - status = "okay"; - - hvac_2: hvac-large-1 { - compatible = "ot,hvac-large"; - heat-range = < 40 75 >; - cool-range = < 65 80 >; - }; - }; + hvac_2: hvac-large-1 { + compatible = "ot,hvac-large"; + heat-range = < 40 75 >; + cool-range = < 65 80 >; }; +}; - fragment@1 { - target = <&rides_1>; - - __overlay__ { - #address-cells = <1>; - #size-cells = <1>; - status = "okay"; - - ride@100 { - #address-cells = <1>; - #size-cells = <1>; - - track@30 { - incline-up = < 48 32 16 >; - }; +&rides_1 { - track@40 { - incline-up = < 47 31 15 >; - }; - }; + #address-cells = <1>; + #size-cells = <1>; + status = "okay"; - ride_200: ride@200 { - #address-cells = <1>; - #size-cells = <1>; - compatible = "ot,ferris-wheel"; - reg = < 0x00000200 0x100 >; - hvac-provider = < &hvac_2 >; - hvac-thermostat = < 27 32 > ; - hvac-zones = < 12 5 >; - hvac-zone-names = "operator", "snack-bar"; - spin-controller = < &spin_ctrl_1 3 >; - spin-rph = < 30 >; - gondolas = < 16 >; - gondola-capacity = < 6 >; + ride@100 { + #address-cells = <1>; + #size-cells = <1>; - ride_200_left: track@10 { - reg = < 0x00000010 0x10 >; - }; + track@30 { + incline-up = < 48 32 16 >; + }; - ride_200_right: track@20 { - reg = < 0x00000020 0x10 >; - }; - }; + track@40 { + incline-up = < 47 31 15 >; }; }; - fragment@2 { - target = <&lights_2>; + ride_200: ride@200 { + #address-cells = <1>; + #size-cells = <1>; + compatible = "ot,ferris-wheel"; + reg = < 0x00000200 0x100 >; + hvac-provider = < &hvac_2 >; + hvac-thermostat = < 27 32 > ; + hvac-zones = < 12 5 >; + hvac-zone-names = "operator", "snack-bar"; + spin-controller = < &spin_ctrl_1 3 >; + spin-rph = < 30 >; + gondolas = < 16 >; + gondola-capacity = < 6 >; + + ride_200_left: track@10 { + reg = < 0x00000010 0x10 >; + }; - __overlay__ { - status = "okay"; - color = "purple", "white", "red", "green"; - rate = < 3 256 >; + ride_200_right: track@20 { + reg = < 0x00000020 0x10 >; }; }; +}; + +&lights_2 { + status = "okay"; + color = "purple", "white", "red", "green"; + rate = < 3 256 >; };
drivers/of/unittest-data/overlay_10.dts +16 -23
@@ -2,33 +2,26 @@ /dts-v1/; /plugin/; -/ { - /* overlay_10 */ - /* overlays 8, 9, 10, 11 application and removal in bad sequence */ +/* overlay_10 */ +/* overlays 8, 9, 10, 11 application and removal in bad sequence */ - fragment@0 { - target-path = "/testcase-data/overlay-node/test-bus"; - __overlay__ { +&unittest_test_bus { + /* suppress DTC warning */ + #address-cells = <1>; + #size-cells = <0>; - /* suppress DTC warning */ - #address-cells = <1>; - #size-cells = <0>; + test-unittest10 { + compatible = "unittest"; + status = "okay"; + reg = <10>; - test-unittest10 { - compatible = "unittest"; - status = "okay"; - reg = <10>; + #address-cells = <1>; + #size-cells = <0>; - #address-cells = <1>; - #size-cells = <0>; - - test-unittest101 { - compatible = "unittest"; - status = "okay"; - reg = <1>; - }; - - }; + test-unittest101 { + compatible = "unittest"; + status = "okay"; + reg = <1>; }; }; };
drivers/of/unittest-data/overlay_11.dts +17 -23
@@ -2,33 +2,27 @@ /dts-v1/; /plugin/; -/ { - /* overlay_11 */ - /* overlays 8, 9, 10, 11 application and removal in bad sequence */ +/* overlay_11 */ +/* overlays 8, 9, 10, 11 application and removal in bad sequence */ - fragment@0 { - target-path = "/testcase-data/overlay-node/test-bus"; - __overlay__ { +&unittest_test_bus { + /* suppress DTC warning */ + #address-cells = <1>; + #size-cells = <0>; - /* suppress DTC warning */ - #address-cells = <1>; - #size-cells = <0>; + test-unittest11 { + compatible = "unittest"; + status = "okay"; + reg = <11>; - test-unittest11 { - compatible = "unittest"; - status = "okay"; - reg = <11>; + #address-cells = <1>; + #size-cells = <0>; - #address-cells = <1>; - #size-cells = <0>; - - test-unittest111 { - compatible = "unittest"; - status = "okay"; - reg = <1>; - }; - - }; + test-unittest111 { + compatible = "unittest"; + status = "okay"; + reg = <1>; }; + }; };
drivers/of/unittest-data/overlay_15.dts +18 -23
51 lines not on this page · raw message
drivers/of/unittest-data/overlay_2.dts +3 -8
@@ -2,13 +2,8 @@ /dts-v1/; /plugin/; -/ { - /* overlay_2 - enable using label */ +/* overlay_2 - enable using label */ - fragment@0 { - target = <&unittest2>; - __overlay__ { - status = "okay"; - }; - }; +&unittest2 { + status = "okay"; };
drivers/of/unittest-data/overlay_3.dts +3 -8
@@ -2,13 +2,8 @@ /dts-v1/; /plugin/; -/ { - /* overlay_3 - disable using label */ +/* overlay_3 - disable using label */ - fragment@0 { - target = <&unittest3>; - __overlay__ { - status = "disabled"; - }; - }; +&unittest3 { + status = "disabled"; };
drivers/of/unittest-data/overlay_4.dts +9 -14
@@ -2,22 +2,17 @@ /dts-v1/; /plugin/; -/ { - /* overlay_4 - test insertion of a full node */ +/* overlay_4 - test insertion of a full node */ - fragment@0 { - target = <&unittestbus>; - __overlay__ { +&unittest_test_bus { - /* suppress DTC warning */ - #address-cells = <1>; - #size-cells = <0>; + /* suppress DTC warning */ + #address-cells = <1>; + #size-cells = <0>; - test-unittest4 { - compatible = "unittest"; - status = "okay"; - reg = <4>; - }; - }; + test-unittest4 { + compatible = "unittest"; + status = "okay"; + reg = <4>; }; };
drivers/of/unittest-data/overlay_5.dts +3 -8
@@ -2,13 +2,8 @@ /dts-v1/; /plugin/; -/ { - /* overlay_5 - test overlay apply revert */ +/* overlay_5 - test overlay apply revert */ - fragment@0 { - target-path = "/testcase-data/overlay-node/test-bus/test-unittest5"; - __overlay__ { - status = "okay"; - }; - }; +&unittest5 { + status = "okay"; };
drivers/of/unittest-data/overlay_6.dts +4 -9
@@ -2,14 +2,9 @@ /dts-v1/; /plugin/; -/ { - /* overlay_6 */ - /* overlays 6, 7 application and removal in sequence */ +/* overlay_6 */ +/* overlays 6, 7 application and removal in sequence */ - fragment@0 { - target-path = "/testcase-data/overlay-node/test-bus/test-unittest6"; - __overlay__ { - status = "okay"; - }; - }; +&unittest6 { + status = "okay"; };
drivers/of/unittest-data/overlay_7.dts +4 -9
@@ -2,14 +2,9 @@ /dts-v1/; /plugin/; -/ { - /* overlay_7 */ - /* overlays 6, 7 application and removal in sequence */ +/* overlay_7 */ +/* overlays 6, 7 application and removal in sequence */ - fragment@0 { - target-path = "/testcase-data/overlay-node/test-bus/test-unittest7"; - __overlay__ { - status = "okay"; - }; - }; +&unittest7 { + status = "okay"; };
drivers/of/unittest-data/overlay_8.dts +4 -9
@@ -2,14 +2,9 @@ /dts-v1/; /plugin/; -/ { - /* overlay_8 */ - /* overlays 8, 9, 10, 11 application and removal in bad sequence */ +/* overlay_8 */ +/* overlays 8, 9, 10, 11 application and removal in bad sequence */ - fragment@0 { - target-path = "/testcase-data/overlay-node/test-bus/test-unittest8"; - __overlay__ { - status = "okay"; - }; - }; +&unittest8 { + status = "okay"; };
drivers/of/unittest-data/overlay_9.dts +4 -9
@@ -2,14 +2,9 @@ /dts-v1/; /plugin/; -/ { - /* overlay_9 */ - /* overlays 8, 9, 10, 11 application and removal in bad sequence */ +/* overlay_9 */ +/* overlays 8, 9, 10, 11 application and removal in bad sequence */ - fragment@0 { - target-path = "/testcase-data/overlay-node/test-bus/test-unittest8"; - __overlay__ { - property-foo = "bar"; - }; - }; +&unittest8 { + property-foo = "bar"; };
drivers/of/unittest-data/overlay_bad_phandle.dts +8 -15
@@ -2,20 +2,13 @@ /dts-v1/; /plugin/; -/ { - - fragment@0 { - target = <&electric_1>; - - __overlay__ { - - // This label should cause an error when the overlay - // is applied. There is already a phandle value - // in the base tree for motor-1. - spin_ctrl_1_conflict: motor-1 { - accelerate = < 3 >; - decelerate = < 5 >; - }; - }; +&electric_1 { + + // This label should cause an error when the overlay + // is applied. There is already a phandle value + // in the base tree for motor-1. + spin_ctrl_1_conflict: motor-1 { + accelerate = < 3 >; + decelerate = < 5 >; }; };
drivers/of/unittest-data/overlay_bad_symbol.dts +9 -16
@@ -2,22 +2,15 @@ /dts-v1/; /plugin/; -/ { +&electric_1 { - fragment@0 { - target = <&electric_1>; - - __overlay__ { - - // This label should cause an error when the overlay - // is applied. There is already a symbol hvac_1 - // in the base tree - hvac_1: hvac-medium-2 { - compatible = "ot,hvac-medium"; - heat-range = < 50 75 >; - cool-range = < 60 80 >; - }; - - }; + // This label should cause an error when the overlay + // is applied. There is already a symbol hvac_1 + // in the base tree + hvac_1: hvac-medium-2 { + compatible = "ot,hvac-medium"; + heat-range = < 50 75 >; + cool-range = < 60 80 >; }; + };
drivers/of/unittest-data/tests-overlay.dtsi +2 -2
@@ -5,7 +5,7 @@ overlay-node { /* test bus */ - unittestbus: test-bus { + unittest_test_bus: test-bus { compatible = "simple-bus"; #address-cells = <1>; #size-cells = <0>;
@@ -70,7 +70,7 @@ reg = <8>; }; - i2c-test-bus { + unittest_i2c_test_bus: i2c-test-bus { compatible = "unittest-i2c-bus"; status = "okay"; reg = <50>;
Signature · 1 line
Frank Rowand <[email protected]>
PATCH v5 4/4 of: improve reporting invalid overlay target path
In reply to [email protected]From: Frank Rowand <[email protected]>
Errors while developing the patch to create of_overlay_fdt_apply() exposed inadequate error messages to debug problems when overlay devicetree fragment nodes contain an invalid target path. Improve the messages in find_target_node() to remedy this.
---
changes from v2:
- add fragment node name as suggested by Geert
- existing error message printed short node name, thus not discriminating between fragments; change to full node name
- existing error message printed node address, which is devicetree internal debugging, not useful in an overlay apply error message; remove node address from message
drivers/of/overlay.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
drivers/of/overlay.c +16 -6
@@ -488,20 +488,30 @@ static int build_changeset(struct overlay_changeset *ovcs)*/ static struct device_node *find_target_node (struct device_node *info_node) { +struct device_node *node;const char *path;u32 val;int ret; ret =of_property_read_u32 (info_node,"target" , &val); -if (!ret) -return of_find_node_by_phandle (val); +if (!ret) { + node =of_find_node_by_phandle (val); +if (!node) +pr_err ("find target, node: %pOF, phandle 0x%x not found\n" , + info_node, val); +return node; + } ret =of_property_read_string (info_node,"target-path" , &path); -if (!ret) -return of_find_node_by_path (path); +if (!ret) { + node =of_find_node_by_path (path); +if (!node) +pr_err ("find target, node: %pOF, path '%s' not found\n" , + info_node, path); +return node; + } -pr_err ("Failed to find target for node %p (%s)\n" , - info_node, info_node->name); +pr_err ("find target, node: %pOF, no target property\n" , info_node);return NULL ; }
Signature · 1 line
Frank Rowand <[email protected]>
Hi Frank,
Thank you for the patches.
For the whole series,
Quoted 93 lines · On Friday, 2 March 2018 03:51:56 EET [email protected] wrote:
From: Frank Rowand <[email protected]>
Move duplicating and unflattening of an overlay flattened devicetree (FDT) into the overlay application code. To accomplish this,
of_overlay_apply()is replaced byof_overlay_fdt_apply().The copy of the FDT (aka "duplicate FDT") now belongs to devicetree code, which is thus responsible for freeing the duplicate FDT. The caller of
of_overlay_fdt_apply()remains responsible for freeing the original FDT.The unflattened devicetree now belongs to devicetree code, which is thus responsible for freeing the unflattened devicetree.
These ownership changes prevent early freeing of the duplicated FDT or the unflattened devicetree, which could result in use after free errors.
These changes led to migrating some unittest overlay data into their own devicetree source files, and then converting most of them to use sugar syntax instead of hand coding fragments.
Changes from v4:
(all in patch 1/4)
- moveof_overlay_fdt_apply()prototype fromof_private.htoof.h
-of_overlay_apply(): add kfree(fdt) if resolve phandles or initialize changeset fail
-of_overlay_fdt_apply(): add parameter size ofoverlay_fdtand use it for some additional validation of the overlay fdt
- updateunittest.cwith additional parameter toof_overlay_fdt_apply()Changes from v3:
- patch 1/4:OF_OVERLAY: add selectOF_FLATTREEChanges from v2:
- improve error messages in patch 4/4, as suggested by GeertChanges from v1:
- rebase on v4.16-rc1
- update documentation
- split out error message to a separate patchFrank Rowand (4):
of: change overlay apply input data from unflattened to FDT
of: Documentation:of_overlay_apply()replaced by
of_overlay_fdt_apply()
of: convert unittest overlay devicetree source to sugar syntax
of: improve reporting invalid overlay target pathDocumentation/devicetree/overlay-notes.txt | 4 +- drivers/of/Kconfig | 1 + drivers/of/overlay.c | 134 +++++++++-- drivers/of/resolver.c | 6 - drivers/of/unittest-data/Makefile | 28 ++- drivers/of/unittest-data/overlay.dts | 101 ++++---- drivers/of/unittest-data/overlay_0.dts | 14 ++ drivers/of/unittest-data/overlay_1.dts | 14 ++ drivers/of/unittest-data/overlay_10.dts | 27 +++ drivers/of/unittest-data/overlay_11.dts | 28 +++ drivers/of/unittest-data/overlay_12.dts | 14 ++ drivers/of/unittest-data/overlay_13.dts | 14 ++ drivers/of/unittest-data/overlay_15.dts | 30 +++ drivers/of/unittest-data/overlay_2.dts | 9 + drivers/of/unittest-data/overlay_3.dts | 9 + drivers/of/unittest-data/overlay_4.dts | 18 ++ drivers/of/unittest-data/overlay_5.dts | 9 + drivers/of/unittest-data/overlay_6.dts | 10 + drivers/of/unittest-data/overlay_7.dts | 10 + drivers/of/unittest-data/overlay_8.dts | 10 + drivers/of/unittest-data/overlay_9.dts | 10 + drivers/of/unittest-data/overlay_bad_phandle.dts | 23 +- drivers/of/unittest-data/overlay_bad_symbol.dts | 25 +- drivers/of/unittest-data/tests-overlay.dtsi | 217 +---------------- drivers/of/unittest.c | 294 +++++++++++------------ include/linux/of.h | 6 +- 26 files changed, 582 insertions(+), 483 deletions(-) create mode 100644 drivers/of/unittest-data/overlay_0.dts create mode 100644 drivers/of/unittest-data/overlay_1.dts create mode 100644 drivers/of/unittest-data/overlay_10.dts create mode 100644 drivers/of/unittest-data/overlay_11.dts create mode 100644 drivers/of/unittest-data/overlay_12.dts create mode 100644 drivers/of/unittest-data/overlay_13.dts create mode 100644 drivers/of/unittest-data/overlay_15.dts create mode 100644 drivers/of/unittest-data/overlay_2.dts create mode 100644 drivers/of/unittest-data/overlay_3.dts create mode 100644 drivers/of/unittest-data/overlay_4.dts create mode 100644 drivers/of/unittest-data/overlay_5.dts create mode 100644 drivers/of/unittest-data/overlay_6.dts create mode 100644 drivers/of/unittest-data/overlay_7.dts create mode 100644 drivers/of/unittest-data/overlay_8.dts create mode 100644 drivers/of/unittest-data/overlay_9.dts
Signature · 3 lines
Regards, Laurent Pinchart